refactor: move lexer try-catch to runner
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
return self.tokens
|
||||
|
||||
def is_at_end(self) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user