From 0cbf696303eb7111438dd8e0f80e80699a374ee4 Mon Sep 17 00:00:00 2001 From: John Doty Date: Mon, 9 Sep 2024 06:23:11 -0700 Subject: [PATCH] The start rule cannot be transparent --- parser/parser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/parser/parser.py b/parser/parser.py index e657897..c69fe65 100644 --- a/parser/parser.py +++ b/parser/parser.py @@ -2815,10 +2815,12 @@ class Grammar: def get_precedence(self, name: str) -> None | tuple[Assoc, int]: return self._precedence.get(name) + # TODO: The flattened form should retain NonTerminal, not just str. def generate_nonterminal_dict( self, start: str | None = None ) -> typing.Tuple[dict[str, list[list[str | Terminal]]], set[str]]: - """Convert the rules into a dictionary of productions. + """Convert the rules into a dictionary of productions, and a set of + the names of transparent nonterminals. Our table generators work on a very flat set of productions. This is the first step in flattening the productions from the members: walk the rules @@ -2838,6 +2840,8 @@ class Grammar: rule = nonterminals.get(start) if rule is None: raise ValueError(f"Cannot find a rule named '{start}'") + if rule.transparent: + raise ValueError("The start rule cannot be transparent") queue = [rule] while len(queue) > 0: rule = queue.pop()