From 81f4013dcf6ef5345a7d51c12a4e824d5ad822cd Mon Sep 17 00:00:00 2001 From: Sam Pagenkopf Date: Sun, 4 Feb 2024 18:18:07 -0600 Subject: [PATCH] add lexer error --- structedit/liveparse.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/structedit/liveparse.js b/structedit/liveparse.js index 929cf09..c1ab337 100644 --- a/structedit/liveparse.js +++ b/structedit/liveparse.js @@ -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)); @@ -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 = {