Skip to content

Commit 4e9ccf8

Browse files
committed
Fix parsing of other line continuation scenarios
1 parent 92bfeb3 commit 4e9ccf8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/natalie/parser.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,14 @@ def visit_string_concat_node(node)
785785
end
786786
end
787787
left
788+
when %i[str dstr]
789+
right[1] = left[1] + right[1]
790+
right
791+
when %i[dstr str]
792+
left << right
793+
left
788794
else
789-
debug node
795+
raise SyntaxError, "Unexpected nodes for StringConcatNode: #{left.inspect} and #{right.inspect}"
790796
end
791797
end
792798

test/natalie/string_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,4 +758,19 @@ def initialize(s)
758758
"a\nb\nc".each_line(chomp: true).to_a.should == %w[a b c]
759759
end
760760
end
761+
762+
describe 'line continuation' do
763+
s = 'foo' \
764+
'bar'
765+
s.should == 'foobar'
766+
s = 'foo' \
767+
"bar#{1 + 1}"
768+
s.should == 'foobar2'
769+
s = "foo#{1 + 1}" \
770+
"bar#{1 + 1}"
771+
s.should == 'foo2bar2'
772+
s = "foo#{1 + 1}" \
773+
'bar'
774+
s.should == 'foo2bar'
775+
end
761776
end

0 commit comments

Comments
 (0)