25 lines
746 B
Python
25 lines
746 B
Python
from src.interpreter.error import PebbleRuntimeError
|
|
from src.position import Position
|
|
from src.token import Token, TokenType
|
|
|
|
|
|
class Pebble:
|
|
@staticmethod
|
|
def report(position: Position, where: str, msg: str):
|
|
print(f"({position}) Error{where}: {msg}")
|
|
|
|
@classmethod
|
|
def error(cls, position: Position, msg: str):
|
|
cls.report(position, "", msg)
|
|
|
|
@classmethod
|
|
def token_error(cls, token: Token, msg: str):
|
|
if token.type == TokenType.EOF:
|
|
cls.report(token.position, " at end", msg)
|
|
else:
|
|
cls.report(token.position, f" at '{token.lexeme}'", msg)
|
|
|
|
@classmethod
|
|
def runtime_error(cls, error: PebbleRuntimeError):
|
|
print(f"{error}\n({error.token.position})")
|