Beispiel #1
0
 def visit_NameLeaf(self, node: NameLeaf) -> None:
     if node.value not in self.rules and node.value not in self.tokens.values(
     ):
         # TODO: Add line/col info to (leaf) nodes
         print("HEY HOOOOOOO")
         print(node)
         print("WTFFFFFFFFFF")
         raise GrammarError(f"Dangling reference to rule {node.value!r}")
 def __init__(self, rules: Dict[str, Rule], file: Optional[IO[Text]]):
     if "start" not in rules:
         raise GrammarError("Grammar must have a 'start' rule")
     checker = RuleCheckingVisitor(rules)
     for rule in rules.values():
         checker.visit(rule)
     self.rules = rules
     self.file = file
     self.level = 0
     compute_nullables(rules)
     self.first_graph, self.first_sccs = compute_left_recursives(self.rules)
     self.todo = self.rules.copy()  # Rules to generate
     self.counter = 0  # For name_rule()/name_loop()
Beispiel #3
0
 def __init__(self, grammar: Grammar, file: Optional[IO[Text]]):
     self.grammar = grammar
     self.rules = grammar.rules
     if "start" not in self.rules:
         raise GrammarError("Grammar must have a 'start' rule")
     checker = RuleCheckingVisitor(self.rules)
     for rule in self.rules.values():
         checker.visit(rule)
     self.file = file
     self.level = 0
     compute_nullables(self.rules)
     self.first_graph, self.first_sccs = compute_left_recursives(self.rules)
     self.todo = self.rules.copy()  # Rules to generate
     self.counter = 0  # For name_rule()/name_loop()
     self.keyword_counter = 499  # For keyword_type()
 def __init__(self, grammar: Grammar, file: Optional[IO[Text]]):
     self.grammar = grammar
     self.rules = grammar.rules
     if "trailer" not in grammar.metas and "start" not in self.rules:
         raise GrammarError(
             "Grammar without a trailer must have a 'start' rule")
     checker = RuleCheckingVisitor(self.rules)
     for rule in self.rules.values():
         checker.visit(rule)
     self.file = file
     self.level = 0
     compute_nullables(self.rules)
     self.first_graph, self.first_sccs = compute_left_recursives(self.rules)
     self.todo = self.rules.copy()  # Rules to generate
     self.counter = 0  # For name_rule()/name_loop()
     self.keyword_counter = 499  # For keyword_type()
     self.all_rules: Dict[str, Rule] = {}  # Rules + temporal rules
     self._local_variable_stack: List[List[str]] = []
 def visit_NameLeaf(self, node: NameLeaf):
     if (node.value not in self.rules
             and node.value not in token.tok_name.values()
             and node.value != "CUT"):
         # TODO: Add line/col info to (leaf) nodes
         raise GrammarError(f"Dangling reference to rule {node.value!r}")
Beispiel #6
0
 def validate_rule_names(self):
     for rule in self.rules:
         if rule.startswith("_"):
             raise GrammarError(f"Rule names cannot start with underscore: '{rule}'")
Beispiel #7
0
 def visit_NamedItem(self, node: NameLeaf) -> None:
     if node.name and node.name.startswith("_"):
         raise GrammarError(f"Variable names cannot start with underscore: '{node.name}'")
     self.visit(node.item)
Beispiel #8
0
 def visit_NameLeaf(self, node: NameLeaf) -> None:
     if node.value not in self.rules and node.value not in self.tokens:
         raise GrammarError(f"Dangling reference to rule {node.value!r}")
Beispiel #9
0
 def visit_NameLeaf(self, node: NameLeaf) -> None:
     if node.value not in self.rules and node.value not in self.tokens:
         # TODO: Add line/col info to (leaf) nodes
         raise GrammarError(f"Dangling reference to rule {node.value!r}")