Skip to content

Commit

Permalink
Fixed #4249: parse error with macros with %{}
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Apr 7, 2017
1 parent 2229513 commit d3ae522
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Expand Up @@ -756,6 +756,8 @@ describe "Parser" do

it_parses "macro foo;bar{% begin %}body{% end %}baz;end", Macro.new("foo", [] of Arg, Expressions.from(["bar".macro_literal, MacroIf.new(true.bool, "body".macro_literal), "baz;".macro_literal] of ASTNode))

it_parses "macro x\n%{}\nend", Macro.new("x", body: MacroLiteral.new("%{}\n"))

it_parses "def foo : Int32\n1\nend", Def.new("foo", body: 1.int32, return_type: "Int32".path)
it_parses "def foo(x) : Int32\n1\nend", Def.new("foo", args: ["x".arg], body: 1.int32, return_type: "Int32".path)

Expand Down
7 changes: 6 additions & 1 deletion src/compiler/crystal/syntax/lexer.cr
Expand Up @@ -2118,7 +2118,12 @@ module Crystal
break
end
when '}'
if @macro_curly_count > 0
if delimiter_state && delimiter_state.end == '}'
delimiter_state = delimiter_state.with_open_count_delta(-1)
if delimiter_state.open_count == 0
delimiter_state = nil
end
elsif @macro_curly_count > 0
# Once we find the final '}' that closes the interpolation,
# we are back inside the delimiter
if @macro_curly_count == 1
Expand Down

0 comments on commit d3ae522

Please sign in to comment.