From 403de68b77166945abfdd222941c954922ab149e Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Fri, 13 Apr 2018 16:14:48 +0900 Subject: [PATCH] Parser: make an error on unbalanced end brace '}' in macro body (#5420) Fixed #5417 --- spec/compiler/parser/parser_spec.cr | 1 + src/compiler/crystal/syntax/parser.cr | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 3d1995d26c78..27ae875ed9e1 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -780,6 +780,7 @@ describe "Parser" do it_parses "macro foo;bar{% for x in y %}\\ \n body{% end %}\\ baz;end", Macro.new("foo", [] of Arg, Expressions.from(["bar".macro_literal, MacroFor.new(["x".var], "y".var, "body".macro_literal), "baz;".macro_literal] of ASTNode)) it_parses "macro foo; 1 + 2 {{foo}}\\ 3 + 4; end", Macro.new("foo", [] of Arg, Expressions.from([" 1 + 2 ".macro_literal, MacroExpression.new("foo".var), "3 + 4; ".macro_literal] of ASTNode)) + assert_syntax_error "macro foo; {% foo = 1 }; end" assert_syntax_error "macro def foo : String; 1; end" it_parses "def foo;{{@type}};end", Def.new("foo", body: Expressions.from([MacroExpression.new("@type".instance_var)] of ASTNode), macro_def: true) diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index 9fa5f15152e1..ac798bbc6878 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -2870,6 +2870,7 @@ module Crystal when :MACRO_CONTROL_START macro_control = parse_macro_control(start_line, start_column, macro_state) if macro_control + check :"%}" pieces << macro_control skip_whitespace = check_macro_skip_whitespace else