From 58cd1a56b24f94aa95bd36e1cd670d1498040fe7 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Fri, 4 Aug 2023 00:26:15 -0400 Subject: [PATCH] Output fancier error message on parse error --- 3x5.js | 6 +++++- notcl.js | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/3x5.js b/3x5.js index 940da9a..0b1c382 100644 --- a/3x5.js +++ b/3x5.js @@ -25,7 +25,11 @@ */ function renderCard(state, code) { const script = Notcl.parse(code); - state.output = JSON.stringify(script, null, 2); + if (script[0]) { + state.output = JSON.stringify(script[1], null, 2); + } else { + state.output = script[1]; + } return state.output; } diff --git a/notcl.js b/notcl.js index fc43a8f..7c1b17a 100644 --- a/notcl.js +++ b/notcl.js @@ -64,8 +64,8 @@ var Notcl = (() => { * Parse out a Notcl script into an easier-to-interpret representation. * No script is actually executed yet. * - * @param {string} code - * @returns Script + * @param {string} code to parse + * @returns {[true, Notcl.Script] | [false, string]} parsed list of commands, or error message on failure */ parse(code) { /* Preprocess */ @@ -85,9 +85,9 @@ var Notcl = (() => { ); return [ false, - `Error at position ${commands[1]} -${before}${after} -${"-".repeat(before.length)}^`, + `
Error at position ${commands[1]}
+${escapeHtml(before + "" + after)}
+${"-".repeat(before.length)}^
`, ]; } },