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