@@ -880,18 +880,15 @@ lambda_param[arg_ty]: a=NAME { _PyAST_arg(a->v.Name.id, NULL, NULL, EXTRA) }
880
880
fstring_middle[expr_ty]:
881
881
| fstring_replacement_field
882
882
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
883
- # There are some shenanigans with the fstring_format_spec: Don't try to put it in its own rule
884
- # or otherwise it will try to parse the first token with the regular tokenizer mode (due to the EXTRA).
885
- # TODO: (Ideally we need a way similar to 'memo' so the parser can set the tokenize mode on fstring/normal)
886
883
fstring_replacement_field[expr_ty]:
887
- | '{' a=(yield_expr | star_expressions) debug_expr="="? conversion=[
888
- conv_token="!" conv=NAME { _PyPegen_check_fstring_conversion(p, conv_token, conv) ? NULL : conv }
889
- ] format=[
890
- ':' spec=fstring_format_spec* { spec ? _PyAST_JoinedStr((asdl_expr_seq*)spec, EXTRA) : NULL }
891
- ] '}' {
884
+ | '{' a=(yield_expr | star_expressions) debug_expr="="? conversion=[fstring_conversion] format=[fstring_full_format_spec] '}' {
892
885
_PyPegen_formatted_value(p, a, debug_expr, conversion, format, EXTRA)
893
886
}
894
887
| invalid_replacement_field
888
+ fstring_conversion[expr_ty]:
889
+ | conv_token="!" conv=NAME { _PyPegen_check_fstring_conversion(p, conv_token, conv) }
890
+ fstring_full_format_spec[expr_ty]:
891
+ | ':' spec=fstring_format_spec* { spec ? _PyAST_JoinedStr((asdl_expr_seq*)spec, EXTRA) : NULL }
895
892
fstring_format_spec[expr_ty]:
896
893
| t=FSTRING_MIDDLE { _PyPegen_constant_from_token(p, t) }
897
894
| fstring_replacement_field
0 commit comments