Passed
Push — master ( 1ac98c...ed1e15 )
by P.R.
01:49
created

SDocVisitor.errors()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
crap 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
9
10
# ----------------------------------------------------------------------------------------------------------------------
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
64
65
# ----------------------------------------------------------------------------------------------------------------------
66