-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
37 lines (27 loc) · 1.21 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
from lexer import LocationInformation
from typing import Optional
class Error(Exception):
"""Base class for errors"""
def __init__(self, message):
self.message = message
super().__init__(self.message)
class ParserError(Error):
def __init__(self, message: str, position: Optional[LocationInformation] = None):
if position is None:
self.location_str = "Following error occurred: "
else:
self.location_str = f"Following error occurred at line: {position.start_line}, col: {position.start_col - position.end_col}."
super(ParserError, self).__init__(self.location_str + message)
class LexerError(Error):
def __init__(self, message: str, position: Optional[LocationInformation] = None):
if position is None:
self.location_str = "Following error occurred: "
else:
self.location_str = f"Following error occurred at line: {position.start_line}, col: {position.start_col - position.end_col}."
super(LexerError, self).__init__(self.location_str + message)
class ReturnError(Error):
def __init__(self, value):
self.value = value
@property
def return_value(self):
return self.value