Skip to content

Commit

Permalink
Fix parsing macro body with escaped backslash in literal (#10995)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Jul 24, 2021
1 parent c79cfdc commit a23527f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,9 @@ module Crystal

it_parses "macro foo\neenum\nend", Macro.new("foo", body: Expressions.from(["eenum\n".macro_literal] of ASTNode))
it_parses "macro foo\n'\\''\nend", Macro.new("foo", body: Expressions.from(["'\\''\n".macro_literal] of ASTNode))
it_parses "macro foo\n'\\\\'\nend", Macro.new("foo", body: Expressions.from(["'\\\\'\n".macro_literal] of ASTNode))
it_parses %(macro foo\n"\\'"\nend), Macro.new("foo", body: Expressions.from([%("\\'"\n).macro_literal] of ASTNode))
it_parses %(macro foo\n"\\\\"\nend), Macro.new("foo", body: Expressions.from([%("\\\\"\n).macro_literal] of ASTNode))

assert_syntax_error "macro foo; {% foo = 1 }; end"
assert_syntax_error "macro def foo : String; 1; end"
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,10 @@ module Crystal
when '\\'
char = next_char
if delimiter_state
if char == delimiter_state.end
case char
when delimiter_state.end
char = next_char
when '\\'
char = next_char
end
whitespace = false
Expand Down

0 comments on commit a23527f

Please sign in to comment.