-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblems.py
82 lines (60 loc) · 2.21 KB
/
problems.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import abc
class Problem(abc.ABC):
def __init__(self, cat, msg, position, name=None, extra=None):
self.cat = cat
self.msg = msg
self.position = position
self.name = name
if isinstance(extra, list):
self.extra = extra
elif extra is None:
self.extra = []
else:
self.extra = [extra]
@abc.abstractmethod
def set_interactive(self, tooltip):
pass
def show(self, codelines):
out = """{}
{}: {}""".format(self.position.get_descriptive_line(codelines), self.name, self.msg)
for msg, tok in self.extra:
out += "\n\n" + tok.position.get_descriptive_line(codelines, msg + " on line {}:")
return out
class Error(Problem):
def __init__(self, *args, **kwargs):
super().__init__("error", *args, **kwargs)
def set_interactive(self, tooltip):
tooltip.error_header("Error" if self.name is None else self.name)
tooltip.newline()
tooltip.text(self.msg)
tooltip.newline()
tooltip.newline()
for msg, token in self.extra:
tooltip.text(msg + ":")
tooltip.goto_token(token)
tooltip.newline()
class Warning(Problem):
def __init__(self, *args, **kwargs):
super().__init__("warning", *args, **kwargs)
def set_interactive(self, tooltip):
tooltip.warning_header("Warning" if self.name is None else self.name)
tooltip.newline()
tooltip.text(self.msg)
tooltip.newline()
tooltip.newline()
for msg, token in self.extra:
tooltip.text(msg + ":")
tooltip.goto_token(token)
tooltip.newline()
class SyntaxError(Error):
def __init__(self, *args, **kwargs):
super().__init__(*args, name="Syntax Error", **kwargs)
class SemanticError(Error):
def __init__(self, *args, **kwargs):
super().__init__(*args, name="Semantic Error", **kwargs)
class RuntimeWarning(Warning):
def __init__(self, *args, **kwargs):
super().__init__(*args, name="Runtime Warning", **kwargs)
class StyleWarning(Warning):
def __init__(self, *args, **kwargs):
super().__init__(*args, name="Style Warning", **kwargs)