// https://microsoft.github.io/monaco-editor/monarch.html import { languages } from "monaco-editor/esm/vs/editor/editor.api.js"; export const conf: languages.LanguageConfiguration = { brackets: [ ["{", "}"], ["(", ")"], ], autoClosingPairs: [ { open: "{", close: "}" }, { open: "(", close: ")" }, { open: "[", close: "]" }, { open: '"', close: '"' }, ], surroundingPairs: [ { open: "(", close: ")" }, { open: "{", close: "}" }, { open: "[", close: "]" }, { open: '"', close: '"' }, ], }; export const language = { // Set defaultToken to invalid to see what you do not tokenize yet // defaultToken: 'invalid', keywords: ["return", "else", "if", "let", "true", "false", "fn"], operators: ["=", ">", "<", "!", "==", "!=", "+", "-", "*", "/"], // we include these common regular expressions symbols: /[=>](?!@symbols)/, "@brackets"], [/@symbols/, { cases: { "@operators": "operator", "@default": "" } }], // @ annotations. // As an example, we emit a debugging log message on these tokens. // Note: message are supressed during the first load -- change some lines to see them. [ /@\s*[a-zA-Z_\$][\w\$]*/, { token: "annotation", log: "annotation token: $0" }, ], // numbers // [/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"], // [/0[xX][0-9a-fA-F]+/, "number.hex"], [/\d+/, "number"], // delimiter: after number because of .\d floats [/[;,.]/, "delimiter"], // strings [/"([^"\\]|\\.)*$/, "string.invalid"], // non-teminated string [/"/, { token: "string.quote", bracket: "@open", next: "@string" }], // characters [/'[^\\']'/, "string"], [/(')(@escapes)(')/, ["string", "string.escape", "string"]], [/'/, "string.invalid"], ], string: [ [/[^\\"]+/, "string"], [/@escapes/, "string.escape"], [/\\./, "string.escape.invalid"], [/"/, { token: "string.quote", bracket: "@close", next: "@pop" }], ], whitespace: [[/[ \t\r\n]+/, "white"]], }, };