Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert " in match pattern and add test for escape chars #162

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/erg_parser/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ impl Lexer /*<'a>*/ {
'r' => s.push('\r'),
'n' => s.push('\n'),
'\'' => s.push('\''),
'"' => s.push('"'),
't' => s.push_str(" "), // tab is invalid, so changed into 4 whitespace
'\\' => s.push('\\'),
_ => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/erg_parser/tests/test1_basic_syntax.er
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ a, _, ...b = five_elem_tuple
f x, y =
x + y
if! True, do!:
print! "\\hello, world\""
print! "\"\\hello, world\\\""
10.times! do!:
if! x.y.z, do!:
print! ""
Expand Down
2 changes: 1 addition & 1 deletion compiler/erg_parser/tests/test3_literal_syntax.er
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
0.00, -0.0, .1, 400.

# Str Literal
"", "a", "こんにちは", "\" \\ "
"", "a", "こんにちは", "\"\\", "\"\'\\\0\r\n\t"

# Boolean Litteral
True, False
Expand Down
8 changes: 5 additions & 3 deletions compiler/erg_parser/tests/tokenize_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(Comma, ","),
(UBar, "_"),
(Comma, ","),
(Spread, "..."), // EllipsisLit
(EllipsisLit, "..."),
(Symbol, "b"),
(Equal, "="),
(Symbol, "five_elem_tuple"),
Expand All @@ -62,7 +62,7 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(Newline, newline),
(Indent, " "),
(Symbol, "print!"),
(StrLit, "\"\\\\hello, world\\\"\""),
(StrLit, "\"\"\\hello, world\\\"\""),
(Newline, newline),
(NatLit, "10"),
(Dot, "."),
Expand Down Expand Up @@ -264,7 +264,9 @@ fn test_lexer_for_literals() -> ParseResult<()> {
(Comma, ","),
(StrLit, "\"こんにちは\""),
(Comma, ","),
(StrLit, "\"\\\" \\\\ \""),
(StrLit, "\"\"\\\""),
(Comma, ","),
(StrLit, "\"\"\'\\\0\r\n \""),
(Newline, newline),
(Newline, newline),
(Newline, newline),
Expand Down