Skip to content

Commit

Permalink
Fixed #2054: can't format heredoc in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Jan 25, 2016
1 parent 72c4654 commit 9af5350
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -777,4 +777,8 @@ describe Crystal::Formatter do
assert_format "case 1\nwhen 2 # a\n # b\nend"

assert_format "{} of A => B\n{} of Foo => Bar"

assert_format "<<-HTML\n \#{1}x\n HTML"
assert_format "<<-HTML\n \#{1}x\n y\n HTML"
assert_format "<<-HTML\n \#{1}x\n y\n z\n HTML"
end
13 changes: 13 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ module Crystal
end
next_string_token
else
skip_strings

check :INTERPOLATION_START
write "\#{"
delimiter_state = @token.delimiter_state
Expand All @@ -412,6 +414,8 @@ module Crystal
end
end

skip_strings

check :DELIMITER_END
write @token.raw
format_regex_modifiers if is_regex
Expand All @@ -420,6 +424,15 @@ module Crystal
false
end

private def skip_strings
# Heredocs might indice some spaces that are removed
# because of indentation
while @token.type == :STRING
write @token.raw
next_string_token
end
end

def visit(node : RegexLiteral)
accept node.value

Expand Down

0 comments on commit 9af5350

Please sign in to comment.