Skip to content

Commit

Permalink
[3.10] pythongh-125529: Avoid f-strings in the metagrammar
Browse files Browse the repository at this point in the history
Grammar actions need to be valid Python tokens and the accepted tokens need to be
listed in the actions mini-grammar).

In Python 3.12+ (PEP 701), f-strings are no longer STRING tokens, so pegen fails
to regenerate the metaparser on this Python version, as in:

   PYTHON_FOR_REGEN=python3.12 make regen-pegen-metaparser

Use `+` and plain strings rather than f-strings.

Co-Authored-By: Petr Viktorin <[email protected]>
  • Loading branch information
lysnikolaou and encukou committed Oct 16, 2024
1 parent 850189a commit 697a077
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/grammar_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def named_item(self) -> Optional[NamedItem]:
and
(item := self.item())
):
return NamedItem ( name . string , item , f"{type.string}*" )
return NamedItem ( name . string , item , type . string + "*" )
self.reset(mark)
if cut: return None
cut = False
Expand Down
2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/metagrammar.gram
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ items[NamedItemList]:
| named_item { [named_item] }

named_item[NamedItem]:
| NAME '[' type=NAME '*' ']' '=' ~ item {NamedItem(name.string, item, f"{type.string}*")}
| NAME '[' type=NAME '*' ']' '=' ~ item {NamedItem(name.string, item, type.string+"*")}
| NAME '[' type=NAME ']' '=' ~ item {NamedItem(name.string, item, type.string)}
| NAME '=' ~ item {NamedItem(name.string, item)}
| item {NamedItem(None, item)}
Expand Down

0 comments on commit 697a077

Please sign in to comment.