-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptions.py
More file actions
78 lines (57 loc) · 2.47 KB
/
Copy pathexceptions.py
File metadata and controls
78 lines (57 loc) · 2.47 KB
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
"""
Overview and Description
========================
This Python module describes exceptions in Ram.
Copyright and Usage Information
===============================
All forms of distribution of this code, whether as given or with any changes,
are expressly prohibited.
This file is Copyright (c) 2021 Will Assad, Zain Lakhani,
Ariel Chouminov, Ramya Chawla.
"""
from typing import Any
class RamException(Exception):
"""Abstract Ram exception."""
def __init__(self, line=None, line_number=None, error='') -> None:
if line is None or line_number is None:
super().__init__(error)
elif error is None:
super().__init__(f'Line {line_number}: \'{line}\'')
else:
super().__init__(f'Line {line_number}: \'{line}\' \n {error}')
class RamSyntaxException(RamException):
"""Syntax Exception."""
def __init__(self, message=None) -> None:
RamException.__init__(self, error=message)
class RamSyntaxKeywordException(RamSyntaxException):
"""Keyword Syntax Exception."""
def __init__(self, foreign: str) -> None:
RamSyntaxException.__init__(self, f'Keyword \'{foreign}\' invalid.')
class RamSyntaxOperatorException(RamSyntaxException):
"""Keyword Syntax Exception."""
def __init__(self, foreign: str) -> None:
RamSyntaxException.__init__(self, f'Operator \'{foreign}\' invalid.')
class RamNameException(RamException):
""" Undefined variable exception. """
def __init__(self, foreign: str) -> None:
RamException.__init__(self, error=f'Variable \'{foreign}\' not defined.')
class RamOperatorEvaluateException(RamException):
""" Equivalent to python TypeError. """
def __init__(self, one: Any, op: str, two: Any) -> None:
RamException.__init__(self, error=f'Cannot perform operation \'{one} {op} {two}\'')
class RamBlockException(Exception):
""" Undefined block creation. """
def __init__(self, message: str) -> None:
super().__init__(message)
class RamGeneralException(Exception):
""" General Ram Exception """
def __init__(self, message: str) -> None:
super().__init__(message)
class RamFileException(Exception):
"""Error reading a .ram file. """
def __init__(self, message: str) -> None:
super().__init__(message)
class RamFileNotFoundException(RamFileException):
""" .ram file path does not exist. """
def __init__(self, file_path: str) -> None:
super().__init__(f'File path \'{file_path}\' does not exist.')