source: make SourceLocation comparable

This commit is contained in:
Antoine Viallon 2023-05-24 00:22:50 +02:00
parent 8c26293416
commit bcca6d4a6e
Signed by: aviallon
GPG key ID: D126B13AB555E16F

View file

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