functions basically work now, but they're extremely inneficient

This commit is contained in:
SpookyDervish
2025-09-13 06:26:15 +10:00
parent 865a31827a
commit 170272353c
6 changed files with 74 additions and 66 deletions

View File

@@ -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}")