-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
33 lines (22 loc) · 799 Bytes
/
errors.py
File metadata and controls
33 lines (22 loc) · 799 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
31
32
33
from typing import Optional, List
from args import Args
from patterns.singleton import Singleton
from position import Position
class Error:
def __init__(self, message: str, position: Optional[Position] = None):
self.message = message + '.'
self.position = position
def __str__(self) -> str:
pos = '' if self.position is None else f':{self.position.line}'
return f'{Args().source}{pos}: {self.message}'
class Errors(metaclass=Singleton):
list: List[Error] = []
def is_ok(self):
return len(self.list) == 0
class CompilationException(Exception):
def __init__(self, error: Error):
self.error = error
def handle(self):
Errors().list.append(self.error)
def __str__(self) -> str:
return str(self.error)