Completed
Push — master ( 4563ee...0442a2 )
by P.R.
02:07
created

SDocVisitor.errors()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
9
10
# ----------------------------------------------------------------------------------------------------------------------
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
55
# ----------------------------------------------------------------------------------------------------------------------
56