Failed Conditions
Pull Request — master (#1152)
by Lasse
03:36
created

coalib.parsing.StringProcessing.LineParser.parse()   B

Complexity

Conditions 4

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 34
rs 8.5806
1
from coalib.misc.Decorators import generate_ordering, generate_repr
2
3
4
@generate_repr("match", "range")
5
@generate_ordering("range", "match")
6
class Match:
7
    """
8
    Stores information about a single textual match.
9
    """
10
11
    def __init__(self, match, position):
12
        """
13
        Instantiates a new Match.
14
15
        :param match:    The actual matched string.
16
        :param position: The position where the match was found. Starts from
17
                         zero.
18
        """
19
        self._match = match
20
        self._position = position
21
22
    def __len__(self):
23
        return len(self.match)
24
25
    def __str__(self):
26
        return self.match
27
28
    @property
29
    def match(self):
30
        """
31
        Returns the text matched.
32
33
        :returns: The text matched.
34
        """
35
        return self._match
36
37
    @property
38
    def position(self):
39
        """
40
        Returns the position where the text was matched (zero-based).
41
42
        :returns: The position.
43
        """
44
        return self._position
45
46
    @property
47
    def end_position(self):
48
        """
49
        Marks the end position of the matched text (zero-based).
50
51
        :returns: The end-position.
52
        """
53
        return len(self) + self.position
54
55
    @property
56
    def range(self):
57
        """
58
        Returns the position range where the text was matched.
59
60
        :returns: A pair indicating the position range. The first element is
61
                  the start position, the second one the end position.
62
        """
63
        return (self.position, self.end_position)
64