Skip to content

Commit f58fd86

Browse files
spalladinoAry Borenszweig
authored and
Ary Borenszweig
committedMar 1, 2017
Parse suffix if/unless in macros after macro var
Set beginning of line to false right after parsing a macro var. Fixes #4087.
1 parent c2c2276 commit f58fd86

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎spec/compiler/parser/parser_spec.cr

+7
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,13 @@ describe "Parser" do
769769
it_parses "macro foo;%var;end", Macro.new("foo", [] of Arg, Expressions.from([MacroVar.new("var"), MacroLiteral.new(";")] of ASTNode))
770770
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))
771771

772+
["if", "unless"].each do |keyword|
773+
it_parses "macro foo;%var #{keyword} true;end", Macro.new("foo", [] of Arg, Expressions.from([MacroVar.new("var"), " #{keyword} true;".macro_literal] of ASTNode))
774+
it_parses "macro foo;var #{keyword} true;end", Macro.new("foo", [] of Arg, "var #{keyword} true;".macro_literal)
775+
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))
776+
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))
777+
end
778+
772779
it_parses "a = 1; pointerof(a)", [Assign.new("a".var, 1.int32), PointerOf.new("a".var)]
773780
it_parses "pointerof(@a)", PointerOf.new("@a".instance_var)
774781
it_parses "a = 1; pointerof(a)", [Assign.new("a".var, 1.int32), PointerOf.new("a".var)]

‎src/compiler/crystal/syntax/lexer.cr

+1
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,7 @@ module Crystal
20322032
while ident_part?(char)
20332033
char = next_char
20342034
end
2035+
beginning_of_line = false
20352036
@token.type = :MACRO_VAR
20362037
@token.value = string_range_from_pool(start)
20372038
@token.macro_state = Token::MacroState.new(whitespace, nest, delimiter_state, beginning_of_line, yields, comment)

0 commit comments

Comments
 (0)
Please sign in to comment.