diff --git a/compiler/source.py b/compiler/source.py index a765a54..14ec6f1 100644 --- a/compiler/source.py +++ b/compiler/source.py @@ -70,6 +70,23 @@ class SourceLocation: return str(self.begin) return f"{str(self.begin)} - {str(self.end)}" + @typecheck + def __lt__(self, other: SourceLocation) -> bool: + return self.end < other.begin + + @typecheck + def __ge__(self, other: SourceLocation) -> bool: + return not self.__lt__(other) + + def __eq__(self, other) -> bool: + if not isinstance(other, self.__class__): + return False + + return all(( + self.begin == self.begin, + self.end == self.end + )) + @property def source_substring(self) -> str: source = self.source.splitlines(keepends=False)