Skip to content

Commit

Permalink
Fix +=, -=, and == operators of RuleSize
Browse files Browse the repository at this point in the history
  • Loading branch information
akosthekiss committed Dec 12, 2024
1 parent f5de911 commit 2606880
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions grammarinator/runtime/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ def __add__(self, other):
def __iadd__(self, other):
self.depth += other.depth
self.tokens += other.tokens
return self

def __sub__(self, other):
return RuleSize(depth=self.depth - other.depth, tokens=self.tokens - other.tokens)

def __isub__(self, other):
self.depth -= other.depth
self.tokens -= other.tokens
return self

def __eq__(self, other):
if not isinstance(other, RuleSize):
return NotImplemented
return self.depth == other.depth and self.tokens == other.tokens

def __le__(self, other):
Expand Down

0 comments on commit 2606880

Please sign in to comment.