From 980b92f6318c3e34fe4ffc9008e3870f738d64ec Mon Sep 17 00:00:00 2001 From: Araozu Date: Mon, 26 Aug 2024 08:43:36 -0500 Subject: [PATCH] refactor: use a highlight level to emit errors --- src/components/Code.astro | 5 +- src/components/InteractiveCode.astro | 164 +------------------- src/components/Navbar.astro | 6 - src/lexer/highlighter.ts | 123 +++++---------- src/lexer/identifier_lexer.test.ts | 55 ------- src/lexer/identifier_lexer.ts | 44 ------ src/lexer/lexer.test.ts | 45 ------ src/lexer/lexer.ts | 166 -------------------- src/lexer/number_lexer.test.ts | 19 --- src/lexer/number_lexer.ts | 47 ------ src/lexer/string_lexer.test.ts | 32 ---- src/lexer/string_lexer.ts | 49 ------ src/lexer/types.ts | 75 +++++++++ src/pages/learn/basics/variables.mdx | 14 +- src/thp_machine/machine_parser.ts | 218 --------------------------- 15 files changed, 125 insertions(+), 937 deletions(-) delete mode 100644 src/lexer/identifier_lexer.test.ts delete mode 100644 src/lexer/identifier_lexer.ts delete mode 100644 src/lexer/lexer.test.ts delete mode 100644 src/lexer/lexer.ts delete mode 100644 src/lexer/number_lexer.test.ts delete mode 100644 src/lexer/number_lexer.ts delete mode 100644 src/lexer/string_lexer.test.ts delete mode 100644 src/lexer/string_lexer.ts create mode 100644 src/lexer/types.ts delete mode 100644 src/thp_machine/machine_parser.ts diff --git a/src/components/Code.astro b/src/components/Code.astro index 4e7ed07..709f5e9 100644 --- a/src/components/Code.astro +++ b/src/components/Code.astro @@ -1,10 +1,11 @@ --- import { native_highlighter } from "../lexer/highlighter"; +import type { HighlightLevel } from "../lexer/types"; import CodeError from "./docs/CodeError.astro"; -const { thpcode, no_warnings } = Astro.props; +const { thpcode, no_warnings, level } = Astro.props; -const [native_html, error_type, error_message] = await native_highlighter(thpcode); +const [native_html, error_type, error_message] = await native_highlighter(thpcode, level as HighlightLevel); ---
): string {
-    let outLines: Array = [];
-
-    for (const [idx, line] of lines.entries()) {
-        const tokens = lex(line);
-        const lineArray = [
-            `
`, - ]; - - for (const token of tokens) { - if (token.token_type !== "") { - lineArray.push( - `${token.v}`, - ); - } else { - lineArray.push(token.v); - } - } - lineArray.push("
"); - - outLines.push(lineArray.join("")); - } - - return outLines.join("\n"); -} - -const codeHtml = highlightCode(leftTrimDedent(code)); -let instructionSet: Array>; -try { - instructionSet = parse_str(steps); -} catch (e) { - console.error(Astro.url); - throw e; -} - -const serialized_inst = JSON.stringify(instructionSet); +import Code from "./Code.astro"; +const { code } = Astro.props; +// TODO: Delete this component, replace with Code --- -
- thp code -
-
-
-
stdout
-
-
-
-
-
-
state
-
- -
-
-
-
- - -
-
- - + diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index 9e51092..8b9c34a 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -30,12 +30,6 @@ const { showSidebarButton = true } = Astro.props; > Learn -