Coverage for phml\nodes\point.py: 100%
18 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 16:33 -0600
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 16:33 -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
8 (1-indexed integer) represents a column in a source file. The offset field (0-indexed integer)
9 represents a character in a source file.
10 """
12 def __init__(self, line: int, column: int, offset: Optional[int] = None):
13 if line < 0:
14 raise IndexError(f"Point.line must be >= 0 but was {line}")
16 self.line = line
18 if column < 0:
19 raise IndexError(f"Point.column must be >= 0 but was {column}")
21 self.column = column
23 if offset is not None and offset < 0:
24 raise IndexError(f"Point.offset must be >= 0 or None but was {line}")
26 self.offset = offset
28 def __eq__(self, obj) -> bool:
29 return bool(
30 obj is not None
31 and isinstance(obj, self.__class__)
32 and self.line == obj.line
33 and self.column == obj.column
34 )
36 def __repr__(self) -> str:
37 return f"point(line: {self.line}, column: {self.column}, offset: {self.offset})"
39 def __str__(self) -> str:
40 return f"{self.line}:{self.column}"