Skip to content

Commit

Permalink
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
@@ -70,6 +70,8 @@ describe "Parser" do
it_parses %(:"\\\\foo"), "\\foo".symbol
it_parses %(:"\\\"foo"), "\"foo".symbol
it_parses %(:"\\\"foo\\\""), "\"foo\"".symbol
it_parses %(:"\\b\\n\\r\\t\\v\\f\\e"), "\b\n\r\t\v\f\e".symbol
it_parses %(:"\\u{61}"), "a".symbol

it_parses "[1, 2]", ([1.int32, 2.int32] of ASTNode).array
it_parses "[\n1, 2]", ([1.int32, 2.int32] of ASTNode).array
28 changes: 26 additions & 2 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
@@ -458,8 +458,32 @@ module Crystal
char = next_char
case char
when '\\'
if peek_next_char == '"' || peek_next_char == '\\'
io << next_char
case char = next_char
when 'b'
io << "\u{8}"
when 'n'
io << "\n"
when 'r'
io << "\r"
when 't'
io << "\t"
when 'v'
io << "\v"
when 'f'
io << "\f"
when 'e'
io << "\e"
when 'u'
io << consume_string_unicode_escape
when '0', '1', '2', '3', '4', '5', '6', '7'
io << consume_octal_escape(char)
when '\n'
@line_number += 1
io << "\n"
when '\0'
raise "unterminated quoted symbol", line, column
else
io << char
end
when '"'
break

0 comments on commit a6a0fb7

Please sign in to comment.