Skip to content

Commit

Permalink
Try to add syntax highlighting to vm langauge
Browse files Browse the repository at this point in the history
  • Loading branch information
netalondon committed Mar 5, 2024
1 parent fa1a422 commit 8ce3453
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions web/src/languages/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
53 changes: 53 additions & 0 deletions web/src/languages/vm.ts
Original file line number Diff line number Diff line change
@@ -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,
},
};
4 changes: 2 additions & 2 deletions web/src/pages/vm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ const VM = () => {
>
<Editor
value={state.files.vm}
onChange={function (source: string): void {
onChange={(source: string) => {
actions.setVm(source);
}}
language={""}
language={"vm"}
highlight={state.controls.valid ? state.vm.highlight : undefined}
/>
</Panel>
Expand Down

0 comments on commit 8ce3453

Please sign in to comment.