From 4356e62d387549c4760caae6ac97e70f89705246 Mon Sep 17 00:00:00 2001 From: cvs0 <143862758+cvs0@users.noreply.github.com> Date: Fri, 24 May 2024 22:34:29 -0600 Subject: [PATCH] refactor: Improve error handling in lexer.ts --- frontend/lexer.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/frontend/lexer.ts b/frontend/lexer.ts index 80295ea..622ca41 100644 --- a/frontend/lexer.ts +++ b/frontend/lexer.ts @@ -46,8 +46,7 @@ export function tokenize(sourceCode: string): Token[] { src.shift(); src.shift(); } else { - console.error("Unterminated multi-line comment"); - Deno.exit(1); + throw new Error("Unterminated multi-line comment"); } } @@ -207,8 +206,7 @@ export function tokenize(sourceCode: string): Token[] { src.shift(); pushToken(src, TokenType.String, tokens) } else { - console.error("Unterminated string literal"); - Deno.exit(1); + throw new Error("Unterminated string literal"); } } @@ -224,8 +222,7 @@ export function tokenize(sourceCode: string): Token[] { src.shift(); pushToken(src, TokenType.String, tokens) } else { - console.error("Unterminated string literal"); - Deno.exit(1); + throw new Error("Unterminated string literal"); } } @@ -274,13 +271,11 @@ export function tokenize(sourceCode: string): Token[] { src.shift(); // Skip current char } else { // Unrecognized character - console.error( - "Unrecognized character found in source: ", - src[0].charCodeAt(0), + throw new Error( + "Unrecognized character found in source: " + + src[0].charCodeAt(0) + src[0] ); - - Deno.exit(1); } } }