functions basically work now, but they're extremely inneficient
This commit is contained in:
21
error.py
21
error.py
@@ -22,4 +22,23 @@ def traceback(code: str, error_type: str, error_message: str, line: Union[int, N
|
||||
console.print(f"[bold red]{error_type}: {error_message}")
|
||||
|
||||
exit(1)
|
||||
|
||||
|
||||
def warning(code: str, warning_msg: str, note: str = None, line: Union[int, None] = None, start_column: Union[int, None] = None, end_column: Union[int, None] = None):
|
||||
if line != None:
|
||||
console.print(f"[bold cyan]warning:[/] {warning_msg}\n")
|
||||
lines = code.split("\n")[line-1:line+2]
|
||||
|
||||
console.print(f"{line } > " + lines[0], highlight=False)
|
||||
if start_column != None and end_column != None:
|
||||
console.print(" " + (" " * start_column) + "[bold red]" + ("^" * (end_column-start_column+1)))
|
||||
|
||||
try:
|
||||
console.print(f"{line+1} " + lines[1], highlight=False)
|
||||
console.print(f"{line+2} " + lines[2], highlight=False)
|
||||
console.print(" ...", highlight=False)
|
||||
except IndexError: # the file is less than 3 lines i guess
|
||||
pass
|
||||
else:
|
||||
console.print(f"[bold cyan]warning:[/] {warning_msg}")
|
||||
if note != None:
|
||||
console.print(f"[bold]note:[/] {note}")
|
Reference in New Issue
Block a user