Skip to content

Commit

Permalink
refactor: Improve error handling in lexer.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
cvs0 committed May 25, 2024
1 parent a22498d commit 4356e62
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions frontend/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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");
}
}

Expand All @@ -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");
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 4356e62

Please sign in to comment.