refactor: move lexer try-catch to runner

This commit is contained in:
2026-02-07 16:36:07 +01:00
parent cc3aa56614
commit 1e789726b0
2 changed files with 9 additions and 8 deletions

View File

@@ -22,7 +22,13 @@ class Runner:
@staticmethod
def run(source: str, path: Optional[Path] = None):
lexer: Lexer = Lexer(source, path)
tokens: list[Token] = lexer.process()
tokens: list[Token]
try:
tokens = lexer.process()
except:
print("Partially parsed tokens:")
print(lexer.tokens)
return
print(list(filter(lambda t: t.type not in Parser.IGNORE, tokens)))
if Pebble.had_error:

View File

@@ -21,13 +21,8 @@ class Lexer:
raise SyntaxError(f"[ERROR] Error at {self.start_pos}: {msg}")
def process(self) -> list[Token]:
try:
self.scan_tokens()
self.tokens.append(Token(TokenType.EOF, "", None, self.get_position()))
except Exception as e:
print("Partially parsed tokens:")
print(self.tokens)
raise e
self.scan_tokens()
self.tokens.append(Token(TokenType.EOF, "", None, self.get_position()))
return self.tokens
def is_at_end(self) -> bool: