@@ -2626,41 +2626,42 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
26262626 case ')' :
26272627 case ']' :
26282628 case '}' :
2629- if (! tok -> level ) {
2630- if ( INSIDE_FSTRING (tok ) && ! current_tok -> curly_bracket_depth && c == '}' ) {
2631- return MAKE_TOKEN ( syntaxerror ( tok , "f-string: single '}' is not allowed" ));
2632- }
2629+ if (INSIDE_FSTRING ( tok ) && ! current_tok -> curly_bracket_depth && c == '}' ) {
2630+ return MAKE_TOKEN ( syntaxerror (tok , "f-string: single '}' is not allowed" ));
2631+ }
2632+ if (! tok -> tok_extra_tokens && ! tok -> level ) {
26332633 return MAKE_TOKEN (syntaxerror (tok , "unmatched '%c'" , c ));
26342634 }
2635- tok -> level -- ;
2636- int opening = tok -> parenstack [tok -> level ];
2637- if (!((opening == '(' && c == ')' ) ||
2638- (opening == '[' && c == ']' ) ||
2639
ED4F
- (opening == '{' && c == '}' )))
2640- {
2641- /* If the opening bracket belongs to an f-string's expression
2642- part (e.g. f"{)}") and the closing bracket is an arbitrary
2643- nested expression, then instead of matching a different
2644- syntactical construct with it; we'll throw an unmatched
2645- parentheses error. */
2646- if (INSIDE_FSTRING (tok ) && opening == '{' ) {
2647- assert (current_tok -> curly_bracket_depth >= 0 );
2648- int previous_bracket = current_tok -> curly_bracket_depth - 1 ;
2649- if (previous_bracket == current_tok -> curly_bracket_expr_start_depth ) {
2650- return MAKE_TOKEN (syntaxerror (tok , "f-string: unmatched '%c'" , c ));
2635+ if (tok -> level > 0 ) {
2636+ tok -> level -- ;
2637+ int opening = tok -> parenstack [tok -> level ];
2638+ if (!tok -> tok_extra_tokens && !((opening == '(' && c == ')' ) ||
2639+ (opening == '[' && c == ']' ) ||
2640+ (opening == '{' && c == '}' ))) {
2641+ /* If the opening bracket belongs to an f-string's expression
2642+ part (e.g. f"{)}") and the closing bracket is an arbitrary
2643+ nested expression, then instead of matching a different
2644+ syntactical construct with it; we'll throw an unmatched
2645+ parentheses error. */
2646+ if (INSIDE_FSTRING (tok ) && opening == '{' ) {
2647+ assert (current_tok -> curly_bracket_depth >= 0 );
2648+ int previous_bracket = current_tok -> curly_bracket_depth - 1 ;
2649+ if (previous_bracket == current_tok -> curly_bracket_expr_start_depth ) {
2650+ return MAKE_TOKEN (syntaxerror (tok , "f-string: unmatched '%c'" , c ));
2651+ }
2652+ }
2653+ if (tok -> parenlinenostack [tok -> level ] != tok -> lineno ) {
2654+ return MAKE_TOKEN (syntaxerror (tok ,
2655+ "closing parenthesis '%c' does not match "
2656+ "opening parenthesis '%c' on line %d" ,
2657+ c , opening , tok -> parenlinenostack [tok -> level ]));
2658+ }
2659+ else {
2660+ return MAKE_TOKEN (syntaxerror (tok ,
2661+ "closing parenthesis '%c' does not match "
2662+ "opening parenthesis '%c'" ,
2663+ c , opening ));
26512664 }
2652- }
2653- if (tok -> parenlinenostack [tok -> level ] != tok -> lineno ) {
2654- return MAKE_TOKEN (syntaxerror (tok ,
2655- "closing parenthesis '%c' does not match "
2656- "opening parenthesis '%c' on line %d" ,
2657- c , opening , tok -> parenlinenostack [tok -> level ]));
2658- }
2659- else {
2660- return MAKE_TOKEN (syntaxerror (tok ,
2661- "closing parenthesis '%c' does not match "
2662- "opening parenthesis '%c'" ,
2663- c , opening ));
26642665 }
26652666 }
26662667
0 commit comments