-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
218 lines (155 loc) · 5.36 KB
/
errors.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
class SyntaxException(Exception):
"""
Parent Exception for Syntax Errors
"""
def __init__(self, error):
self.message = "\033[31m" + "Syntax Error: " + "\033[0m"
super().__init__(self.message + error)
class RuntimeException(Exception):
"""
Parent Exception for Runtime Errors
"""
def __init__(self, error):
self.message = "\033[31m" + "Runtime Error: " + "\033[0m"
super().__init__(self.message + error)
class ForeignCharacter(SyntaxException):
"""
Raised when a foreign character is passed to the lexer
parameter:
index: index at which invalid character was found
character: the invalid character that was found
"""
def __init__(self, index, character):
self.message = (
"Foreign Character \033[33m %c \033[0m found at index \033[33m %d \033[0m"
% (character, index)
)
super().__init__(self.message)
class WrongCharacter(SyntaxException):
"""
Raised when a , or ? character is passed to the lexer in a wrong place
parameter:
index: index at which invalid character was found
character: the invalid character that was found
"""
def __init__(self, character, index):
self.message = (
"\033[33m %c \033[0m wrongly referenced at index \033[33m %d \033[0m"
% (character, index)
)
super().__init__(self.message)
class FullStopNotFound(SyntaxException):
"""
Raised when a full stop is not present.
parameter:
"""
def __init__(self):
self.message = "All commands must terminate with full stops '.'"
super().__init__(self.message)
class FalseTermination(SyntaxException):
"""
Raised when a full stop is present in between
parameter:
"""
def __init__(self, index):
self.message = (
"Non terminating Full Stop present at index \033[33m %d \033[0m" % index
)
super().__init__(self.message)
class ReservedIdentifier(SyntaxException):
"""
Raised when an reserved identifier is passed to the lexer
parameter:
index: index at which reserved character was found
identifier: the reserved identifier that was found
"""
def __init__(self, identifier):
self.message = (
"\033[33m %s \033[0m cannot be used for naming, it is a reserved keyword"
% identifier
)
super().__init__(self.message)
class IdentifierExists(RuntimeException):
"""
Raised when assigning a name which already exists
varName: name of the variable
"""
def __init__(self, varName):
self.message = (
"A variable with name \033[33m %s \033[0m already exists" % varName
)
super().__init__(self.message)
class InvalidAsssign(SyntaxException):
"""
Raised when a Invalid assignment value is passed to the parser
parameter:
index: index at which Invalid value was found
value: the Invalid value that was found
"""
def __init__(self, value):
self.message = (
"Invalid value \033[33m %d \033[0m negative values cannot be assigned"
% value
)
super().__init__(self.message)
class WrongIndex(RuntimeException):
"""
Raised when an out of bound index is passed on runtime
parameter:
index: index at which wrong index was found
value: the Invalid index that was found
range: permissible range
"""
def __init__(self, index, lindex, uindex):
self.message = (
"Wrong index \033[33m %s \033[0m found, index can vary from \033[33m %s \033[0m to \033[33m %s \033[0m"
% (str(index), str(lindex), str(uindex),)
)
super().__init__(self.message)
class ParserException(SyntaxException):
"""
Raised when an error is raised during parsing:
token: token at which the parser found the error
"""
def __init__(self, token):
self.message = "Invalid token \033[33m %s \033[0m found" % token.type
super().__init__(self.message)
class EmptyTileNamingException(RuntimeException):
"""
Raised when assigning a name to an empty tile
"""
def __init__(self, index):
self.message = (
"Empty Tile at \033[33m %d \033[0m,\033[33m %d \033[0m cannot be named"
% index
)
super().__init__(self.message)
class EmptyTileQueryException(RuntimeException):
"""
Raised when assigning a name to an empty tile
"""
def __init__(self, index):
self.message = (
"Empty Tile at \033[33m %d \033[0m,\033[33m %d \033[0m cannot be queried"
% index
)
super().__init__(self.message)
class NamedParserException(SyntaxException):
"""
Raised when an error is raised during parsing:
token: token at which the parser found the error
"""
def __init__(self, pre, post, correct):
self.message = (
"\033[33m %s \033[0m cannot be followed by \033[33m %s \033[0m, try \033[33m %s \033[0m"
% (pre, post, correct)
)
super().__init__(self.message)
class ParserEOFException(SyntaxException):
"""
Raised when an error is raised during parsing:
token: token at which the parser found the error
"""
def __init__(self):
self.message = "Parse error in Command. Reached EOL"
super().__init__(self.message)