Visitor that collects all the keywords and soft keywords in the Grammar
| 43 | |
| 44 | |
| 45 | class 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 | |
| 62 | class RuleCheckingVisitor(GrammarVisitor): |
no outgoing calls
no test coverage detected
searching dependent graphs…