Skip to content

Commit

Permalink
Speed up resolve_term_references
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaIng committed Sep 14, 2021
1 parent 859b200 commit 47124f9
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,18 +857,14 @@ def resolve_term_references(term_dict):
except KeyError:
raise GrammarError("Terminal used but not defined: %s" % item)
assert term_value is not None
if term_value is token_tree:
raise GrammarError(
"Recursion in terminal '%s' (recursion is only allowed in rules, not terminals)" % name)
exp.children[0] = term_value
changed = True
if not changed:
break

for name, term in term_dict.items():
if term: # Not just declared
for child in term.children:
ids = [id(x) for x in child.iter_subtrees()]
if id(term) in ids:
raise GrammarError("Recursion in terminal '%s' (recursion is only allowed in rules, not terminals)" % name)


def options_from_rule(name, params, *x):
if len(x) > 1:
Expand Down

0 comments on commit 47124f9

Please sign in to comment.