Reorganized syntactical analyzer

This commit is contained in:
Kyler 2024-03-06 21:45:47 -07:00
parent c62122b0e3
commit 85d2fe67b6
2 changed files with 790 additions and 405 deletions

View File

@ -8,6 +8,7 @@ class FileInfo:
_line: int
_col: int
_length: int
_lines: int
def __init__(
self,
@ -15,11 +16,13 @@ class FileInfo:
line: int,
col: int,
length: int,
lines: int = 0,
):
self._filename = filename
self._line = line
self._col = col
self._length = length
self._lines = lines
def __repr__(self) -> str:
return (
@ -27,6 +30,38 @@ class FileInfo:
f"('{self._filename}',{self._line},{self._col},{self._length})"
)
def __add__(self, other: "FileInfo") -> "FileInfo":
filename = self.filename
line = self.line
col = self.col
if self.line != other.line:
if other.lines == 0:
length = other.col + other.length
else:
length = other.length
lines = other.line - self.line
else:
length = (other.col + other.length) - col
lines = 0
return FileInfo(
filename,
line,
col,
length,
lines,
)
@property
def filename(self) -> str: return self._filename
@property
def line(self) -> int: return self._line
@property
def col(self) -> int: return self._col
@property
def length(self) -> int: return self._length
@property
def lines(self) -> int: return self._lines
class CompilerError(Exception):

File diff suppressed because it is too large Load Diff