source: make SourceLocation comparable
This commit is contained in:
parent
8c26293416
commit
bcca6d4a6e
1 changed files with 17 additions and 0 deletions
|
|
@ -70,6 +70,23 @@ class SourceLocation:
|
||||||
return str(self.begin)
|
return str(self.begin)
|
||||||
return f"{str(self.begin)} - {str(self.end)}"
|
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
|
@property
|
||||||
def source_substring(self) -> str:
|
def source_substring(self) -> str:
|
||||||
source = self.source.splitlines(keepends=False)
|
source = self.source.splitlines(keepends=False)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue