diff --git a/src/arx/lexer.py b/src/arx/lexer.py index 4c0f8d2..6ad9a46 100644 --- a/src/arx/lexer.py +++ b/src/arx/lexer.py @@ -204,6 +204,16 @@ def get_next_token(self) -> Token: return self.cur_tok +class LexerError(Exception): + """Custom exception for lexer errors.""" + + def __init__(self, message: str, location: SourceLocation): + super().__init__( + f"{message} at line {location.line}, col {location.col}" + ) + self.location = location + + class Lexer: """ Lexer class for tokenizing known variables. @@ -311,7 +321,16 @@ def get_token(self) -> Token: # Number: [0-9.]+ if self.last_char.isdigit() or self.last_char == ".": num_str = "" + dot_count = 0 + while self.last_char.isdigit() or self.last_char == ".": + if self.last_char == ".": + dot_count += 1 + if dot_count > 1: + raise LexerError( + "Invalid number format: multiple decimal points", + self.lex_loc, + ) num_str += self.last_char self.last_char = self.advance()