-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdouble_char_exceptions.py
58 lines (40 loc) · 2.37 KB
/
double_char_exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from dodona.translator import Translator
from exceptions.utils import DelayedExceptions, FeedbackException
class DoubleCharError(FeedbackException):
"""Base class for double char related exceptions in this module."""
def __init__(self, trans: Translator, msg: str, line: int, pos: int):
super(DoubleCharError, self).__init__(trans=trans, msg=msg, line=line, pos=pos)
class LocatableDoubleCharError(DoubleCharError):
"""Exceptions that can be located"""
def __init__(self, trans: Translator, msg: str, line: int, pos: int):
super(LocatableDoubleCharError, self).__init__(trans=trans, msg=msg, line=line, pos=pos)
def __lt__(self, other):
return (self.line, self.pos) < (other.line, other.pos)
def __gt__(self, other):
return (self.line, self.pos) > (other.line, other.pos)
def __le__(self, other):
return (self.line, self.pos) <= (other.line, other.pos)
def __ge__(self, other):
return (self.line, self.pos) >= (other.line, other.pos)
def __eq__(self, other):
return (self.line, self.pos) == (other.line, other.pos)
def __ne__(self, other):
return (self.line, self.pos) != (other.line, other.pos)
class MissingOpeningCharError(LocatableDoubleCharError):
"""Exception that indicates that an opening equivalent of a certain character is missing"""
def __init__(self, trans: Translator, char: str, line: int, pos: int):
msg = f"{trans.translate(Translator.Text.MISSING_OPENING_CHARACTER)} '{char}'"
super(MissingOpeningCharError, self).__init__(trans=trans, msg=msg, line=line, pos=pos)
class MissingClosingCharError(LocatableDoubleCharError):
"""Exception that indicates that a closing equivalent of a certain character is missing"""
def __init__(self, trans: Translator, char: str, line: int, pos: int):
msg = f"{trans.translate(Translator.Text.MISSING_CLOSING_CHARACTER)} '{char}'"
super(MissingClosingCharError, self).__init__(trans=trans, msg=msg, line=line, pos=pos)
class MultipleMissingCharsError(DelayedExceptions):
def __init__(self, translator: Translator):
super().__init__()
self.translator = translator
self.exceptions: [LocatableDoubleCharError]
def __str__(self):
self.exceptions.sort()
return f"{self.translator.translate(Translator.Text.ERRORS)} ({len(self)}):\n{self._print_exceptions()}"