From dc94ebc42f984ed5b1de6c08eba87c808d790bc7 Mon Sep 17 00:00:00 2001 From: night199uk Date: Sat, 17 Aug 2019 17:53:26 -0700 Subject: [PATCH] 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). --- lark/load_grammar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lark/load_grammar.py b/lark/load_grammar.py index 12ae38f..7b3bb3f 100644 --- a/lark/load_grammar.py +++ b/lark/load_grammar.py @@ -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))