Fix for priority in Earley

This commit is contained in:
Erez Shinan 2017-08-06 17:50:32 +03:00
parent 5c4c320c26
commit 121d54ec3a
1 changed files with 6 additions and 8 deletions

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