Skip to content

Commit cc8e942

Browse files
committedJul 29, 2013
Allow new lines in chained method invocation (fixes #287)
1 parent afa8cb9 commit cc8e942

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

Diff for: ‎lib/opal/lexer.rb

+7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ def next_token
289289

290290
next if [:expr_beg, :expr_dot].include? @lex_state
291291

292+
if scanner.scan(/([\ \t\r\f\v]*)\./)
293+
space_seen = true unless scanner[1].empty?
294+
scanner.pos = scanner.pos - 1
295+
296+
next unless scanner.check(/\.\./)
297+
end
298+
292299
cmd_start = true
293300
@lex_state = :expr_beg
294301
return '\\n', '\\n'

Diff for: ‎spec/parser/call_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
opal_parse("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:lit, 1], [:lit, 2]]]
1919
opal_parse("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:lit, 1], [:splat, [:lit, 2]]]]
2020
end
21+
22+
it "supports leading dots on newline" do
23+
opal_parse("foo\n.bar").should == [:call, [:call, nil, :foo, [:arglist]], :bar, [:arglist]]
24+
lambda { opal_parse("foo\n..bar") }.should raise_error(Exception)
25+
end
2126
end
2227

2328
describe "Operator calls" do

0 commit comments

Comments
 (0)
Please sign in to comment.