jslike 1.3.1 → 1.4.1
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/dist/editor/monaco/index.d.cts +236 -0
- 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/{src → dist/esm}/cli/wang-run.js +0 -0
- package/{src → dist/esm}/cli/wang-validate.js +0 -0
- package/dist/esm/editor/wang-prism.js +136 -0
- package/{src → dist/esm}/index.js +2 -6
- package/{src → dist/esm}/runtime/environment.js +11 -1
- package/dist/index.cjs +8112 -0
- package/dist/index.d.cts +9482 -0
- package/dist/index.d.ts +9482 -0
- package/dist/index.js +8078 -0
- package/dist/validator/index.cjs +5753 -0
- package/dist/validator/index.d.cts +103 -0
- package/dist/validator/index.d.ts +103 -0
- package/dist/validator/index.js +5727 -0
- package/package.json +50 -10
- /package/{src/editor/wang-prism.js → dist/editor/wang-prism.d.cts} +0 -0
- /package/{src → dist/esm}/ast/nodes.js +0 -0
- /package/{src → dist/esm}/editor/monaco/index.js +0 -0
- /package/{src → dist/esm}/errors/enhanced-error.js +0 -0
- /package/{src → dist/esm}/interpreter/index.js +0 -0
- /package/{src → dist/esm}/interpreter/interpreter.js +0 -0
- /package/{src → dist/esm}/metadata/index.js +0 -0
- /package/{src → dist/esm}/parser.js +0 -0
- /package/{src → dist/esm}/resolvers/memory.js +0 -0
- /package/{src → dist/esm}/runtime/builtins.js +0 -0
- /package/{src → dist/esm}/validator/index.js +0 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Wang Language Definition for Monaco Editor
|
|
2
|
+
const wangLanguage = {
|
|
3
|
+
defaultToken: 'invalid',
|
|
4
|
+
tokenPostfix: '.wang',
|
|
5
|
+
|
|
6
|
+
keywords: [
|
|
7
|
+
'let',
|
|
8
|
+
'const',
|
|
9
|
+
'var',
|
|
10
|
+
'if',
|
|
11
|
+
'else',
|
|
12
|
+
'for',
|
|
13
|
+
'while',
|
|
14
|
+
'do',
|
|
15
|
+
'break',
|
|
16
|
+
'continue',
|
|
17
|
+
'return',
|
|
18
|
+
'function',
|
|
19
|
+
'class',
|
|
20
|
+
'extends',
|
|
21
|
+
'constructor',
|
|
22
|
+
'async',
|
|
23
|
+
'await',
|
|
24
|
+
'import',
|
|
25
|
+
'export',
|
|
26
|
+
'from',
|
|
27
|
+
'as',
|
|
28
|
+
'try',
|
|
29
|
+
'catch',
|
|
30
|
+
'finally',
|
|
31
|
+
'throw',
|
|
32
|
+
'this',
|
|
33
|
+
'super',
|
|
34
|
+
'new',
|
|
35
|
+
'typeof',
|
|
36
|
+
'instanceof',
|
|
37
|
+
'in',
|
|
38
|
+
'of',
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
typeKeywords: [],
|
|
42
|
+
|
|
43
|
+
operators: [
|
|
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
|
+
'<',
|
|
80
|
+
'>',
|
|
81
|
+
],
|
|
82
|
+
|
|
83
|
+
symbols: /[=><!~?:&|+\-*\/\^%]+/,
|
|
84
|
+
|
|
85
|
+
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
|
86
|
+
|
|
87
|
+
tokenizer: {
|
|
88
|
+
root: [
|
|
89
|
+
// Identifiers and keywords
|
|
90
|
+
[
|
|
91
|
+
/[a-zA-Z_$][\w$]*/,
|
|
92
|
+
{
|
|
93
|
+
cases: {
|
|
94
|
+
'@keywords': 'keyword',
|
|
95
|
+
'true|false|null|undefined': 'constant',
|
|
96
|
+
'@default': 'identifier',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
|
|
101
|
+
// Whitespace
|
|
102
|
+
{ include: '@whitespace' },
|
|
103
|
+
|
|
104
|
+
// Delimiters and operators
|
|
105
|
+
[/[{}()\[\]]/, '@brackets'],
|
|
106
|
+
[/[<>](?!@symbols)/, '@brackets'],
|
|
107
|
+
[
|
|
108
|
+
/@symbols/,
|
|
109
|
+
{
|
|
110
|
+
cases: {
|
|
111
|
+
'@operators': 'operator',
|
|
112
|
+
'@default': '',
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
|
|
117
|
+
// Numbers
|
|
118
|
+
[/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
|
|
119
|
+
[/0[xX][0-9a-fA-F]+/, 'number.hex'],
|
|
120
|
+
[/\d+/, 'number'],
|
|
121
|
+
|
|
122
|
+
// Delimiter
|
|
123
|
+
[/[;,.]/, 'delimiter'],
|
|
124
|
+
|
|
125
|
+
// Strings
|
|
126
|
+
[/"([^"\\]|\\.)*$/, 'string.invalid'],
|
|
127
|
+
[/'([^'\\]|\\.)*$/, 'string.invalid'],
|
|
128
|
+
[/"/, 'string', '@string_double'],
|
|
129
|
+
[/'/, 'string', '@string_single'],
|
|
130
|
+
|
|
131
|
+
// Template literals
|
|
132
|
+
[/`/, 'string.template', '@template'],
|
|
133
|
+
|
|
134
|
+
// Regular expressions
|
|
135
|
+
[/\/(?=([^\/\\]|\\.)+\/)/, 'regexp', '@regexp'],
|
|
136
|
+
],
|
|
137
|
+
|
|
138
|
+
whitespace: [
|
|
139
|
+
[/[ \t\r\n]+/, ''],
|
|
140
|
+
[/\/\*/, 'comment', '@comment'],
|
|
141
|
+
[/\/\/.*$/, 'comment'],
|
|
142
|
+
],
|
|
143
|
+
|
|
144
|
+
comment: [
|
|
145
|
+
[/[^\/*]+/, 'comment'],
|
|
146
|
+
[/\*\//, 'comment', '@pop'],
|
|
147
|
+
[/[\/*]/, 'comment'],
|
|
148
|
+
],
|
|
149
|
+
|
|
150
|
+
string_double: [
|
|
151
|
+
[/[^\\"]+/, 'string'],
|
|
152
|
+
[/@escapes/, 'string.escape'],
|
|
153
|
+
[/\\./, 'string.escape.invalid'],
|
|
154
|
+
[/"/, 'string', '@pop'],
|
|
155
|
+
],
|
|
156
|
+
|
|
157
|
+
string_single: [
|
|
158
|
+
[/[^\\']+/, 'string'],
|
|
159
|
+
[/@escapes/, 'string.escape'],
|
|
160
|
+
[/\\./, 'string.escape.invalid'],
|
|
161
|
+
[/'/, 'string', '@pop'],
|
|
162
|
+
],
|
|
163
|
+
|
|
164
|
+
template: [
|
|
165
|
+
[/[^`\\$]+/, 'string.template'],
|
|
166
|
+
[/@escapes/, 'string.escape'],
|
|
167
|
+
[/\\./, 'string.escape.invalid'],
|
|
168
|
+
[/\${/, { token: 'delimiter.bracket', next: '@templateExpression' }],
|
|
169
|
+
[/`/, 'string.template', '@pop'],
|
|
170
|
+
],
|
|
171
|
+
|
|
172
|
+
templateExpression: [[/}/, { token: 'delimiter.bracket', next: '@pop' }], { include: 'root' }],
|
|
173
|
+
|
|
174
|
+
regexp: [
|
|
175
|
+
[
|
|
176
|
+
/(\{)(\d+(?:,\d*)?)(\})/,
|
|
177
|
+
['regexp.escape.control', 'regexp.escape.control', 'regexp.escape.control'],
|
|
178
|
+
],
|
|
179
|
+
[/(\[)([^\]\\]|\\.)*(\])/, 'regexp.escape.control'],
|
|
180
|
+
[/(\()(\?:|\?=|\?!)/, ['regexp.escape.control', 'regexp.escape.control']],
|
|
181
|
+
[/[()]/, 'regexp.escape.control'],
|
|
182
|
+
[/@escapes/, 'regexp.escape'],
|
|
183
|
+
[/\\./, 'regexp.escape'],
|
|
184
|
+
[/\/[gimsuy]*/, { token: 'regexp', bracket: '@close', next: '@pop' }],
|
|
185
|
+
[/./, 'regexp'],
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Register the language with Monaco
|
|
191
|
+
function registerWangLanguage(monaco) {
|
|
192
|
+
monaco.languages.register({ id: 'wang' });
|
|
193
|
+
monaco.languages.setMonarchTokensProvider('wang', wangLanguage);
|
|
194
|
+
|
|
195
|
+
// Configuration for brackets and auto-closing
|
|
196
|
+
monaco.languages.setLanguageConfiguration('wang', {
|
|
197
|
+
comments: {
|
|
198
|
+
lineComment: '//',
|
|
199
|
+
blockComment: ['/*', '*/'],
|
|
200
|
+
},
|
|
201
|
+
brackets: [
|
|
202
|
+
['{', '}'],
|
|
203
|
+
['[', ']'],
|
|
204
|
+
['(', ')'],
|
|
205
|
+
],
|
|
206
|
+
autoClosingPairs: [
|
|
207
|
+
{ open: '{', close: '}' },
|
|
208
|
+
{ open: '[', close: ']' },
|
|
209
|
+
{ open: '(', close: ')' },
|
|
210
|
+
{ open: '"', close: '"', notIn: ['string'] },
|
|
211
|
+
{ open: "'", close: "'", notIn: ['string'] },
|
|
212
|
+
{ open: '`', close: '`', notIn: ['string'] },
|
|
213
|
+
{ open: '/*', close: '*/' },
|
|
214
|
+
],
|
|
215
|
+
surroundingPairs: [
|
|
216
|
+
{ open: '{', close: '}' },
|
|
217
|
+
{ open: '[', close: ']' },
|
|
218
|
+
{ open: '(', close: ')' },
|
|
219
|
+
{ open: '"', close: '"' },
|
|
220
|
+
{ open: "'", close: "'" },
|
|
221
|
+
{ open: '`', close: '`' },
|
|
222
|
+
],
|
|
223
|
+
folding: {
|
|
224
|
+
markers: {
|
|
225
|
+
start: new RegExp('^\\s*//\\s*#?region\\b'),
|
|
226
|
+
end: new RegExp('^\\s*//\\s*#?endregion\\b'),
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
indentationRules: {
|
|
230
|
+
increaseIndentPattern: new RegExp('^.*(\\{[^}]*|\\([^)]*|\\[[^\\]]*)$'),
|
|
231
|
+
decreaseIndentPattern: new RegExp('^\\s*(\\}|\\)|\\])'),
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export { registerWangLanguage, wangLanguage };
|
|
@@ -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
|
+
}
|