From 121d54ec3a387e195b4b0555f79e705bbbeab16d Mon Sep 17 00:00:00 2001
From: Erez Shinan <erezshin+git@gmail.com>
Date: Sun, 6 Aug 2017 17:50:32 +0300
Subject: [PATCH] Fix for priority in Earley

---
 lark/parsers/earley.py | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/lark/parsers/earley.py b/lark/parsers/earley.py
index 216061b..4444113 100644
--- a/lark/parsers/earley.py
+++ b/lark/parsers/earley.py
@@ -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