From 07e5416092e2e7ceb919827b2d801548ed0a7f69 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Fri, 13 Jul 2018 18:30:41 -0300 Subject: [PATCH] Fix: accept newline before closing macro --- spec/compiler/formatter/formatter_spec.cr | 2 ++ spec/compiler/parser/parser_spec.cr | 1 + src/compiler/crystal/syntax/parser.cr | 1 + 3 files changed, 4 insertions(+) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index 4bf1d468f7aa..e6c43a32525f 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -1167,4 +1167,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 diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 9f16d059515e..6036137e5b8a 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -779,6 +779,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) diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index 69911b6d2040..bc5e2185a4f9 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -3014,6 +3014,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