Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/arx/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down
Loading