Skip to content

Commit

Permalink
Fix: accept newline before closing macro
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jul 13, 2018
1 parent e12a1fa commit ad5656d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1169,4 +1169,6 @@ describe Crystal::Formatter do

assert_format "begin 0[1] rescue 2 end"
assert_format "begin\n 0[1] rescue 2 end", "begin 0[1] rescue 2 end"

assert_format "{%\n if 1\n 2\n end\n%}"
end
1 change: 1 addition & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ module Crystal
it_parses "{%\na = 1\n%}", MacroExpression.new(Assign.new("a".var, 1.int32), output: false)
it_parses "{% a = 1 if 2 %}", MacroExpression.new(If.new(2.int32, Assign.new("a".var, 1.int32)), output: false)
it_parses "{% if 1; 2; end %}", MacroExpression.new(If.new(1.int32, 2.int32), output: false)
it_parses "{%\nif 1; 2; end\n%}", MacroExpression.new(If.new(1.int32, 2.int32), output: false)
it_parses "{% unless 1; 2; end %}", MacroExpression.new(If.new(1.int32, Nop.new, 2.int32), output: false)
it_parses "{%\n1\n2\n3\n%}", MacroExpression.new(Expressions.new([1.int32, 2.int32, 3.int32] of ASTNode), output: false)

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 @@ -3012,6 +3012,7 @@ module Crystal

macro_control = parse_macro_control(@line_number, @column_number)
if macro_control
skip_space_or_newline
check :"%}"
next_token_skip_space
macro_control
Expand Down

0 comments on commit ad5656d

Please sign in to comment.