-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.py
77 lines (62 loc) · 2.19 KB
/
error.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
from enum import Enum, auto
from util import LogColor
class InterpreterError(Exception):
def __init__(self, m, node=None, ty=None, message=None, cont=False, name=None, classnames=None, object=None):
super().__init__(m)
self.node = node
self.type = ty
self.message = message
self.cont = cont
self.name = name
self.classnames = classnames
self.object = object
class ErrorType(Enum):
Exception = auto()
Syntax = auto()
DoesNotExist = auto()
TypeError = auto()
MultipleDefinition = auto()
ArgumentError = auto()
MacroExpansionError = auto()
InterruptedError = auto()
class Error():
def __init__(self, ty, location, message, filename, name="Exception"):
self.type = ty
self.filename = filename
self.message = message
self.location = location
self.name = name
@property
def location_filename(self):
if self.filename is None:
return '<none>'
return self.filename
@property
def location_row(self):
if self.location is None:
return 0
return self.location[1]
@property
def location_col(self):
if self.location is None:
return 0
return self.location[0]
def __repr__(self):
nstr = f"{self.location_filename}:{self.location_row}:{self.location_col}: {LogColor.Error}{self.name}:{LogColor.Default}"
# nstr = f"{self.location_filename}:{self.location_row}:{self.location_col}: {LogColor.Error}{self.type.name} error:{LogColor.Default}"
# if self.type == ErrorType.Exception:
# nstr = f"{self.location_filename}:{self.location_row}:{self.location_col}: {LogColor.Error}{self.name}:{LogColor.Default}"
return f"{LogColor.Bold}{nstr}{LogColor.Default} {self.message}"
__str__ = __repr__
class ErrorList():
def __init__(self):
self.errors = []
def clear_errors(self):
self.errors = []
def push_error(self, error):
self.errors.append(error)
def print_errors(self):
for error in self.errors:
print(error)
def get_errors(self):
return self.errors