Skip to content

Commit 48458d5

Browse files
committed
Fix xstr with plain gvar unparsing
Follow-up to #387 ```shell bundle exec bin/unparser -e '`#$G`' (string) Original-Source: `#$G` Generated-Source: lib/unparser/emitter/xstr.rb:56:in 'Unparser::Emitter::XStr#escape_xstr' lib/unparser/emitter/xstr.rb:52:in 'Unparser::Emitter::XStr#emit_string' lib/unparser/emitter/xstr.rb:45:in 'block in Unparser::Emitter::XStr#emit_xstr' lib/unparser/emitter/xstr.rb:41:in 'Array#each' lib/unparser/emitter/xstr.rb:41:in 'Unparser::Emitter::XStr#emit_xstr' lib/unparser/emitter/xstr.rb:16:in 'Unparser::Emitter::XStr#dispatch' lib/unparser/generation.rb:13:in 'block in Unparser::Generation#write_to_buffer' lib/unparser/generation.rb:44:in 'Unparser::Generation#with_comments' lib/unparser/generation.rb:13:in 'Unparser::Generation#write_to_buffer' <internal:kernel>:91:in 'Kernel#tap' lib/unparser/generation.rb:236:in 'Unparser::Generation#visit_deep' lib/unparser/generation.rb:132:in 'block in Unparser::Generation#emit_body' lib/unparser/generation.rb:138:in 'Unparser::Generation#with_indent' lib/unparser/generation.rb:122:in 'Unparser::Generation#emit_body' lib/unparser/emitter/root.rb:11:in 'Unparser::Emitter::Root#dispatch' lib/unparser/generation.rb:13:in 'block in Unparser::Generation#write_to_buffer' lib/unparser/generation.rb:44:in 'Unparser::Generation#with_comments' lib/unparser/generation.rb:13:in 'Unparser::Generation#write_to_buffer' lib/unparser.rb:148:in 'block in Unparser.unparse_ast' <internal:kernel>:91:in 'Kernel#tap' Original-Node: (xstr (gvar :$G)) Generated-Node: undefined Error: (string) ```
1 parent f31f816 commit 48458d5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/unparser/emitter/xstr.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def emit_xstr
4141
children.each do |child|
4242
if n_begin?(child)
4343
emit_begin(child)
44+
elsif n_gvar?(child)
45+
emit_gvar(child)
4446
else
4547
emit_string(child)
4648
end
@@ -67,6 +69,11 @@ def emit_begin(component)
6769
visit(Util.one(component.children)) if component.children.any?
6870
write('}')
6971
end
72+
73+
def emit_gvar(component)
74+
write('#')
75+
write(Util.one(component.children).to_s)
76+
end
7077
end # XStr
7178
end # Emitter
7279
end # Unparser

test/corpus/literal/literal.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@
7474
#`
7575
`#{}`
7676
`#G`
77+
`#$G`

0 commit comments

Comments
 (0)