From ef8c129c6ec9742ecb0ce809e4fd739818417a4b Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Thu, 21 Dec 2017 02:21:28 +0900 Subject: [PATCH] Parser: make an error on unbalanced end brace '}' in macro body 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 94f2e09f83df..c29e31cbeee2 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -775,6 +775,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 289d7b664437..1d0f672c7095 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -2809,6 +2809,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