Browse Source

Fix for priority in Earley

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
121d54ec3a
1 changed files with 6 additions and 8 deletions
  1. +6
    -8
      lark/parsers/earley.py

+ 6
- 8
lark/parsers/earley.py View File

@@ -224,16 +224,14 @@ class ApplyCallbacks(Transformer_NoRecurse):
return Tree(rule.origin, children)

def _compare_rules(rule1, rule2):
if rule1 == rule2:
return 0

if rule1.options and rule2.options:
if rule1.options.priority is not None and rule2.options.priority is not None:
assert rule1.options.priority != rule2.options.priority, "Priority is the same between both rules: %s == %s" % (rule1, rule2)
return -compare(rule1.options.priority, rule2.options.priority)

if rule1.origin != rule2.origin:
if rule1.options and rule2.options:
if rule1.options.priority is not None and rule2.options.priority is not None:
assert rule1.options.priority != rule2.options.priority, "Priority is the same between both rules: %s == %s" % (rule1, rule2)
return -compare(rule1.options.priority, rule2.options.priority)

return 0

c = compare( len(rule1.expansion), len(rule2.expansion))
if rule1.origin.startswith('__'): # XXX hack! We need to set priority in parser, not here
c = -c


Loading…
Cancel
Save