Skip to content

Commit

Permalink
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/compiler/lexer/lexer_spec.cr
Original file line number Diff line number Diff line change
@@ -456,6 +456,8 @@ describe "Lexer" do
assert_syntax_error "'\\u{110000}'", "invalid unicode codepoint (too large)"
assert_syntax_error ":+1", "unexpected token"

assert_syntax_error "'\\1'", "invalid char escape sequence"

it_lexes_string %("\\1"), String.new(Bytes[1])
it_lexes_string %("\\4"), String.new(Bytes[4])
it_lexes_string %("\\10"), String.new(Bytes[8])
6 changes: 5 additions & 1 deletion src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
@@ -587,6 +587,10 @@ module Crystal
case char1 = next_char
when '\\'
case char2 = next_char
when '\\'
@token.value = '\\'
when '\''
@token.value = '\''
when 'b'
@token.value = '\b'
when 'e'
@@ -609,7 +613,7 @@ module Crystal
when '\0'
raise "unterminated char literal", line, column
else
@token.value = char2
raise "invalid char escape sequence", line, column
end
when '\''
raise "invalid empty char literal (did you mean '\\\''?)", line, column

0 comments on commit c49cf61

Please sign in to comment.