Skip to content

Commit

Permalink
Parse suffix if/unless in macros after macro var
Browse files Browse the repository at this point in the history
Set beginning of line to false right after parsing a macro var.
Fixes #4087.
  • Loading branch information
spalladino authored and asterite committed Mar 1, 2017
1 parent c2c2276 commit f58fd86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Expand Up @@ -769,6 +769,13 @@ describe "Parser" do
it_parses "macro foo;%var;end", Macro.new("foo", [] of Arg, Expressions.from([MacroVar.new("var"), MacroLiteral.new(";")] of ASTNode))
it_parses "macro foo;%var{1, x} = hello;end", Macro.new("foo", [] of Arg, Expressions.from([MacroVar.new("var", [1.int32, "x".var] of ASTNode), MacroLiteral.new(" = hello;")] of ASTNode))

["if", "unless"].each do |keyword|
it_parses "macro foo;%var #{keyword} true;end", Macro.new("foo", [] of Arg, Expressions.from([MacroVar.new("var"), " #{keyword} true;".macro_literal] of ASTNode))
it_parses "macro foo;var #{keyword} true;end", Macro.new("foo", [] of Arg, "var #{keyword} true;".macro_literal)
it_parses "macro foo;#{keyword} %var;true;end;end", Macro.new("foo", [] of Arg, Expressions.from(["#{keyword} ".macro_literal, MacroVar.new("var"), ";true;".macro_literal, "end;".macro_literal] of ASTNode))
it_parses "macro foo;#{keyword} var;true;end;end", Macro.new("foo", [] of Arg, Expressions.from(["#{keyword} var;true;".macro_literal, "end;".macro_literal] of ASTNode))
end

it_parses "a = 1; pointerof(a)", [Assign.new("a".var, 1.int32), PointerOf.new("a".var)]
it_parses "pointerof(@a)", PointerOf.new("@a".instance_var)
it_parses "a = 1; pointerof(a)", [Assign.new("a".var, 1.int32), PointerOf.new("a".var)]
Expand Down
1 change: 1 addition & 0 deletions src/compiler/crystal/syntax/lexer.cr
Expand Up @@ -2032,6 +2032,7 @@ module Crystal
while ident_part?(char)
char = next_char
end
beginning_of_line = false
@token.type = :MACRO_VAR
@token.value = string_range_from_pool(start)
@token.macro_state = Token::MacroState.new(whitespace, nest, delimiter_state, beginning_of_line, yields, comment)
Expand Down

0 comments on commit f58fd86

Please sign in to comment.