8000 Don't emit one token per character in long strings · geddski/python@2cd4001 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cd4001

Browse files
committed
Don't emit one token per character in long strings
That's not very efficient. FIX: Fixes an inefficiency in the parsing of large strings.
1 parent 9f829b5 commit 2cd4001

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/python.grammar

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,29 +242,31 @@ FormatReplacement { "{" (YieldExpression | commaSep<"*"? test>) FormatConversion
242242

243243
formatStringSpecChars { ![{}]+ }
244244

245-
formatString1Content { !['{\\] | "\\" _ | "{{" }
246-
formatString2Content { !["{\\] | "\\" _ | "{{" }
245+
formatString1Content { (!['{\\] | "\\" _ | "{{")+ }
246+
formatString2Content { (!["{\\] | "\\" _ | "{{")+ }
247247

248248
longStringStart<quote> { stringPrefix? quote quote quote }
249249

250-
longString1Content { !['\\] | "\\" _ | "'" longString1_2 }
250+
longString1Content { (!['\\] | "\\" _ | "'" longString1_2)+ }
251251
longString1_2 { !['\\] | "\\" _ | "'" longString1_3 }
252252
longString1_3 { !['\\] | "\\" _ }
253253

254-
longString2Content { !["\\] | "\\" _ | '"' longString2_2 }
254+
longString2Content { (!["\\] | "\\" _ | '"' longString2_2)+ }
255255
longString2_2 { !["\\] | "\\" _ | '"' longString2_3 }
256256
longString2_3 { !["\\] | "\\" _ }
257257

258258
longFormatStringStart<quote> { formatPrefix quote quote quote }
259259

260-
longFormatString1Content { !['\\{] | "\\" _ | "'" longFormatString1_2 | "{{" }
260+
longFormatString1Content { (!['\\{] | "\\" _ | "'" longFormatString1_2 | "{{")+ }
261261
longFormatString1_2 { !['\\{] | "\\" _ | "{{" | "'" longFormatString1_3 }
262262
longFormatString1_3 { !['\\{] | "\\" _ | "{{" }
263263

264-
longFormatString2Content { !["\\{] | "\\" _ | "'" longFormatString2_2 | "{{" }
264+
longFormatString2Content { (!["\\{] | "\\" _ | "'" longFormatString2_2 | "{{")+ }
265265
longFormatString2_2 { !["\\{] | "\\" _ | "{{" | "'" longFormatString2_3 }
266266
longFormatString2_3 { !["\\{] | "\\" _ | "{{" }
267267

268+
@precedence { "{", formatString1Content, formatString2Content, longFormatString1Content, longFormatString2Content }
269+
268270
Number {
269271
(std.digit ("_" | std.digit)* ("." std.digit ("_" | std.digit)*)? | "." std.digit ("_" | std.digit)*)
270272
($[eE] $[+\-]? std.digit ("_" | std.digit)*)? $[jJ]? |

0 commit comments

Comments
 (0)
0