Commit 613f076f
613f076fbe56Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
Merge pull request #279 from ryanseys/rs-node-interp-symbol
feat(parse,codegen): support InterpolatedSymbolNode (:"foo_#{x}")
Details
- Commit
- 613f076fbe56
- Parent
- 168b6c9336f7
- Merge parent
- 18c3f982b07d
spinel_codegen.rbmodifiedView file
@@ -1728,6 +1728,13 @@
17281728
if t == "InterpolatedStringNode"17291729
return "string"17301730
end1731+
if t == "InterpolatedSymbolNode"1732+
# Spinel doesn't intern dynamic symbols; the runtime value is1733+
# the assembled string. Use sites that need symbol-typed1734+
# behaviour (sym_int_hash keys, ===) won't work, but puts/==/1735+
# string interpolation/regex match all do.1736+
return "string"1737+
end17311738
if t == "TrueNode"17321739
return "bool"17331740
end@@ -17185,6 +17192,15 @@
1718517192
if t == "InterpolatedStringNode"1718617193
return compile_interpolated(nid)1718717194
end17195+
if t == "InterpolatedSymbolNode"17196+
# `:"foo_#{x}"` -- assemble via the same parts loop as17197+
# InterpolatedStringNode. CRuby returns a Symbol; Spinel returns17198+
# the string form because dynamic symbol interning isn't17199+
# supported (sp_sym ids are reserved for compile-time literals).17200+
# Use sites that accept either string or symbol -- puts, ==,17201+
# string interpolation -- behave identically.17202+
return compile_interpolated(nid)17203+
end1718817204
if t == "NumberedReferenceReadNode"1718917205
num = @nd_value[nid]1719017206
if num >= 1 && num <= 9spinel_parse.cmodifiedView file
Loading diff…
test/interp_symbol.rbaddedView file
Loading diff…
test/interp_symbol.rb.expectedaddedView file
Loading diff…