Skip to content

Commit

Permalink
add lexer error
Browse files Browse the repository at this point in the history
  • Loading branch information
44100hertz committed Feb 5, 2024
1 parent 6b88813 commit 81f4013
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion structedit/liveparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function load() {
}

function generateTree(text) {
const lexed = lexString(text);
try {
const lexed = lexString(text);
const parsed = parseTokens(lexed);
const tree = trimTree(parsed);
console.log(JSON.stringify(tree));
Expand Down Expand Up @@ -63,6 +63,9 @@ function lexString(text, position = 0) {
matchKind = candidate[0];
}
if (!candidate || end > text.length) {
if (matchKind === "UNKNOWN") {
throw new Error(`Unknown Token: ${token}`);
}
if (end <= text.length) token = token.slice(0, -1);
if (matchKind !== 'white') {
const parsedToken = {
Expand Down

0 comments on commit 81f4013

Please sign in to comment.