8000 Allow escaped quotes in raw strings · kaizhi-singtown/python@fa12659 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa12659

Browse files
committed
Allow escaped quotes in raw strings
FIX: Support escaped quotes inside raw strings. Closes lezer-parser#27
1 parent 14ef0d5 commit fa12659

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/tokens.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ export const strings = new ExternalTokenizer((input, stack) => {
180180
return
181181
}
182182
break
183+
} else if (input.next == backslash && !escapes && input.peek(1) > -1) {
184+
// Raw strings still ignore escaped quotes, weirdly.
185+
input.advance(2)
183186
} else if (input.next == quote && (!long || input.peek(1) == quote && input.peek(2) == quote)) {
184187
if (input.pos == start) {
185188
input.acceptToken(stringEnd, long ? 3 : 1)

test/expression.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ Script(ExpressionStatement(ContinuedString(String, String)),
3333
ExpressionStatement(String),
3434
ExpressionStatement(String))
3535

36+
# Raw string
37+
38+
r"foo\"" + r'\\'
39+
40+
==>
41+
42+
Script(ExpressionStatement(BinaryExpression(String,ArithOp,String)))
43+
3644
# Bracketed continued string
3745

3846
print('00300:'

0 commit comments

Comments
 (0)
0