diff --git a/lark/grammar.py b/lark/grammar.py index 2338f04..da1e282 100644 --- a/lark/grammar.py +++ b/lark/grammar.py @@ -51,6 +51,13 @@ class Rule(object): def __repr__(self): return 'Rule(%r, %r, %r, %r)' % (self.origin, self.expansion, self.alias, self.options) + def __hash__(self): + return hash((self.origin, tuple(self.expansion))) + def __eq__(self, other): + if not isinstance(other, Rule): + return False + return self.origin == other.origin and self.expansion == other.expansion + class RuleOptions: def __init__(self, keep_all_tokens=False, expand1=False, priority=None):