Skip to content

Commit 53c4431

Browse files
makenowjustRX14
authored andcommittedAug 16, 2017
Parser: allow to use trailing comma after named arguments in index notation (#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.
1 parent dc877a8 commit 53c4431

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
 

‎spec/compiler/parser/parser_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ describe "Parser" do
341341
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)])
342342

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

‎src/compiler/crystal/syntax/parser.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4089,7 +4089,7 @@ module Crystal
40894089
skip_space_or_newline if allow_newline
40904090
if @token.type == :","
40914091
next_token_skip_space_or_newline
4092-
if @token.type == :")" || @token.type == :"&"
4092+
if @token.type == :")" || @token.type == :"&" || @token.type == :"]"
40934093
break
40944094
end
40954095
else

0 commit comments

Comments
 (0)
Please sign in to comment.