Skip to content

Commit dd4d8a3

Browse files
committedMay 5, 2015
Allow trailing comma after arg and assocs in paren args
Fixes #638.
1 parent 03f2890 commit dd4d8a3

File tree

4 files changed

+2256
-2203
lines changed

4 files changed

+2256
-2203
lines changed
 

Diff for: ‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## edge (upcoming 0.8.0)
22

3+
* Parser: Allow trailing comma in paren arglists, after normal args as
4+
well as assoc args.
5+
36
* Parser: Fix parsing of parens following divide operator without a
47
space.
58

Diff for: ‎lib/opal/parser/grammar.rb

+2,221-2,196
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎lib/opal/parser/grammar.y

+22-7
Original file line numberDiff line numberDiff line change
@@ -607,23 +607,38 @@ rule
607607
result = [s(:hash, *val[0])]
608608
}
609609

610-
paren_args: tLPAREN2 none tRPAREN
611-
{
612-
result = []
613-
}
614-
| tLPAREN2 call_args opt_nl tRPAREN
610+
paren_args: tLPAREN2 opt_call_args rparen
615611
{
616612
result = val[1]
617613
}
618-
| tLPAREN2 block_call opt_nl tRPAREN
619-
| tLPAREN2 args tCOMMA block_call opt_nl tRPAREN
614+
615+
rparen: opt_nl tRPAREN
620616

621617
opt_paren_args: none
622618
{
623619
result = []
624620
}
625621
| paren_args
626622

623+
opt_call_args: none
624+
{
625+
result = []
626+
}
627+
| call_args
628+
| args tCOMMA
629+
{
630+
result = val[0]
631+
}
632+
| args tCOMMA assocs tCOMMA
633+
{
634+
result = val[0]
635+
result << new_hash(nil, val[2], nil)
636+
}
637+
| assocs tCOMMA
638+
{
639+
result = [new_hash(nil, val[0], nil)]
640+
}
641+
627642
call_args: command
628643
{
629644
result = [val[0]]

Diff for: ‎spec/lib/parser/call_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,13 @@
153153
parsed('1-(2)').should == [:call, [:int, 1], '-'.to_sym, [:arglist, [:paren, [:int, 2]]]]
154154
end
155155
end
156+
157+
describe 'Calls with trailing comma' do
158+
it 'parses correctly' do
159+
parsed('foo(1,)').should == [:call, nil, :foo, [:arglist, [:int, 1]]]
160+
parsed('foo(1, 2,)').should == [:call, nil, :foo, [:arglist, [:int, 1], [:int, 2]]]
161+
162+
parsed('foo(a: 100,)').should == [:call, nil, :foo, [:arglist,
163+
[:hash, [:sym, :a], [:int, 100]]]]
164+
end
165+
end

0 commit comments

Comments
 (0)
Please sign in to comment.