source: add ordering to Location
This commit is contained in:
parent
5b3f0262a7
commit
bd402beba7
1 changed files with 36 additions and 0 deletions
|
|
@ -6,6 +6,10 @@ from dataclasses import dataclass
|
|||
from beartype import beartype
|
||||
from beartype.typing import Optional
|
||||
|
||||
from .logger import Logger
|
||||
|
||||
logger = Logger(__name__)
|
||||
|
||||
|
||||
@beartype
|
||||
@dataclass
|
||||
|
|
@ -17,6 +21,38 @@ class Location:
|
|||
def __str__(self) -> str:
|
||||
return f"{self.file}:{self.line}:{self.character}"
|
||||
|
||||
@beartype
|
||||
def __lt__(self, other: Location) -> bool:
|
||||
if self.file != other.file:
|
||||
logger.trace(f"{self} is not in the same file as {other}")
|
||||
return False
|
||||
|
||||
if self.line < other.line:
|
||||
logger.trace(f"{self} lesser than {other}")
|
||||
return True
|
||||
|
||||
if self.line > other.line:
|
||||
logger.trace(f"{self} greater than {other}")
|
||||
return False
|
||||
|
||||
if self.character < other.character:
|
||||
logger.trace(f"{self} lesser than {other}")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@beartype
|
||||
def __ge__(self, other: Location) -> bool:
|
||||
return not self.__lt__(other)
|
||||
|
||||
@beartype
|
||||
def __eq__(self, other: Location) -> bool:
|
||||
return all((
|
||||
self.file == other.file,
|
||||
self.line == other.line,
|
||||
self.character == other.character
|
||||
))
|
||||
|
||||
|
||||
@beartype
|
||||
class SourceLocation:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue