1
|
1 |
|
import os |
2
|
|
|
|
3
|
|
|
|
4
|
1 |
View Code Duplication |
class Position: |
|
|
|
|
5
|
|
|
""" |
6
|
|
|
Class for start and end position of a node in a SDoc source file. |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
10
|
1 |
|
def __init__(self, file_name: str, start_line: int, start_column: int, end_line: int, end_column: int): |
11
|
|
|
""" |
12
|
|
|
Object constructor. |
13
|
|
|
|
14
|
|
|
:param str file_name: The name of the file where the node is defined. |
15
|
|
|
:param int start_line: The line where the node definition starts. |
16
|
|
|
:param int start_column: The column where the node definition starts. |
17
|
|
|
:param int end_line: The line where the node definition ends. |
18
|
|
|
:param int end_column: The column where the node definition end. |
19
|
|
|
""" |
20
|
1 |
|
self.file_name: str = file_name |
21
|
|
|
""" |
22
|
|
|
The name of the file where the node is defined. |
23
|
|
|
""" |
24
|
|
|
|
25
|
1 |
|
self.start_line: int = start_line |
26
|
|
|
""" |
27
|
|
|
The line where the node definition starts. |
28
|
|
|
""" |
29
|
|
|
|
30
|
1 |
|
self.start_column: int = start_column |
31
|
|
|
""" |
32
|
|
|
The column where the node definition starts. |
33
|
|
|
""" |
34
|
|
|
|
35
|
1 |
|
self.end_line: int = end_line |
36
|
|
|
""" |
37
|
|
|
The line where the node definition ends. |
38
|
|
|
""" |
39
|
1 |
|
self.end_column: int = end_column |
40
|
1 |
|
""" |
41
|
|
|
The column where the node definition end. |
42
|
|
|
""" |
43
|
|
|
|
44
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
45
|
1 |
|
def __str__(self) -> str: |
46
|
|
|
""" |
47
|
|
|
String representation of the position. |
48
|
|
|
""" |
49
|
1 |
|
if not self.file_name: |
50
|
|
|
return "{0:d}.{1:d}".format(self.start_line, self.start_column + 1) |
51
|
|
|
|
52
|
1 |
|
return "{0!s}:{1:d}.{2:d}".format(os.path.relpath(self.file_name), self.start_line, self.start_column + 1) |
53
|
|
|
|
54
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
55
|
|
|
|