source: avoid printing source file twice if it is the same for beginning and end (which is very likely).
This commit is contained in:
parent
ff2435171c
commit
a69788ca52
1 changed files with 10 additions and 4 deletions
|
|
@ -17,10 +17,16 @@ class Location:
|
|||
file: str = "<none>"
|
||||
internal: bool = False
|
||||
|
||||
def to_string(self, show_file: bool = True) -> str:
|
||||
filename = "<internal>" if self.internal else self.file
|
||||
message = ""
|
||||
if show_file:
|
||||
message = f"{filename}:"
|
||||
message += f"{self.line}:{self.character}"
|
||||
return message
|
||||
|
||||
def __str__(self) -> str:
|
||||
if self.internal:
|
||||
return "<internal>"
|
||||
return f"{self.file}:{self.line}:{self.character}"
|
||||
return self.to_string()
|
||||
|
||||
@typecheck
|
||||
def __lt__(self, other: Location) -> bool:
|
||||
|
|
@ -76,7 +82,7 @@ class SourceLocation:
|
|||
def __str__(self):
|
||||
if self.begin == self.end:
|
||||
return str(self.begin)
|
||||
return f"{str(self.begin)} - {str(self.end)}"
|
||||
return f"{str(self.begin)} - {self.end.to_string(self.begin.file != self.end.file)}"
|
||||
|
||||
@typecheck
|
||||
def __lt__(self, other: SourceLocation) -> bool:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue