Skip to content

Commit

Permalink
Merge pull request #7607 from asterite/bug/disallow-space-between-enu…
Browse files Browse the repository at this point in the history
…m-members

Parser: disallow space between enum members
  • Loading branch information
asterite committed Mar 30, 2019
2 parents 779e744 + 06d9a82 commit 05e2a10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,8 @@ module Crystal

it_parses "enum Foo; @[Bar]; end", EnumDef.new("Foo".path, [Annotation.new("Bar".path)] of ASTNode)

assert_syntax_error "enum Foo; A B; end", "expecting ',', ';', 'end' or newline after enum member"

it_parses "1.[](2)", Call.new(1.int32, "[]", 2.int32)
it_parses "1.[]?(2)", Call.new(1.int32, "[]?", 2.int32)
it_parses "1.[]=(2, 3)", Call.new(1.int32, "[]=", 2.int32, 3.int32)
Expand Down
11 changes: 7 additions & 4 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5522,17 +5522,20 @@ module Crystal
next_token_skip_space
if @token.type == :"="
next_token_skip_space_or_newline

constant_value = parse_logical_or
next_token_skip_statement_end
else
constant_value = nil
skip_statement_end
end

skip_space

case @token.type
when :",", :";"
when :",", :";", :NEWLINE, :EOF
next_token_skip_statement_end
else
unless @token.keyword?(:end)
raise "expecting ',', ';', 'end' or newline after enum member", location
end
end

arg = Arg.new(constant_name, constant_value).at(location).at_end(constant_value || location)
Expand Down

0 comments on commit 05e2a10

Please sign in to comment.