-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase.py
40 lines (28 loc) · 1.32 KB
/
base.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
###############################################################################
# #
# #
# BASE MODULE #
# #
# #
###############################################################################
from enum import Enum
_SHOULD_LOG_SCOPE = False # see '--scope' command line option
_SHOULD_LOG_STACK = False # see '--stack' command line option
class ErrorCode(Enum):
UNEXPECTED_TOKEN = "Unexpected token"
ID_NOT_FOUND = "Identifier not found"
DUPLICATE_ID = "Duplicate id found"
VARIABLE_NOT_INITIALISER = "Variable not initialised"
MISSING_RETURN = "Missing return statement"
class Error(Exception):
def __init__(self, error_code=None, token=None, message=None):
self.error_code = error_code
self.token = token
# add exception class name before the message
self.message = f"{self.__class__.__name__}: {message}"
class LexerError(Error):
pass
class ParserError(Error):
pass
class SemanticError(Error):
pass