|
@@ -0,0 +1,40 @@
|
|
|
+from output import *
|
|
|
+import sys
|
|
|
+
|
|
|
+error_list: dict = {}
|
|
|
+
|
|
|
+
|
|
|
+class Error(object):
|
|
|
+ line: int = -1
|
|
|
+ column: int = -1
|
|
|
+ error_id: int = 1
|
|
|
+ curr_token_list: list = []
|
|
|
+ has_occur: bool = False
|
|
|
+
|
|
|
+ def __init__(self, text: str, is_code_error: bool):
|
|
|
+ self.text = text
|
|
|
+ self.is_code_error = is_code_error
|
|
|
+ self.id = Error.error_id
|
|
|
+ Error.error_id += 1
|
|
|
+
|
|
|
+ def call(self):
|
|
|
+ Error.has_occur = True
|
|
|
+ color_println('red', self.text)
|
|
|
+ if self.is_code_error:
|
|
|
+ color_println('red', f'line = {self.line}')
|
|
|
+ for i in range(len(Error.curr_token_list)):
|
|
|
+ if i == self.column:
|
|
|
+ color_print('red', Error.curr_token_list[i], True)
|
|
|
+ else:
|
|
|
+ color_print('red', Error.curr_token_list[i])
|
|
|
+ print(' ', end='')
|
|
|
+ print()
|
|
|
+ exit(self.id)
|
|
|
+
|
|
|
+
|
|
|
+def add_error(name: str, text: str, is_code_error: bool = False):
|
|
|
+ error_list.update({name: Error(text, is_code_error)})
|
|
|
+
|
|
|
+
|
|
|
+def call_error(name: str):
|
|
|
+ error_list[name].call()
|