Skip to content
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
6 changes: 3 additions & 3 deletions Tools/peg_generator/pegen/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def string(self) -> Optional[tokenize.TokenInfo]:

@memoize
def fstring_start(self) -> Optional[tokenize.TokenInfo]:
FSTRING_START = getattr(token, "FSTRING_START")
FSTRING_START = getattr(token, "FSTRING_START", None)
if not FSTRING_START:
return None
tok = self._tokenizer.peek()
Expand All @@ -217,7 +217,7 @@ def fstring_start(self) -> Optional[tokenize.TokenInfo]:

@memoize
def fstring_middle(self) -> Optional[tokenize.TokenInfo]:
FSTRING_MIDDLE = getattr(token, "FSTRING_MIDDLE")
FSTRING_MIDDLE = getattr(token, "FSTRING_MIDDLE", None)
if not FSTRING_MIDDLE:
return None
tok = self._tokenizer.peek()
Expand All @@ -227,7 +227,7 @@ def fstring_middle(self) -> Optional[tokenize.TokenInfo]:

@memoize
def fstring_end(self) -> Optional[tokenize.TokenInfo]:
FSTRING_END = getattr(token, "FSTRING_END")
FSTRING_END = getattr(token, "FSTRING_END", None)
if not FSTRING_END:
return None
tok = self._tokenizer.peek()
Expand Down
6 changes: 6 additions & 0 deletions Tools/peg_generator/pegen/parser_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import ast
import contextlib
import re
Expand Down Expand Up @@ -75,6 +76,11 @@ class RuleCheckingVisitor(GrammarVisitor):
def __init__(self, rules: Dict[str, Rule], tokens: Set[str]):
self.rules = rules
self.tokens = tokens
# If python < 3.12 add the virtual fstring tokens
if sys.version_info < (3, 12):
self.tokens.add("FSTRING_START")
self.tokens.add("FSTRING_END")
self.tokens.add("FSTRING_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