Browse Source

Implement eq/hash for Rule (Issue #278)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.66
Erez Shinan 6 years ago
parent
commit
5c68bf677a
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      lark/grammar.py

+ 7
- 0
lark/grammar.py View File

@@ -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):


Loading…
Cancel
Save