Coverage for phml\nodes\point.py: 54%
24 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-30 09:38 -0600
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-30 09:38 -0600
1from typing import Optional
4class Point:
5 """Represents one place in a source file.
7 The line field (1-indexed integer) represents a line in a source file. The column field (1-indexed integer) represents a column in a source file. The offset field (0-indexed integer) represents a character in a source file.
8 """
10 def __init__(self, line: int, column: int, offset: Optional[int] = None):
11 if line < 0:
12 raise IndexError(f"Point.line must be >= 0 but was {line}")
14 self.line = line
16 if column < 0:
17 raise IndexError(f"Point.column must be >= 0 but was {column}")
19 self.column = column
21 if offset is not None and offset < 0:
22 raise IndexError(f"Point.offset must be >= 0 or None but was {line}")
24 self.offset = offset
26 def __eq__(self, obj) -> bool:
27 if isinstance(obj, self.__class__):
28 if self.line == obj.line:
29 if self.column == obj.column:
30 return True
31 else:
32 # print(f"{self.column} != {obj.column}: Columns are not equal")
33 return False
34 else:
35 # print(f"{self.line} != {obj.line}: Lines are not equal")
36 return False
37 # print(
38 # f"{type(self).__name__} != {type(obj).__name__}: Point can not be equated to {type(obj).__name__}"
39 # )
40 return False
42 def __repr__(self) -> str:
43 return f"point(line: {self.line}, column: {self.column}, offset: {self.offset})"
45 def __str__(self) -> str:
46 return f"{self.line}:{self.column}"