Skip to content

Commit

Permalink
Add location pointing to the end of a source
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Rosskopf authored and markusrosskopf committed Aug 28, 2023
1 parent 6c6c2ae commit 0a82902
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ dist
docs
.coverage*
*.lobster
.DS_Store
.venv/
.idea
4 changes: 4 additions & 0 deletions trlc/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def to_string(self, include_column=True):
def context_lines(self):
return []

def get_end_location(self):
"""Get location pointing to the end of a source."""
return self


class TRLC_Error(Exception):
""" The universal exception that TRLC raises if something goes wrong
Expand Down
14 changes: 14 additions & 0 deletions trlc/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ def context_lines(self):
return [stripped_line,
" " * stripped_offset + "^" * min(tlen, maxtrail)]

def get_end_location(self):
lines_in_between = self.lexer.content[
self.start_pos : self.end_pos + 1
].count("\n")
end_line = self.line_no + lines_in_between

end_col = self.end_pos + 1
for n in range(self.end_pos, 0, -1):
if self.lexer.content[n] == "\n":
end_col = self.end_pos - n
break

return Location(self.file_name, end_line, end_col)


class Token_Base:
def __init__(self, location, kind, value):
Expand Down

0 comments on commit 0a82902

Please sign in to comment.