From 957921b793d34f3d6b1ee511bbc01223f6e395d0 Mon Sep 17 00:00:00 2001 From: Araozu Date: Mon, 20 May 2024 10:02:08 -0500 Subject: [PATCH] Finish thp code DSL basic implementation --- src/components/InteractiveCode.astro | 41 +++++--- src/pages/learn/error-handling/try.mdx | 125 ++++++------------------- src/pages/learn/index.mdx | 38 ++++---- src/thp_machine/machine_parser.ts | 46 +++++++-- 4 files changed, 115 insertions(+), 135 deletions(-) diff --git a/src/components/InteractiveCode.astro b/src/components/InteractiveCode.astro index 4838f51..014faba 100644 --- a/src/components/InteractiveCode.astro +++ b/src/components/InteractiveCode.astro @@ -1,5 +1,7 @@ --- import { lex } from "../lexer/lexer"; +import type { Instruction } from "../thp_machine/machine_parser"; +import { parse_str } from "../thp_machine/machine_parser"; const {code, steps} = Astro.props; /** @@ -97,6 +99,15 @@ function highlightCode(lines: Array): string { } const codeHtml = highlightCode(trimAndDedent(code)); +let instructionSet: Array>; +try { + instructionSet = parse_str(steps); +} catch (e) { + console.error(Astro.url); + throw e; +} + +const serialized_inst = JSON.stringify(instructionSet); ---