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,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
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -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
|
+
}
|
|
@@ -105,10 +105,6 @@ export async function execute(code, env = null, options = {}) {
|
|
|
105
105
|
env = createGlobalEnvironment(new Environment());
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
// Create a child environment for user code to allow shadowing of built-ins
|
|
109
|
-
// This prevents conflicts when user code declares variables with same names as stdlib functions
|
|
110
|
-
const userEnv = env.extend();
|
|
111
|
-
|
|
112
108
|
// Create interpreter with module resolver and abort signal if provided
|
|
113
109
|
const interpreter = new Interpreter(env, {
|
|
114
110
|
moduleResolver: options.moduleResolver,
|
|
@@ -124,10 +120,10 @@ export async function execute(code, env = null, options = {}) {
|
|
|
124
120
|
containsTopLevelAwait(ast);
|
|
125
121
|
|
|
126
122
|
if (needsAsync) {
|
|
127
|
-
const result = await interpreter.evaluateAsync(ast,
|
|
123
|
+
const result = await interpreter.evaluateAsync(ast, env);
|
|
128
124
|
return result instanceof ReturnValue ? result.value : result;
|
|
129
125
|
} else {
|
|
130
|
-
const result = interpreter.evaluate(ast,
|
|
126
|
+
const result = interpreter.evaluate(ast, env);
|
|
131
127
|
return result instanceof ReturnValue ? result.value : result;
|
|
132
128
|
}
|
|
133
129
|
}
|
|
@@ -9,7 +9,17 @@ export class Environment {
|
|
|
9
9
|
|
|
10
10
|
define(name, value, isConst = false) {
|
|
11
11
|
if (this.vars.has(name)) {
|
|
12
|
-
|
|
12
|
+
// Allow redeclaration for non-const (REPL-style behavior)
|
|
13
|
+
// But cannot redeclare a const
|
|
14
|
+
if (this.consts.has(name)) {
|
|
15
|
+
throw new Error(`Cannot redeclare const '${name}'`);
|
|
16
|
+
}
|
|
17
|
+
// Update existing variable
|
|
18
|
+
this.vars.set(name, value);
|
|
19
|
+
if (isConst) {
|
|
20
|
+
this.consts.add(name);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
13
23
|
}
|
|
14
24
|
this.vars.set(name, value);
|
|
15
25
|
if (isConst) {
|