-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherror.py
110 lines (80 loc) · 2.3 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from enum import Enum
class VerboseLevel(Enum):
NONE = 0
CURR_ONLY = 1
FULL = 2
# flag for displaying uniquified names
unique_names = False
def set_unique_names(b):
global unique_names
unique_names = b
def get_unique_names():
global unique_names
return unique_names
# flag for verbose trace
verbose = False
def set_verbose(b):
global verbose
verbose = b
def get_verbose():
global verbose
if verbose == VerboseLevel.NONE:
return False
return verbose
# flag for expect fail
expect_fail_flag = False
def expect_fail():
return expect_fail_flag
def set_expect_fail(b):
global expect_fail_flag
expect_fail_flag = b
# flag for expect static_fail
expect_static_fail_flag = False
def expect_static_fail():
return expect_static_fail_flag
def set_expect_static_fail(b):
global expect_static_fail_flag
expect_static_fail_flag = b
def error_header(location):
# seeing a strange error where some Meta objects don't have a line member.
if hasattr(location, 'line'):
return '{file}:{line1}.{column1}-{line2}.{column2}: ' \
.format(file=location.filename,
line1=location.line, column1=location.column,
line2=location.end_line, column2=location.end_column)
def error(location, msg):
exc = Exception(error_header(location) + msg)
exc.depth = 0
raise exc
class IncompleteProof(Exception):
pass
def incomplete_error(location, msg):
exc = IncompleteProof(error_header(location) + msg)
exc.depth = 0
raise exc
def warning(location, msg):
print(error_header(location) + msg)
class StaticError(Exception):
pass
def static_error(location, msg):
raise StaticError(error_header(location) + msg)
MAX_ERR_DEPTH = 2
# Parse Errors need to carry around some extra data
class ParseError(Exception):
def __init__(self, loc, msg, depth=0, missing=False, last=False):
super().__init__(msg)
self.loc = loc
self.depth = depth
self.missing = missing
self.last = last
self.trace = []
def extend(self, loc, msg):
self.trace += [ParseError(loc, msg)]
return self
def base_message(self):
return super().__str__()
def __str__(self):
base = error_header(self.loc) + super().__str__()
if self.trace:
base += "\n"
return base+"\n".join([str(x) for x in self.trace[:MAX_ERR_DEPTH]])