Fix Earley non-determinism

Rule.order should be set as the index of each expansion with rules
of the same name (e.g: a : b    # rule.order 1 | c    # rule.order 2).
This commit is contained in:
night199uk 2019-08-17 17:53:26 -07:00 committed by Erez Sh
parent d845aa3bf1
commit dc94ebc42f
1 changed files with 2 additions and 2 deletions

View File

@ -511,12 +511,12 @@ class Grammar:
simplify_rule = SimplifyRule_Visitor()
compiled_rules = []
for i, rule_content in enumerate(rules):
for rule_content in rules:
name, tree, options = rule_content
simplify_rule.visit(tree)
expansions = rule_tree_to_text.transform(tree)
for expansion, alias in expansions:
for i, (expansion, alias) in enumerate(expansions):
if alias and name.startswith('_'):
raise GrammarError("Rule %s is marked for expansion (it starts with an underscore) and isn't allowed to have aliases (alias=%s)" % (name, alias))