Skip to content

Commit 47124f9

Browse files
committed
Speed up resolve_term_references
1 parent 859b200 commit 47124f9

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lark/load_grammar.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -857,18 +857,14 @@ def resolve_term_references(term_dict):
857857
except KeyError:
858858
raise GrammarError("Terminal used but not defined: %s" % item)
859859
assert term_value is not None
860+
if term_value is token_tree:
861+
raise GrammarError(
862+
"Recursion in terminal '%s' (recursion is only allowed in rules, not terminals)" % name)
860863
exp.children[0] = term_value
861864
changed = True
862865
if not changed:
863866
break
864867

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

873869
def options_from_rule(name, params, *x):
874870
if len(x) > 1:

0 commit comments

Comments
 (0)