Skip to content

Commit

Permalink
Parser: make an error on unbalanced end brace '}' in macro body (#5420)
Browse files Browse the repository at this point in the history
Fixed #5417
  • Loading branch information
makenowjust authored and sdogruyol committed Apr 13, 2018
1 parent 72ce28f commit 403de68
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 403de68

Please sign in to comment.