Browse Source

BUGFIX for declared terminals

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.7.8
Erez Sh 5 years ago
parent
commit
17b6d6d3b3
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      lark/load_grammar.py

+ 6
- 4
lark/load_grammar.py View File

@@ -656,16 +656,18 @@ def resolve_term_references(term_defs):
raise GrammarError("Rules aren't allowed inside terminals (%s in %s)" % (item, name))
if item.type == 'TERMINAL':
term_value = term_dict[item]
assert term_value is not None
exp.children[0] = term_value
changed = True
if not changed:
break

for name, term in term_dict.items():
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)
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, *x):


Loading…
Cancel
Save