diff --git a/web/src/languages/loader.js b/web/src/languages/loader.js index fdc161358..7f28c935a 100644 --- a/web/src/languages/loader.js +++ b/web/src/languages/loader.js @@ -2,11 +2,13 @@ import { loader } from "@monaco-editor/react"; import { CmpLanguage } from "./cmp"; import { HdlLanguage } from "./hdl"; import { TstLanguage } from "./tst"; +import { VmLanguage } from "./vm"; const LANGUAGES = { hdl: HdlLanguage, cmp: CmpLanguage, tst: TstLanguage, + vm: VmLanguage }; export async function registerLanguages() { diff --git a/web/src/languages/vm.ts b/web/src/languages/vm.ts new file mode 100644 index 000000000..efab6661f --- /dev/null +++ b/web/src/languages/vm.ts @@ -0,0 +1,53 @@ +import * as monaco from "monaco-editor/esm/vs/editor/editor.api"; +import { base } from "./base"; + +export const VmLanguage: monaco.languages.IMonarchLanguage = { + keywords: [ + "push", + "pop", + "add", + "sub", + "neg", + "lt", + "gt", + "eq", + "and", + "or", + "not", + "function", + "call", + "return", + "label", + "goto", + "if-goto", + "argument", + "local", + "static", + "constant", + "this", + "that", + "pointer", + "temp", + ], + + tokenizer: { + root: [ + [ + /[_a-zA-Z][_a-zA-Z0-9.$]*/, + { + cases: { + "@keywords": "keyword", + "@default": "identifier", + }, + }, + ], + + [/\d+/, "number"], + + // whitespace + { include: "@whitespace" }, + ], + + ...base.tokenizer, + }, +}; diff --git a/web/src/pages/vm.tsx b/web/src/pages/vm.tsx index 4fb778f29..6e74d5185 100644 --- a/web/src/pages/vm.tsx +++ b/web/src/pages/vm.tsx @@ -196,10 +196,10 @@ const VM = () => { > { actions.setVm(source); }} - language={""} + language={"vm"} highlight={state.controls.valid ? state.vm.highlight : undefined} />