Skip to content

gh-133555: Allow to regenerate the parser with Python < 3.14 #133557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Grammar/Tokens
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# When adding new tokens, remember to update the PEG generator in
# Tools/peg_generator/pegen/parser_generator.py
# This will ensure that older versions of Python can generate a Python parser
# using "python -m pegen python <GRAMMAR FILE>".

ENDMARKER
NAME
NUMBER
Expand Down
5 changes: 5 additions & 0 deletions Tools/peg_generator/pegen/parser_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def __init__(self, rules: Dict[str, Rule], tokens: Set[str]):
self.tokens.add("FSTRING_START")
self.tokens.add("FSTRING_END")
self.tokens.add("FSTRING_MIDDLE")
# If python < 3.14 add the virtual tstring tokens
if sys.version_info < (3, 14, 0, 'beta', 1):
self.tokens.add("TSTRING_START")
self.tokens.add("TSTRING_END")
self.tokens.add("TSTRING_MIDDLE")

def visit_NameLeaf(self, node: NameLeaf) -> None:
if node.value not in self.rules and node.value not in self.tokens:
Expand Down
Loading