Skip to content

Commit

Permalink
wasm: add highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
koka831 committed Feb 16, 2024
1 parent f82dd23 commit 08822e0
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,56 @@
<script>
const editor = ace.edit("editor");
editor.setTheme("ace/theme/gruvbox");
editor.session.setMode("ace/mode/text", () => {
editor.session.getMode().$highlightRules.$rules = {
start: [
{
token: "keyword.control",
regex: "\\b(if|else|while|for|return|and|or)\\b"
},
{
token: "support.class",
regex: "class\s*",
next: "variable"
},
{
token: "support.function",
regex: "fun\s*",
next: "variable"
},
{
token: "keyword",
regex: "\\b(var|print)\\b"
},
{
token: "string.single",
regex: "\'.*\'"
},
{
token: "string.double",
regex: "\".*\""
},

{
token: "constant",
regex: "\\b(nil|true|false|this|super)\\b"
},
{
token: "constant.numeric",
regex: "\\b[0-9]+(?:.[0-9]+)?\\b",
},
{
token: "comment",
regex: "\\/\\/.*"
},
{ defaultToken: 'text' }
]
};

editor.session.$mode.$tokenizer = null;
editor.session.bgTokenizer.setTokenizer(editor.session.$mode.getTokenizer());
editor.session.bgTokenizer.start(0);
});

function interpret() {
import("./loxr.js").then(async (loxr) => {
Expand Down

0 comments on commit 08822e0

Please sign in to comment.