Crude first pass at playground page

This commit is contained in:
2024-11-04 22:30:40 -08:00
parent f225d0ecbd
commit f92d287909
9 changed files with 1209 additions and 0 deletions

67
playground/src/monarch.ts Normal file
View File

@@ -0,0 +1,67 @@
import * as monaco from 'monaco-editor'
export let newtLanguage: monaco.languages.IMonarchLanguage = {
// Set defaultToken to invalid to see what you do not tokenize yet
// defaultToken: 'invalid',
keywords: [
"let",
"in",
"where",
"case",
"of",
"data",
"U",
"module",
"ptype",
"pfunc",
"module",
"infixl",
"infixr",
"infix",
],
specialOps: ["=>", "->", ":", "=", ":="],
tokenizer: {
root: [
[
/[a-z_$][\w$]*/,
{ cases: { "@keywords": "keyword", "@default": "identifier" } },
],
[/[A-Z][\w\$]*/, "type.identifier"],
[/\\|λ/, "keyword"],
{ include: "@whitespace" },
[/[{}()\[\]]/, "@brackets"],
[
/[:!#$%&*+.<=>?@\\^|~\/-]+/,
{
cases: {
"@specialOps": "keyword",
"@default": "operator",
},
},
],
[/\d+/, "number"],
// strings
[/"([^"\\]|\\.)*$/, "string.invalid"], // non-teminated string
[/"/, { token: "string.quote", bracket: "@open", next: "@string" }],
],
comment: [
[/[^-]+/, "comment"],
["-/", "comment", "@pop"],
["-", "comment"],
],
string: [
[/[^\\"]+/, "string"],
// [/@escapes/, "string.escape"],
[/\\./, "string.escape.invalid"],
[/"/, { token: "string.quote", bracket: "@close", next: "@pop" }],
],
whitespace: [
[/[ \t\r\n]+/, "white"],
["/-", "comment", "@comment"],
[/--.*$/, "comment"],
],
},
};