-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
30 lines (21 loc) · 737 Bytes
/
errors.py
File metadata and controls
30 lines (21 loc) · 737 Bytes
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
from typing import Optional
from parse_token import Token
from expression_tree_node import Node
class ValidateError(Exception):
def __init__(self, message: str, token: Optional[Token] = None):
self._message = message
self._token = token
self.__repr__()
def __repr__(self):
msg = ""
if isinstance(self._token, Token):
msg = " " * self._token.position + "^ "
print(msg + self._message)
class ExpressionTreeError(Exception):
def __init__(self, message: str, node: Node):
self._message = message
self._node = node
self.__repr__()
def __repr__(self):
msg = " " * self._node.position + "^ "
print(msg + self._message)