From 1fa9a09bfe641381113586edde20a6833354ce88 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Tue, 19 May 2026 13:57:00 +0200 Subject: [PATCH] feat(parser): use custom syntax error class --- lexer/base.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lexer/base.py b/lexer/base.py index 1104e7a..f6f357d 100644 --- a/lexer/base.py +++ b/lexer/base.py @@ -5,6 +5,13 @@ from lexer.position import Position from lexer.token import Token, TokenType +class MidasSyntaxError(Exception): + def __init__(self, pos: Position, message: str): + super().__init__(f"[ERROR] Error at {pos}: {message}") + self.pos: Position = pos + self.message: str = message + + class Lexer(ABC): """An abstract lexer which provides methods to easily extend it into a concrete one @@ -38,9 +45,9 @@ class Lexer(ABC): msg (str): the error message Raises: - SyntaxError + MidasSyntaxError """ - raise SyntaxError(f"[ERROR] Error at {self.start_pos}: {msg}") + raise MidasSyntaxError(self.start_pos, msg) def process(self) -> list[Token]: """Scan tokens out of the source text @@ -49,7 +56,7 @@ class Lexer(ABC): list[Token]: all the tokens that could be scanned Raises: - SyntaxError: if a syntax error is found + MidasSyntaxError: if a syntax error is found """ self.scan_tokens() self.tokens.append(Token(TokenType.EOF, "", None, self.get_position()))