From 06d9a82f1822f633d020a9ac0b87d5fcdc844a00 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Sat, 30 Mar 2019 13:30:08 -0300 Subject: [PATCH] Parser: disallow space between enum members --- spec/compiler/parser/parser_spec.cr | 2 ++ src/compiler/crystal/syntax/parser.cr | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 710bc251d6a8..6970cdd745c6 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -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) diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index cd3ee7de288a..9c0148dc29fb 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -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)