MCPcopy Index your code
hub / github.com/python/cpython / KeywordCollectorVisitor

Class KeywordCollectorVisitor

Tools/peg_generator/pegen/parser_generator.py:45–59  ·  view source on GitHub ↗

Visitor that collects all the keywords and soft keywords in the Grammar

Source from the content-addressed store, hash-verified

43
44
45class KeywordCollectorVisitor(GrammarVisitor):
46 """Visitor that collects all the keywords and soft keywords in the Grammar"""
47
48 def __init__(self, gen: "ParserGenerator", keywords: dict[str, int], soft_keywords: set[str]):
49 self.generator = gen
50 self.keywords = keywords
51 self.soft_keywords = soft_keywords
52
53 def visit_StringLeaf(self, node: StringLeaf) -> None:
54 val = ast.literal_eval(node.value)
55 if re.match(r"[a-zA-Z_]\w*\Z", val): # This is a keyword
56 if node.value.endswith("'") and node.value not in self.keywords:
57 self.keywords[val] = self.generator.keyword_type()
58 else:
59 return self.soft_keywords.add(node.value.replace('"', ""))
60
61
62class RuleCheckingVisitor(GrammarVisitor):

Callers 1

collect_rulesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…