@@ -2435,8 +2435,6 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
2435
2435
// before it.
2436
2436
char start_char = tok_nextc (tok );
2437
2437
char peek1 = tok_nextc (tok );
2438
- char peek2 = tok_nextc (tok );
2439
- tok_backup (tok , peek2 );
2440
2438
tok_backup (tok , peek1 );
2441
2439
tok_backup (tok , start_char );
2442
2440
@@ -2448,27 +2446,28 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
2448
2446
return tok_get_normal_mode (tok , current_tok , token );
2449
2447
}
2450
2448
2451
- // Emit FSTRING_END in case we've reached the end of the string
2452
- if (start_char == current_tok -> f_string_quote
2453
- && (current_tok -> f_string_quote_size != 3 || (start_char == peek1 && start_char == peek2 ))) {
2454
- // Advance the tokenizer state again to create a token out of the end quotes
2455
- for (int i = 0 ; i < current_tok -> f_string_quote_size ; i ++ ) {
2456
- tok_nextc (tok );
2457
- }
2458
-
2459
- if (current_tok -> last_expr_buffer != NULL ) {
2460
- PyMem_Free (current_tok -> last_expr_buffer );
2461
- current_tok -> last_expr_buffer = NULL ;
2462
- current_tok -> last_expr_size = 0 ;
2463
- current_tok -> last_expr_end = -1 ;
2449
+ // Check if we are at the end of the string
2450
+ for (int i = 0 ; i < current_tok -> f_string_quote_size ; i ++ ) {
2451
+ char quote = tok_nextc (tok );
2452
+ if (quote != current_tok -> f_string_quote ) {
2453
+ tok_backup (tok , quote );
2454
+ goto f_string_middle ;
2464
2455
}
2456
+ }
2465
2457
2466
- p_start = tok -> start ;
2467
- p_end = tok -> cur ;
2468
- tok -> tok_mode_stack_index -- ;
2469
- return MAKE_TOKEN (FSTRING_END );
2458
+ if (current_tok -> last_expr_buffer != NULL ) {
2459
+ PyMem_Free (current_tok -> last_expr_buffer );
2460
+ current_tok -> last_expr_buffer = NULL ;
2461
+ current_tok -> last_expr_size = 0 ;
2462
+ current_tok -> last_expr_end = -1 ;
2470
2463
}
2471
2464
2465
+ p_start = tok -> start ;
2466
+ p_end = tok -> cur ;
2467
+ tok -> tok_mode_stack_index -- ;
2468
+ return MAKE_TOKEN (FSTRING_END );
2469
+
2470
+ f_string_middle :
2472
2471
int end_quote_size = 0 ;
2473
2472
int unicode_escape = 0 ;
2474
2473
while (end_quote_size != current_tok -> f_string_quote_size ) {
0 commit comments