Reorganized syntactical analyzer
This commit is contained in:
parent
c62122b0e3
commit
85d2fe67b6
|
@ -8,6 +8,7 @@ class FileInfo:
|
||||||
_line: int
|
_line: int
|
||||||
_col: int
|
_col: int
|
||||||
_length: int
|
_length: int
|
||||||
|
_lines: int
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -15,11 +16,13 @@ class FileInfo:
|
||||||
line: int,
|
line: int,
|
||||||
col: int,
|
col: int,
|
||||||
length: int,
|
length: int,
|
||||||
|
lines: int = 0,
|
||||||
):
|
):
|
||||||
self._filename = filename
|
self._filename = filename
|
||||||
self._line = line
|
self._line = line
|
||||||
self._col = col
|
self._col = col
|
||||||
self._length = length
|
self._length = length
|
||||||
|
self._lines = lines
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
|
@ -27,6 +30,38 @@ class FileInfo:
|
||||||
f"('{self._filename}',{self._line},{self._col},{self._length})"
|
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):
|
class CompilerError(Exception):
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue