Skip to content

Commit

Permalink
Syntax: fix incorrect handling of "%w(" (#5241)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and RX14 committed Nov 3, 2017
1 parent 3c7ed65 commit 94480d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,9 @@ describe "Parser" do
assert_syntax_error %(case x; when /x/; 2; when /x/; end), "duplicate when /x/ in case"
assert_syntax_error %(case x; when X; 2; when X; end), "duplicate when X in case"

assert_syntax_error "%w(", "Unterminated String array literal"
assert_syntax_error "%i(", "Unterminated Symbol array literal"

it "gets corrects of ~" do
node = Parser.parse("\n ~1")
loc = node.location.not_nil!
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,11 @@ module Crystal
next_char
end

if start == current_pos
@token.type = :EOF
return @token
end

@token.type = :STRING
@token.value = string_range(start)
set_token_raw_from_start(start)
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2049,8 +2049,8 @@ module Crystal
when :STRING_ARRAY_END
next_token
break
when :EOF
raise "Unterminated symbol array literal"
else
raise "Unterminated #{elements_type} array literal"
end
end

Expand Down

0 comments on commit 94480d9

Please sign in to comment.