Skip to content

Commit

Permalink
Fixed #4297: formatter bug with %w{...}
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Apr 16, 2017
1 parent b88c28f commit a8fbfb0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 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 @@ -336,6 +336,8 @@ describe Crystal::Formatter do

assert_format "%w(one two three)", "%w(one two three)"
assert_format "%i(one two three)", "%i(one two three)"
assert_format "%w{one( two( three)}", "%w{one( two( three)}"
assert_format "%i{one( two( three)}", "%i{one( two( three)}"

assert_format "/foo/"
assert_format "/foo/imx"
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ module Crystal
when '(', '{', '[', '<'
start_char = next_char
next_char :SYMBOL_ARRAY_START
@token.raw = "%i#{start_char}" if @wants_raw
@token.delimiter_state = Token::DelimiterState.new(:symbol_array, start_char, closing_char(start_char))
else
@token.type = :"%"
Expand Down Expand Up @@ -335,6 +336,7 @@ module Crystal
when '(', '{', '[', '<'
start_char = next_char
next_char :STRING_ARRAY_START
@token.raw = "%w#{start_char}" if @wants_raw
@token.delimiter_state = Token::DelimiterState.new(:string_array, start_char, closing_char(start_char))
else
@token.type = :"%"
Expand Down Expand Up @@ -2399,6 +2401,7 @@ module Crystal
end

if current_char == @token.delimiter_state.end
@token.raw = current_char.to_s if @wants_raw
next_char
@token.type = :STRING_ARRAY_END
return @token
Expand Down
8 changes: 2 additions & 6 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,7 @@ module Crystal
next_token
when :STRING_ARRAY_START, :SYMBOL_ARRAY_START
first = true
if @token.type == :STRING_ARRAY_START
write "%w("
else
write "%i("
end
write @token.raw
count = 0
while true
has_space_newline = space_newline?
Expand All @@ -656,7 +652,7 @@ module Crystal
write @token.raw
first = false
when :STRING_ARRAY_END
write ")"
write @token.raw
next_token
break
end
Expand Down

0 comments on commit a8fbfb0

Please sign in to comment.