Skip to content

Commit

Permalink
Fix ASTNode#to_s for {% verbatim do %} ... {% end %} (crystal-lan…
Browse files Browse the repository at this point in the history
…g#6665)

For example, it shows wrong result.

Code:

    p!({% verbatim do %}1{{2}}3{% end %})

Result:

    {% verbatim do %}1
    {{ 2 }}
    3
    {% end %} # => 3

This commit fixes it.
  • Loading branch information
makenowjust authored and Ezra Stevens committed Oct 1, 2018
1 parent 7fa2119 commit d806ff8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe "ASTNode#to_s" do
expect_to_s "1.&*"
expect_to_s "1.&**"
expect_to_s "1.~(2)"
expect_to_s %({% verbatim do %}\n 1{{ 2 }}\n 3{{ 4 }}\n{% end %})
expect_to_s %({% for foo in bar %}\n {{ if true\n foo\n bar\nend }}\n{% end %})
expect_to_s %(asm("nop" ::::))
expect_to_s %(asm("nop" : "a"(1), "b"(2) : "c"(3), "d"(4) : "e", "f" : "volatile", "alignstack", "intel"))
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,9 @@ module Crystal

def visit(node : MacroVerbatim)
@str << "{% verbatim do %}"
node.exp.accept self
inside_macro do
node.exp.accept self
end
@str << "{% end %}"
false
end
Expand Down

0 comments on commit d806ff8

Please sign in to comment.