Completed
Push — master ( 8e7f82...6833e1 )
by P.R.
02:08
created

SDocVisitor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 47.06%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
dl 0
loc 53
ccs 8
cts 17
cp 0.4706
rs 10
c 2
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A errors() 0 8 1
A __init__() 0 18 1
A _error() 0 17 2
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 = []
60
        if token:
61
            messages.append('Error at {0!s}:{1:d}.{2:d}'.format(filename, line_number, column_number))
62
        messages.append(message)
63
        self._io.error(messages)
64
65
66
# ----------------------------------------------------------------------------------------------------------------------
67