Skip to content

Commit 7ae1b60

Browse files
committed
Revert to using different grammar rules for tstring due to format_spec
1 parent d2bd673 commit 7ae1b60

File tree

3 files changed

+1364
-1131
lines changed

3 files changed

+1364
-1131
lines changed

Grammar/python.gram

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,7 @@ fstring_middle[expr_ty]:
916916
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
917917
fstring_replacement_field[expr_ty]:
918918
| '{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' {
919-
(TOK_GET_MODE(p->tok)->tstring ? _PyPegen_interpolation : _PyPegen_formatted_value)(
920-
p, a, debug_expr, conversion, format, rbrace, EXTRA) }
919+
_PyPegen_formatted_value(p, a, debug_expr, conversion, format, rbrace, EXTRA) }
921920
| invalid_replacement_field
922921
fstring_conversion[ResultTokenWithMetadata*]:
923922
| conv_token="!" conv=NAME { _PyPegen_check_fstring_conversion(p, conv_token, conv) }
@@ -929,8 +928,15 @@ fstring_format_spec[expr_ty]:
929928
fstring[expr_ty]:
930929
| a=FSTRING_START b=fstring_middle* c=FSTRING_END { _PyPegen_joined_str(p, a, (asdl_expr_seq*)b, c) }
931930

931+
tstring_replacement_field[expr_ty]:
932+
| '{' a=annotated_rhs debug_expr='='? conversion=[fstring_conversion] format=[fstring_full_format_spec] rbrace='}' {
933+
_PyPegen_interpolation(p, a, debug_expr, conversion, format, rbrace, EXTRA) }
934+
| invalid_replacement_field
935+
tstring_middle[expr_ty]:
936+
| tstring_replacement_field
937+
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
932938
tstring[expr_ty] (memo):
933-
| a=TSTRING_START b=fstring_middle* c=FSTRING_END { _PyPegen_template_str(p, a, (asdl_expr_seq*)b, c) }
939+
| a=TSTRING_START b=tstring_middle* c=FSTRING_END { _PyPegen_template_str(p, a, (asdl_expr_seq*)b, c) }
934940

935941
string[expr_ty]: s[Token*]=STRING { _PyPegen_constant_from_string(p, s) }
936942
strings[expr_ty] (memo): a[asdl_expr_seq*]=(fstring|string)+ { _PyPegen_concatenate_strings(p, a, EXTRA) }

0 commit comments

Comments
 (0)