Total Complexity | 4 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | """ |
||
11 | class SDocVisitor: |
||
12 | """ |
||
13 | Parent visitor for SDoc level 1 & 2. |
||
14 | """ |
||
15 | |||
16 | # ------------------------------------------------------------------------------------------------------------------ |
||
17 | def __init__(self): |
||
18 | """ |
||
19 | Object constructor. |
||
20 | """ |
||
21 | self._errors = 0 |
||
22 | """ |
||
23 | The error count. |
||
24 | |||
25 | :type: int |
||
26 | """ |
||
27 | |||
28 | # ------------------------------------------------------------------------------------------------------------------ |
||
29 | @property |
||
30 | def errors(self): |
||
31 | """ |
||
32 | Getter for the error count. |
||
33 | |||
34 | :rtype: int |
||
35 | """ |
||
36 | return self._errors |
||
37 | |||
38 | # ------------------------------------------------------------------------------------------------------------------ |
||
39 | def _error(self, message, token): |
||
40 | """ |
||
41 | Logs an error. |
||
42 | |||
43 | :param str message: The error message.this message will be appended with 'at filename:line.column' ot the token. |
||
44 | :param antlr4.Token.CommonToken token: The token where the error occurred. |
||
45 | """ |
||
46 | self._errors += 1 |
||
47 | |||
48 | filename = token.getInputStream().fileName # Replace fileName with get_source_name() when implemented in ANTLR. |
||
49 | line_number = token.line |
||
50 | column_number = token.column + 1 |
||
51 | if token: |
||
52 | print("Error at {0!s}:{1:d}.{2:d}:".format(filename, line_number, column_number)) |
||
53 | print(message) |
||
54 | |||
56 |