Skip to content

Commit 337fe41

Browse files
[Tokenizer] Fix black slash issue in the string
1 parent d314f09 commit 337fe41

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lpython/parser/tokenizer.re

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,18 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost
275275
integer = int_dec | int_oct | int_bin | int_hex;
276276
real = (significand exp?) | (digit+ exp);
277277
imag_number = (real | digit+)[jJ];
278-
string1 = '"' ('\\"'|[^"\x00])* '"';
279-
string2 = "'" ("\\'"|[^'\x00])* "'";
280-
string3 = '"""' ( '\\"' | '"' [^"\x00] | '""' [^"\x00] | [^"\x00] )* '"""';
281-
string4 = "'''" ( "\\'" | "'" [^'\x00] | "''" [^'\x00] | [^'\x00] )* "'''";
278+
string1 = '"' ('\\'[^\x00] | [^"\x00\n\\])* '"';
279+
string2 = "'" ("\\"[^\x00] | [^'\x00\n\\])* "'";
280+
string3 = '"""' ( '\\'[^\x00]
281+
| ('"' | '"' '\\'+) [^"\x00\\]
282+
| ('""' | '""' '\\'+) [^"\x00\\]
283+
| [^"\x00\\] )*
284+
'"""';
285+
string4 = "'''" ( "\\"[^\x00]
286+
| ("'" | "'" "\\"+) [^'\x00\\]
287+
| ("''" | "''" "\\"+) [^'\x00\\]
288+
| [^'\x00\\] )*
289+
"'''";
282290
type_ignore = "#" whitespace? "type:" whitespace? "ignore" [^\n\x00]*;
283291
type_comment = "#" whitespace? "type:" whitespace? [^\n\x00]*;
284292
comment = "#" [^\n\x00]*;

0 commit comments

Comments
 (0)