Skip to content
Permalink
Browse files
Parser: allow to use trailing comma after named arguments in index no…
…tation (#4784)

Fix #4782

For example, current compiler cannot compile this:

    a = [1, 2, 3]
    a[
      index: 1,
    ]
    # Syntax error in foo.cr:4: expected named argument, not ]

Because the compiler does not allow comma after named arguments in index
notation. This fixes it so above is now working.
  • Loading branch information
MakeNowJust authored and RX14 committed Aug 16, 2017
1 parent dc877a8 commit 53c44315fbf5cdd37d630309afb0060b8754a79d
Showing with 2 additions and 1 deletion.
  1. +1 −0 spec/compiler/parser/parser_spec.cr
  2. +1 −1 src/compiler/crystal/syntax/parser.cr
@@ -341,6 +341,7 @@ describe "Parser" do
it_parses "x.foo a: 1, b: 2 ", Call.new("x".call, "foo", named_args: [NamedArgument.new("a", 1.int32), NamedArgument.new("b", 2.int32)])

it_parses "x[a: 1, b: 2]", Call.new("x".call, "[]", named_args: [NamedArgument.new("a", 1.int32), NamedArgument.new("b", 2.int32)])
it_parses "x[a: 1, b: 2,]", Call.new("x".call, "[]", named_args: [NamedArgument.new("a", 1.int32), NamedArgument.new("b", 2.int32)])
it_parses "x[{1}]", Call.new("x".call, "[]", TupleLiteral.new([1.int32] of ASTNode))
it_parses "x[+ 1]", Call.new("x".call, "[]", Call.new(1.int32, "+"))

@@ -4089,7 +4089,7 @@ module Crystal
skip_space_or_newline if allow_newline
if @token.type == :","
next_token_skip_space_or_newline
if @token.type == :")" || @token.type == :"&"
if @token.type == :")" || @token.type == :"&" || @token.type == :"]"
break
end
else

0 comments on commit 53c4431

Please sign in to comment.