jslike 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/jslike.js +1 -1
- package/dist/editor/monaco/index.cjs +239 -0
- package/{src/editor/monaco/index.js → dist/editor/monaco/index.d.cts} +4 -2
- package/dist/editor/monaco/index.d.ts +236 -0
- package/dist/editor/monaco/index.js +214 -0
- package/dist/editor/wang-prism.cjs +109 -0
- package/dist/editor/wang-prism.d.ts +136 -0
- package/dist/editor/wang-prism.js +109 -0
- package/dist/index.cjs +8106 -0
- package/{src/parser.js → dist/index.d.cts} +3276 -41
- package/dist/index.d.ts +9476 -0
- package/dist/index.js +8072 -0
- package/dist/validator/index.cjs +5753 -0
- package/dist/validator/index.d.cts +103 -0
- package/{src/validator/index.js → dist/validator/index.d.ts} +5 -2
- package/dist/validator/index.js +5727 -0
- package/package.json +49 -10
- package/src/ast/nodes.js +0 -236
- package/src/cli/wang-run.js +0 -89
- package/src/cli/wang-validate.js +0 -87
- package/src/errors/enhanced-error.js +0 -124
- package/src/index.js +0 -186
- package/src/interpreter/index.js +0 -201
- package/src/interpreter/interpreter.js +0 -2155
- package/src/metadata/index.js +0 -531
- package/src/resolvers/memory.js +0 -17
- package/src/runtime/builtins.js +0 -517
- package/src/runtime/environment.js +0 -75
- /package/{src/editor/wang-prism.js → dist/editor/wang-prism.d.cts} +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// src/editor/monaco/index.js
|
|
2
|
+
var wangLanguage = {
|
|
3
|
+
defaultToken: "invalid",
|
|
4
|
+
tokenPostfix: ".wang",
|
|
5
|
+
keywords: [
|
|
6
|
+
"let",
|
|
7
|
+
"const",
|
|
8
|
+
"var",
|
|
9
|
+
"if",
|
|
10
|
+
"else",
|
|
11
|
+
"for",
|
|
12
|
+
"while",
|
|
13
|
+
"do",
|
|
14
|
+
"break",
|
|
15
|
+
"continue",
|
|
16
|
+
"return",
|
|
17
|
+
"function",
|
|
18
|
+
"class",
|
|
19
|
+
"extends",
|
|
20
|
+
"constructor",
|
|
21
|
+
"async",
|
|
22
|
+
"await",
|
|
23
|
+
"import",
|
|
24
|
+
"export",
|
|
25
|
+
"from",
|
|
26
|
+
"as",
|
|
27
|
+
"try",
|
|
28
|
+
"catch",
|
|
29
|
+
"finally",
|
|
30
|
+
"throw",
|
|
31
|
+
"this",
|
|
32
|
+
"super",
|
|
33
|
+
"new",
|
|
34
|
+
"typeof",
|
|
35
|
+
"instanceof",
|
|
36
|
+
"in",
|
|
37
|
+
"of"
|
|
38
|
+
],
|
|
39
|
+
typeKeywords: [],
|
|
40
|
+
operators: [
|
|
41
|
+
"=>",
|
|
42
|
+
"+=",
|
|
43
|
+
"-=",
|
|
44
|
+
"*=",
|
|
45
|
+
"/=",
|
|
46
|
+
"===",
|
|
47
|
+
"!==",
|
|
48
|
+
"==",
|
|
49
|
+
"!=",
|
|
50
|
+
"<=",
|
|
51
|
+
">=",
|
|
52
|
+
"<<",
|
|
53
|
+
">>",
|
|
54
|
+
">>>",
|
|
55
|
+
"&&",
|
|
56
|
+
"||",
|
|
57
|
+
"??",
|
|
58
|
+
"?.",
|
|
59
|
+
"...",
|
|
60
|
+
"++",
|
|
61
|
+
"--",
|
|
62
|
+
"**",
|
|
63
|
+
"+",
|
|
64
|
+
"-",
|
|
65
|
+
"*",
|
|
66
|
+
"/",
|
|
67
|
+
"%",
|
|
68
|
+
"&",
|
|
69
|
+
"|",
|
|
70
|
+
"^",
|
|
71
|
+
"~",
|
|
72
|
+
"!",
|
|
73
|
+
"?",
|
|
74
|
+
":",
|
|
75
|
+
"=",
|
|
76
|
+
"<",
|
|
77
|
+
">"
|
|
78
|
+
],
|
|
79
|
+
symbols: /[=><!~?:&|+\-*\/\^%]+/,
|
|
80
|
+
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
|
81
|
+
tokenizer: {
|
|
82
|
+
root: [
|
|
83
|
+
// Identifiers and keywords
|
|
84
|
+
[
|
|
85
|
+
/[a-zA-Z_$][\w$]*/,
|
|
86
|
+
{
|
|
87
|
+
cases: {
|
|
88
|
+
"@keywords": "keyword",
|
|
89
|
+
"true|false|null|undefined": "constant",
|
|
90
|
+
"@default": "identifier"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
// Whitespace
|
|
95
|
+
{ include: "@whitespace" },
|
|
96
|
+
// Delimiters and operators
|
|
97
|
+
[/[{}()\[\]]/, "@brackets"],
|
|
98
|
+
[/[<>](?!@symbols)/, "@brackets"],
|
|
99
|
+
[
|
|
100
|
+
/@symbols/,
|
|
101
|
+
{
|
|
102
|
+
cases: {
|
|
103
|
+
"@operators": "operator",
|
|
104
|
+
"@default": ""
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
// Numbers
|
|
109
|
+
[/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"],
|
|
110
|
+
[/0[xX][0-9a-fA-F]+/, "number.hex"],
|
|
111
|
+
[/\d+/, "number"],
|
|
112
|
+
// Delimiter
|
|
113
|
+
[/[;,.]/, "delimiter"],
|
|
114
|
+
// Strings
|
|
115
|
+
[/"([^"\\]|\\.)*$/, "string.invalid"],
|
|
116
|
+
[/'([^'\\]|\\.)*$/, "string.invalid"],
|
|
117
|
+
[/"/, "string", "@string_double"],
|
|
118
|
+
[/'/, "string", "@string_single"],
|
|
119
|
+
// Template literals
|
|
120
|
+
[/`/, "string.template", "@template"],
|
|
121
|
+
// Regular expressions
|
|
122
|
+
[/\/(?=([^\/\\]|\\.)+\/)/, "regexp", "@regexp"]
|
|
123
|
+
],
|
|
124
|
+
whitespace: [
|
|
125
|
+
[/[ \t\r\n]+/, ""],
|
|
126
|
+
[/\/\*/, "comment", "@comment"],
|
|
127
|
+
[/\/\/.*$/, "comment"]
|
|
128
|
+
],
|
|
129
|
+
comment: [
|
|
130
|
+
[/[^\/*]+/, "comment"],
|
|
131
|
+
[/\*\//, "comment", "@pop"],
|
|
132
|
+
[/[\/*]/, "comment"]
|
|
133
|
+
],
|
|
134
|
+
string_double: [
|
|
135
|
+
[/[^\\"]+/, "string"],
|
|
136
|
+
[/@escapes/, "string.escape"],
|
|
137
|
+
[/\\./, "string.escape.invalid"],
|
|
138
|
+
[/"/, "string", "@pop"]
|
|
139
|
+
],
|
|
140
|
+
string_single: [
|
|
141
|
+
[/[^\\']+/, "string"],
|
|
142
|
+
[/@escapes/, "string.escape"],
|
|
143
|
+
[/\\./, "string.escape.invalid"],
|
|
144
|
+
[/'/, "string", "@pop"]
|
|
145
|
+
],
|
|
146
|
+
template: [
|
|
147
|
+
[/[^`\\$]+/, "string.template"],
|
|
148
|
+
[/@escapes/, "string.escape"],
|
|
149
|
+
[/\\./, "string.escape.invalid"],
|
|
150
|
+
[/\${/, { token: "delimiter.bracket", next: "@templateExpression" }],
|
|
151
|
+
[/`/, "string.template", "@pop"]
|
|
152
|
+
],
|
|
153
|
+
templateExpression: [[/}/, { token: "delimiter.bracket", next: "@pop" }], { include: "root" }],
|
|
154
|
+
regexp: [
|
|
155
|
+
[
|
|
156
|
+
/(\{)(\d+(?:,\d*)?)(\})/,
|
|
157
|
+
["regexp.escape.control", "regexp.escape.control", "regexp.escape.control"]
|
|
158
|
+
],
|
|
159
|
+
[/(\[)([^\]\\]|\\.)*(\])/, "regexp.escape.control"],
|
|
160
|
+
[/(\()(\?:|\?=|\?!)/, ["regexp.escape.control", "regexp.escape.control"]],
|
|
161
|
+
[/[()]/, "regexp.escape.control"],
|
|
162
|
+
[/@escapes/, "regexp.escape"],
|
|
163
|
+
[/\\./, "regexp.escape"],
|
|
164
|
+
[/\/[gimsuy]*/, { token: "regexp", bracket: "@close", next: "@pop" }],
|
|
165
|
+
[/./, "regexp"]
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
function registerWangLanguage(monaco) {
|
|
170
|
+
monaco.languages.register({ id: "wang" });
|
|
171
|
+
monaco.languages.setMonarchTokensProvider("wang", wangLanguage);
|
|
172
|
+
monaco.languages.setLanguageConfiguration("wang", {
|
|
173
|
+
comments: {
|
|
174
|
+
lineComment: "//",
|
|
175
|
+
blockComment: ["/*", "*/"]
|
|
176
|
+
},
|
|
177
|
+
brackets: [
|
|
178
|
+
["{", "}"],
|
|
179
|
+
["[", "]"],
|
|
180
|
+
["(", ")"]
|
|
181
|
+
],
|
|
182
|
+
autoClosingPairs: [
|
|
183
|
+
{ open: "{", close: "}" },
|
|
184
|
+
{ open: "[", close: "]" },
|
|
185
|
+
{ open: "(", close: ")" },
|
|
186
|
+
{ open: '"', close: '"', notIn: ["string"] },
|
|
187
|
+
{ open: "'", close: "'", notIn: ["string"] },
|
|
188
|
+
{ open: "`", close: "`", notIn: ["string"] },
|
|
189
|
+
{ open: "/*", close: "*/" }
|
|
190
|
+
],
|
|
191
|
+
surroundingPairs: [
|
|
192
|
+
{ open: "{", close: "}" },
|
|
193
|
+
{ open: "[", close: "]" },
|
|
194
|
+
{ open: "(", close: ")" },
|
|
195
|
+
{ open: '"', close: '"' },
|
|
196
|
+
{ open: "'", close: "'" },
|
|
197
|
+
{ open: "`", close: "`" }
|
|
198
|
+
],
|
|
199
|
+
folding: {
|
|
200
|
+
markers: {
|
|
201
|
+
start: new RegExp("^\\s*//\\s*#?region\\b"),
|
|
202
|
+
end: new RegExp("^\\s*//\\s*#?endregion\\b")
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
indentationRules: {
|
|
206
|
+
increaseIndentPattern: new RegExp("^.*(\\{[^}]*|\\([^)]*|\\[[^\\]]*)$"),
|
|
207
|
+
decreaseIndentPattern: new RegExp("^\\s*(\\}|\\)|\\])")
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
export {
|
|
212
|
+
registerWangLanguage,
|
|
213
|
+
wangLanguage
|
|
214
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/editor/wang-prism.js
|
|
2
|
+
(function(Prism2) {
|
|
3
|
+
Prism2.languages.wang = {
|
|
4
|
+
// Comments
|
|
5
|
+
comment: [
|
|
6
|
+
{
|
|
7
|
+
pattern: /\/\*[\s\S]*?\*\//,
|
|
8
|
+
greedy: true
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
pattern: /\/\/.*/,
|
|
12
|
+
greedy: true
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
// Template literals with interpolation
|
|
16
|
+
"template-string": {
|
|
17
|
+
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
18
|
+
greedy: true,
|
|
19
|
+
inside: {
|
|
20
|
+
"template-punctuation": {
|
|
21
|
+
pattern: /^`|`$/,
|
|
22
|
+
alias: "string"
|
|
23
|
+
},
|
|
24
|
+
interpolation: {
|
|
25
|
+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
26
|
+
lookbehind: true,
|
|
27
|
+
inside: {
|
|
28
|
+
"interpolation-punctuation": {
|
|
29
|
+
pattern: /^\$\{|\}$/,
|
|
30
|
+
alias: "punctuation"
|
|
31
|
+
},
|
|
32
|
+
rest: Prism2.languages.wang
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
string: /[\s\S]+/
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
// Strings
|
|
39
|
+
string: [
|
|
40
|
+
{
|
|
41
|
+
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
42
|
+
greedy: true
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
// Regular expressions
|
|
46
|
+
regex: {
|
|
47
|
+
pattern: /\/(?:\\.|[^\/\\\r\n])+\/[gimsuy]*/,
|
|
48
|
+
greedy: true,
|
|
49
|
+
inside: {
|
|
50
|
+
"regex-delimiter": {
|
|
51
|
+
pattern: /^\/|\/[gimsuy]*$/,
|
|
52
|
+
alias: "punctuation"
|
|
53
|
+
},
|
|
54
|
+
"regex-flags": {
|
|
55
|
+
pattern: /[gimsuy]+$/,
|
|
56
|
+
alias: "keyword"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
// Keywords
|
|
61
|
+
keyword: /\b(?:let|const|var|if|else|for|while|do|break|continue|return|function|class|extends|constructor|async|await|import|export|from|as|try|catch|finally|throw|new|this|super|typeof|instanceof|in|of)\b/,
|
|
62
|
+
// Boolean and null values
|
|
63
|
+
boolean: /\b(?:true|false)\b/,
|
|
64
|
+
null: /\b(?:null|undefined)\b/,
|
|
65
|
+
// Numbers
|
|
66
|
+
number: /\b(?:0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\b/,
|
|
67
|
+
// Arrow function operator
|
|
68
|
+
"arrow-operator": {
|
|
69
|
+
pattern: /=>/,
|
|
70
|
+
alias: "operator"
|
|
71
|
+
},
|
|
72
|
+
// Operators (order matters for matching)
|
|
73
|
+
operator: /\+\+|--|===|!==|==|!=|<=|>=|<<|>>>|>>|&&|\|\||[?]{2}|\?\.|\.{3}|\*\*|\+=|-=|\*=|\/=|[+\-*/%<>&|^~!?:]=?/,
|
|
74
|
+
// Punctuation
|
|
75
|
+
punctuation: /[{}[\];(),.:]/,
|
|
76
|
+
// Functions (pattern for function calls)
|
|
77
|
+
function: /\b[a-zA-Z_$][\w$]*(?=\s*\()/,
|
|
78
|
+
// Class names (after class or extends)
|
|
79
|
+
"class-name": {
|
|
80
|
+
pattern: /(\b(?:class|extends)\s+)[a-zA-Z_$][\w$]*/,
|
|
81
|
+
lookbehind: true
|
|
82
|
+
},
|
|
83
|
+
// Property names in object literals
|
|
84
|
+
property: {
|
|
85
|
+
pattern: /((?:^|[,{])[ \t]*)(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*|"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*')(?=\s*:)/m,
|
|
86
|
+
lookbehind: true,
|
|
87
|
+
greedy: true
|
|
88
|
+
},
|
|
89
|
+
// Variables and identifiers (must come last)
|
|
90
|
+
variable: /\b[a-zA-Z_$][\w$]*/
|
|
91
|
+
};
|
|
92
|
+
Prism2.languages.wang["class-name"].pattern = /(\b(?:class|extends|new)\s+)[a-zA-Z_$][\w$]*/;
|
|
93
|
+
Prism2.hooks.add("before-tokenize", function(env) {
|
|
94
|
+
if (env.language !== "wang") {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Prism2.hooks.add("wrap", function(env) {
|
|
99
|
+
if (env.language !== "wang") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (env.type === "keyword" && ["import", "export", "from", "as"].includes(env.content)) {
|
|
103
|
+
env.classes.push("wang-module");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
})(Prism);
|
|
107
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
108
|
+
module.exports = Prism.languages.wang;
|
|
109
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Wang Language Definition for Prism.js
|
|
2
|
+
/* global Prism */
|
|
3
|
+
(function (Prism) {
|
|
4
|
+
Prism.languages.wang = {
|
|
5
|
+
// Comments
|
|
6
|
+
comment: [
|
|
7
|
+
{
|
|
8
|
+
pattern: /\/\*[\s\S]*?\*\//,
|
|
9
|
+
greedy: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
pattern: /\/\/.*/,
|
|
13
|
+
greedy: true,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
// Template literals with interpolation
|
|
18
|
+
'template-string': {
|
|
19
|
+
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
20
|
+
greedy: true,
|
|
21
|
+
inside: {
|
|
22
|
+
'template-punctuation': {
|
|
23
|
+
pattern: /^`|`$/,
|
|
24
|
+
alias: 'string',
|
|
25
|
+
},
|
|
26
|
+
interpolation: {
|
|
27
|
+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
28
|
+
lookbehind: true,
|
|
29
|
+
inside: {
|
|
30
|
+
'interpolation-punctuation': {
|
|
31
|
+
pattern: /^\$\{|\}$/,
|
|
32
|
+
alias: 'punctuation',
|
|
33
|
+
},
|
|
34
|
+
rest: Prism.languages.wang,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
string: /[\s\S]+/,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// Strings
|
|
42
|
+
string: [
|
|
43
|
+
{
|
|
44
|
+
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
45
|
+
greedy: true,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
|
|
49
|
+
// Regular expressions
|
|
50
|
+
regex: {
|
|
51
|
+
pattern: /\/(?:\\.|[^\/\\\r\n])+\/[gimsuy]*/,
|
|
52
|
+
greedy: true,
|
|
53
|
+
inside: {
|
|
54
|
+
'regex-delimiter': {
|
|
55
|
+
pattern: /^\/|\/[gimsuy]*$/,
|
|
56
|
+
alias: 'punctuation',
|
|
57
|
+
},
|
|
58
|
+
'regex-flags': {
|
|
59
|
+
pattern: /[gimsuy]+$/,
|
|
60
|
+
alias: 'keyword',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
// Keywords
|
|
66
|
+
keyword:
|
|
67
|
+
/\b(?:let|const|var|if|else|for|while|do|break|continue|return|function|class|extends|constructor|async|await|import|export|from|as|try|catch|finally|throw|new|this|super|typeof|instanceof|in|of)\b/,
|
|
68
|
+
|
|
69
|
+
// Boolean and null values
|
|
70
|
+
boolean: /\b(?:true|false)\b/,
|
|
71
|
+
null: /\b(?:null|undefined)\b/,
|
|
72
|
+
|
|
73
|
+
// Numbers
|
|
74
|
+
number: /\b(?:0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\b/,
|
|
75
|
+
|
|
76
|
+
// Arrow function operator
|
|
77
|
+
'arrow-operator': {
|
|
78
|
+
pattern: /=>/,
|
|
79
|
+
alias: 'operator',
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
// Operators (order matters for matching)
|
|
83
|
+
operator:
|
|
84
|
+
/\+\+|--|===|!==|==|!=|<=|>=|<<|>>>|>>|&&|\|\||[?]{2}|\?\.|\.{3}|\*\*|\+=|-=|\*=|\/=|[+\-*/%<>&|^~!?:]=?/,
|
|
85
|
+
|
|
86
|
+
// Punctuation
|
|
87
|
+
punctuation: /[{}[\];(),.:]/,
|
|
88
|
+
|
|
89
|
+
// Functions (pattern for function calls)
|
|
90
|
+
function: /\b[a-zA-Z_$][\w$]*(?=\s*\()/,
|
|
91
|
+
|
|
92
|
+
// Class names (after class or extends)
|
|
93
|
+
'class-name': {
|
|
94
|
+
pattern: /(\b(?:class|extends)\s+)[a-zA-Z_$][\w$]*/,
|
|
95
|
+
lookbehind: true,
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// Property names in object literals
|
|
99
|
+
property: {
|
|
100
|
+
pattern:
|
|
101
|
+
/((?:^|[,{])[ \t]*)(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*|"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*')(?=\s*:)/m,
|
|
102
|
+
lookbehind: true,
|
|
103
|
+
greedy: true,
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
// Variables and identifiers (must come last)
|
|
107
|
+
variable: /\b[a-zA-Z_$][\w$]*/,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Set wang as an alias for javascript-like highlighting
|
|
111
|
+
Prism.languages.wang['class-name'].pattern = /(\b(?:class|extends|new)\s+)[a-zA-Z_$][\w$]*/;
|
|
112
|
+
|
|
113
|
+
// Hook to handle special Wang syntax
|
|
114
|
+
Prism.hooks.add('before-tokenize', function (env) {
|
|
115
|
+
if (env.language !== 'wang') {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Hook to add special classes for Wang-specific features
|
|
121
|
+
Prism.hooks.add('wrap', function (env) {
|
|
122
|
+
if (env.language !== 'wang') {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Add special class for Wang keywords
|
|
127
|
+
if (env.type === 'keyword' && ['import', 'export', 'from', 'as'].includes(env.content)) {
|
|
128
|
+
env.classes.push('wang-module');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
})(Prism);
|
|
132
|
+
|
|
133
|
+
// Export for module systems
|
|
134
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
135
|
+
module.exports = Prism.languages.wang;
|
|
136
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/editor/wang-prism.js
|
|
2
|
+
(function(Prism2) {
|
|
3
|
+
Prism2.languages.wang = {
|
|
4
|
+
// Comments
|
|
5
|
+
comment: [
|
|
6
|
+
{
|
|
7
|
+
pattern: /\/\*[\s\S]*?\*\//,
|
|
8
|
+
greedy: true
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
pattern: /\/\/.*/,
|
|
12
|
+
greedy: true
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
// Template literals with interpolation
|
|
16
|
+
"template-string": {
|
|
17
|
+
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
18
|
+
greedy: true,
|
|
19
|
+
inside: {
|
|
20
|
+
"template-punctuation": {
|
|
21
|
+
pattern: /^`|`$/,
|
|
22
|
+
alias: "string"
|
|
23
|
+
},
|
|
24
|
+
interpolation: {
|
|
25
|
+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
26
|
+
lookbehind: true,
|
|
27
|
+
inside: {
|
|
28
|
+
"interpolation-punctuation": {
|
|
29
|
+
pattern: /^\$\{|\}$/,
|
|
30
|
+
alias: "punctuation"
|
|
31
|
+
},
|
|
32
|
+
rest: Prism2.languages.wang
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
string: /[\s\S]+/
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
// Strings
|
|
39
|
+
string: [
|
|
40
|
+
{
|
|
41
|
+
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
42
|
+
greedy: true
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
// Regular expressions
|
|
46
|
+
regex: {
|
|
47
|
+
pattern: /\/(?:\\.|[^\/\\\r\n])+\/[gimsuy]*/,
|
|
48
|
+
greedy: true,
|
|
49
|
+
inside: {
|
|
50
|
+
"regex-delimiter": {
|
|
51
|
+
pattern: /^\/|\/[gimsuy]*$/,
|
|
52
|
+
alias: "punctuation"
|
|
53
|
+
},
|
|
54
|
+
"regex-flags": {
|
|
55
|
+
pattern: /[gimsuy]+$/,
|
|
56
|
+
alias: "keyword"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
// Keywords
|
|
61
|
+
keyword: /\b(?:let|const|var|if|else|for|while|do|break|continue|return|function|class|extends|constructor|async|await|import|export|from|as|try|catch|finally|throw|new|this|super|typeof|instanceof|in|of)\b/,
|
|
62
|
+
// Boolean and null values
|
|
63
|
+
boolean: /\b(?:true|false)\b/,
|
|
64
|
+
null: /\b(?:null|undefined)\b/,
|
|
65
|
+
// Numbers
|
|
66
|
+
number: /\b(?:0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\b/,
|
|
67
|
+
// Arrow function operator
|
|
68
|
+
"arrow-operator": {
|
|
69
|
+
pattern: /=>/,
|
|
70
|
+
alias: "operator"
|
|
71
|
+
},
|
|
72
|
+
// Operators (order matters for matching)
|
|
73
|
+
operator: /\+\+|--|===|!==|==|!=|<=|>=|<<|>>>|>>|&&|\|\||[?]{2}|\?\.|\.{3}|\*\*|\+=|-=|\*=|\/=|[+\-*/%<>&|^~!?:]=?/,
|
|
74
|
+
// Punctuation
|
|
75
|
+
punctuation: /[{}[\];(),.:]/,
|
|
76
|
+
// Functions (pattern for function calls)
|
|
77
|
+
function: /\b[a-zA-Z_$][\w$]*(?=\s*\()/,
|
|
78
|
+
// Class names (after class or extends)
|
|
79
|
+
"class-name": {
|
|
80
|
+
pattern: /(\b(?:class|extends)\s+)[a-zA-Z_$][\w$]*/,
|
|
81
|
+
lookbehind: true
|
|
82
|
+
},
|
|
83
|
+
// Property names in object literals
|
|
84
|
+
property: {
|
|
85
|
+
pattern: /((?:^|[,{])[ \t]*)(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*|"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*')(?=\s*:)/m,
|
|
86
|
+
lookbehind: true,
|
|
87
|
+
greedy: true
|
|
88
|
+
},
|
|
89
|
+
// Variables and identifiers (must come last)
|
|
90
|
+
variable: /\b[a-zA-Z_$][\w$]*/
|
|
91
|
+
};
|
|
92
|
+
Prism2.languages.wang["class-name"].pattern = /(\b(?:class|extends|new)\s+)[a-zA-Z_$][\w$]*/;
|
|
93
|
+
Prism2.hooks.add("before-tokenize", function(env) {
|
|
94
|
+
if (env.language !== "wang") {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Prism2.hooks.add("wrap", function(env) {
|
|
99
|
+
if (env.language !== "wang") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (env.type === "keyword" && ["import", "export", "from", "as"].includes(env.content)) {
|
|
103
|
+
env.classes.push("wang-module");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
})(Prism);
|
|
107
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
108
|
+
module.exports = Prism.languages.wang;
|
|
109
|
+
}
|