@cuxt/sandboxjs 0.1.0 → 0.1.3
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/LICENSE +21 -21
- package/README.md +198 -185
- package/{build → dist/cjs}/Sandbox.d.ts +15 -6
- package/dist/cjs/Sandbox.js +126 -0
- package/dist/{SandboxExec.d.ts → cjs/SandboxExec.d.ts} +8 -17
- package/dist/cjs/SandboxExec.js +227 -0
- package/{build/eval.d.ts → dist/cjs/eval/index.d.ts} +10 -2
- package/dist/cjs/eval/index.js +233 -0
- package/dist/cjs/executor/executorUtils.d.ts +161 -0
- package/dist/cjs/executor/executorUtils.js +930 -0
- package/dist/cjs/executor/index.d.ts +1 -0
- package/dist/cjs/executor/index.js +2 -0
- package/dist/cjs/executor/ops/assignment.d.ts +1 -0
- package/dist/cjs/executor/ops/assignment.js +88 -0
- package/dist/cjs/executor/ops/call.d.ts +1 -0
- package/dist/cjs/executor/ops/call.js +160 -0
- package/dist/cjs/executor/ops/comparison.d.ts +1 -0
- package/dist/cjs/executor/ops/comparison.js +36 -0
- package/dist/cjs/executor/ops/control.d.ts +1 -0
- package/dist/cjs/executor/ops/control.js +203 -0
- package/dist/cjs/executor/ops/functions.d.ts +1 -0
- package/dist/cjs/executor/ops/functions.js +55 -0
- package/dist/cjs/executor/ops/index.d.ts +0 -0
- package/dist/cjs/executor/ops/index.js +11 -0
- package/dist/cjs/executor/ops/literals.d.ts +1 -0
- package/dist/cjs/executor/ops/literals.js +45 -0
- package/dist/cjs/executor/ops/misc.d.ts +1 -0
- package/dist/cjs/executor/ops/misc.js +25 -0
- package/dist/cjs/executor/ops/object.d.ts +1 -0
- package/dist/cjs/executor/ops/object.js +51 -0
- package/dist/cjs/executor/ops/prop.d.ts +1 -0
- package/dist/cjs/executor/ops/prop.js +70 -0
- package/dist/cjs/executor/ops/unary.d.ts +1 -0
- package/dist/cjs/executor/ops/unary.js +48 -0
- package/dist/cjs/executor/ops/variables.d.ts +1 -0
- package/dist/cjs/executor/ops/variables.js +16 -0
- package/dist/cjs/executor/opsRegistry.d.ts +33 -0
- package/dist/cjs/executor/opsRegistry.js +8 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/parser/index.d.ts +3 -0
- package/dist/cjs/parser/index.js +1 -0
- package/dist/{parser.d.ts → cjs/parser/lisp.d.ts} +29 -42
- package/dist/cjs/parser/lispTypes/conditionals.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/conditionals.js +135 -0
- package/dist/cjs/parser/lispTypes/control.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/control.js +204 -0
- package/dist/cjs/parser/lispTypes/declarations.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/declarations.js +99 -0
- package/dist/cjs/parser/lispTypes/index.d.ts +3 -0
- package/dist/cjs/parser/lispTypes/index.js +17 -0
- package/dist/cjs/parser/lispTypes/operators.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/operators.js +252 -0
- package/dist/cjs/parser/lispTypes/shared.d.ts +38 -0
- package/dist/cjs/parser/lispTypes/structures.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/structures.js +188 -0
- package/dist/cjs/parser/lispTypes/values.d.ts +2 -0
- package/dist/cjs/parser/lispTypes/values.js +89 -0
- package/dist/cjs/parser/parserUtils.d.ts +34 -0
- package/dist/cjs/parser/parserUtils.js +968 -0
- package/dist/cjs/utils/CodeString.d.ts +16 -0
- package/dist/cjs/utils/CodeString.js +64 -0
- package/dist/cjs/utils/ExecContext.d.ts +34 -0
- package/dist/cjs/utils/ExecContext.js +171 -0
- package/dist/cjs/utils/Prop.d.ts +16 -0
- package/dist/cjs/utils/Prop.js +81 -0
- package/dist/cjs/utils/Scope.d.ts +47 -0
- package/dist/cjs/utils/Scope.js +127 -0
- package/dist/cjs/utils/errors.d.ts +10 -0
- package/dist/cjs/utils/errors.js +12 -0
- package/dist/cjs/utils/functionReplacements.d.ts +11 -0
- package/dist/cjs/utils/functionReplacements.js +362 -0
- package/dist/cjs/utils/index.d.ts +7 -0
- package/dist/cjs/utils/index.js +7 -0
- package/dist/cjs/utils/types.d.ts +221 -0
- package/dist/cjs/utils/types.js +164 -0
- package/dist/cjs/utils/unraw.js +145 -0
- package/dist/{node → esm}/Sandbox.d.ts +15 -6
- package/dist/esm/Sandbox.js +115 -0
- package/dist/esm/Sandbox.js.map +1 -0
- package/{build → dist/esm}/SandboxExec.d.ts +8 -17
- package/dist/esm/SandboxExec.js +224 -0
- package/dist/esm/SandboxExec.js.map +1 -0
- package/dist/{eval.d.ts → esm/eval/index.d.ts} +10 -2
- package/dist/esm/eval/index.js +235 -0
- package/dist/esm/eval/index.js.map +1 -0
- package/dist/esm/executor/executorUtils.d.ts +161 -0
- package/dist/esm/executor/executorUtils.js +898 -0
- package/dist/esm/executor/executorUtils.js.map +1 -0
- package/dist/esm/executor/index.d.ts +1 -0
- package/dist/esm/executor/index.js +2 -0
- package/dist/esm/executor/ops/assignment.d.ts +1 -0
- package/dist/esm/executor/ops/assignment.js +90 -0
- package/dist/esm/executor/ops/assignment.js.map +1 -0
- package/dist/esm/executor/ops/call.d.ts +1 -0
- package/dist/esm/executor/ops/call.js +162 -0
- package/dist/esm/executor/ops/call.js.map +1 -0
- package/dist/esm/executor/ops/comparison.d.ts +1 -0
- package/dist/esm/executor/ops/comparison.js +38 -0
- package/dist/esm/executor/ops/comparison.js.map +1 -0
- package/dist/esm/executor/ops/control.d.ts +1 -0
- package/dist/esm/executor/ops/control.js +205 -0
- package/dist/esm/executor/ops/control.js.map +1 -0
- package/dist/esm/executor/ops/functions.d.ts +1 -0
- package/dist/esm/executor/ops/functions.js +57 -0
- package/dist/esm/executor/ops/functions.js.map +1 -0
- package/dist/esm/executor/ops/index.d.ts +0 -0
- package/dist/esm/executor/ops/index.js +11 -0
- package/dist/esm/executor/ops/literals.d.ts +1 -0
- package/dist/esm/executor/ops/literals.js +47 -0
- package/dist/esm/executor/ops/literals.js.map +1 -0
- package/dist/esm/executor/ops/misc.d.ts +1 -0
- package/dist/esm/executor/ops/misc.js +27 -0
- package/dist/esm/executor/ops/misc.js.map +1 -0
- package/dist/esm/executor/ops/object.d.ts +1 -0
- package/dist/esm/executor/ops/object.js +53 -0
- package/dist/esm/executor/ops/object.js.map +1 -0
- package/dist/esm/executor/ops/prop.d.ts +1 -0
- package/dist/esm/executor/ops/prop.js +72 -0
- package/dist/esm/executor/ops/prop.js.map +1 -0
- package/dist/esm/executor/ops/unary.d.ts +1 -0
- package/dist/esm/executor/ops/unary.js +50 -0
- package/dist/esm/executor/ops/unary.js.map +1 -0
- package/dist/esm/executor/ops/variables.d.ts +1 -0
- package/dist/esm/executor/ops/variables.js +18 -0
- package/dist/esm/executor/ops/variables.js.map +1 -0
- package/dist/esm/executor/opsRegistry.d.ts +33 -0
- package/dist/esm/executor/opsRegistry.js +9 -0
- package/dist/esm/executor/opsRegistry.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parser/index.d.ts +3 -0
- package/dist/esm/parser/index.js +1 -0
- package/{build/parser.d.ts → dist/esm/parser/lisp.d.ts} +29 -42
- package/dist/esm/parser/lispTypes/conditionals.d.ts +2 -0
- package/dist/esm/parser/lispTypes/conditionals.js +137 -0
- package/dist/esm/parser/lispTypes/conditionals.js.map +1 -0
- package/dist/esm/parser/lispTypes/control.d.ts +2 -0
- package/dist/esm/parser/lispTypes/control.js +206 -0
- package/dist/esm/parser/lispTypes/control.js.map +1 -0
- package/dist/esm/parser/lispTypes/declarations.d.ts +2 -0
- package/dist/esm/parser/lispTypes/declarations.js +101 -0
- package/dist/esm/parser/lispTypes/declarations.js.map +1 -0
- package/dist/esm/parser/lispTypes/index.d.ts +3 -0
- package/dist/esm/parser/lispTypes/index.js +19 -0
- package/dist/esm/parser/lispTypes/index.js.map +1 -0
- package/dist/esm/parser/lispTypes/operators.d.ts +2 -0
- package/dist/esm/parser/lispTypes/operators.js +254 -0
- package/dist/esm/parser/lispTypes/operators.js.map +1 -0
- package/dist/esm/parser/lispTypes/shared.d.ts +38 -0
- package/dist/esm/parser/lispTypes/structures.d.ts +2 -0
- package/dist/esm/parser/lispTypes/structures.js +190 -0
- package/dist/esm/parser/lispTypes/structures.js.map +1 -0
- package/dist/esm/parser/lispTypes/values.d.ts +2 -0
- package/dist/esm/parser/lispTypes/values.js +91 -0
- package/dist/esm/parser/lispTypes/values.js.map +1 -0
- package/dist/esm/parser/parserUtils.d.ts +34 -0
- package/dist/esm/parser/parserUtils.js +959 -0
- package/dist/esm/parser/parserUtils.js.map +1 -0
- package/dist/esm/utils/CodeString.d.ts +16 -0
- package/dist/esm/utils/CodeString.js +66 -0
- package/dist/esm/utils/CodeString.js.map +1 -0
- package/dist/esm/utils/ExecContext.d.ts +34 -0
- package/dist/esm/utils/ExecContext.js +168 -0
- package/dist/esm/utils/ExecContext.js.map +1 -0
- package/dist/esm/utils/Prop.d.ts +16 -0
- package/dist/esm/utils/Prop.js +80 -0
- package/dist/esm/utils/Prop.js.map +1 -0
- package/dist/esm/utils/Scope.d.ts +47 -0
- package/dist/esm/utils/Scope.js +122 -0
- package/dist/esm/utils/Scope.js.map +1 -0
- package/dist/esm/utils/errors.d.ts +10 -0
- package/dist/esm/utils/errors.js +10 -0
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/functionReplacements.d.ts +11 -0
- package/dist/esm/utils/functionReplacements.js +361 -0
- package/dist/esm/utils/functionReplacements.js.map +1 -0
- package/dist/esm/utils/index.d.ts +7 -0
- package/dist/esm/utils/index.js +7 -0
- package/dist/esm/utils/types.d.ts +221 -0
- package/dist/esm/utils/types.js +160 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/esm/utils/unraw.js +147 -0
- package/dist/esm/utils/unraw.js.map +1 -0
- package/dist/umd/Sandbox.min.js +2 -0
- package/dist/umd/Sandbox.min.js.map +1 -0
- package/dist/umd/SandboxExec.min.js +2 -0
- package/dist/umd/SandboxExec.min.js.map +1 -0
- package/package.json +70 -68
- package/build/Sandbox.js +0 -62
- package/build/SandboxExec.js +0 -214
- package/build/eval.js +0 -205
- package/build/executor.d.ts +0 -124
- package/build/executor.js +0 -1546
- package/build/parser.js +0 -1527
- package/build/unraw.js +0 -168
- package/build/utils.d.ts +0 -264
- package/build/utils.js +0 -362
- package/dist/Sandbox.d.ts +0 -25
- package/dist/Sandbox.js +0 -270
- package/dist/Sandbox.js.map +0 -1
- package/dist/Sandbox.min.js +0 -2
- package/dist/Sandbox.min.js.map +0 -1
- package/dist/SandboxExec.js +0 -218
- package/dist/SandboxExec.js.map +0 -1
- package/dist/SandboxExec.min.js +0 -2
- package/dist/SandboxExec.min.js.map +0 -1
- package/dist/executor.d.ts +0 -124
- package/dist/executor.js +0 -1550
- package/dist/executor.js.map +0 -1
- package/dist/node/Sandbox.js +0 -277
- package/dist/node/SandboxExec.d.ts +0 -66
- package/dist/node/SandboxExec.js +0 -225
- package/dist/node/eval.d.ts +0 -27
- package/dist/node/executor.d.ts +0 -124
- package/dist/node/executor.js +0 -1567
- package/dist/node/parser.d.ts +0 -154
- package/dist/node/parser.js +0 -1704
- package/dist/node/utils.d.ts +0 -264
- package/dist/node/utils.js +0 -385
- package/dist/parser.js +0 -1690
- package/dist/parser.js.map +0 -1
- package/dist/unraw.d.ts +0 -11
- package/dist/utils.d.ts +0 -264
- package/dist/utils.js +0 -365
- package/dist/utils.js.map +0 -1
- /package/{build → dist/cjs/utils}/unraw.d.ts +0 -0
- /package/dist/{node → esm/utils}/unraw.d.ts +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const require_CodeString = require("../../utils/CodeString.js");
|
|
2
|
+
const require_types = require("../../utils/types.js");
|
|
3
|
+
const require_ExecContext = require("../../utils/ExecContext.js");
|
|
4
|
+
require("../../utils/index.js");
|
|
5
|
+
//#region src/parser/lispTypes/structures.ts
|
|
6
|
+
function registerStructureLispTypes({ NullLisp, createLisp, emptyString, expectTypes, expandDestructure, findPatternEndIdx, lispify, lispifyBlock, lispifyExpr, restOfExp, setLispType }) {
|
|
7
|
+
const closingsCreate = {
|
|
8
|
+
createArray: /^\]/,
|
|
9
|
+
createObject: /^\}/,
|
|
10
|
+
group: /^\)/,
|
|
11
|
+
arrayProp: /^\]/,
|
|
12
|
+
call: /^\)/
|
|
13
|
+
};
|
|
14
|
+
const typesCreate = {
|
|
15
|
+
createArray: require_types.LispType.CreateArray,
|
|
16
|
+
createObject: require_types.LispType.CreateObject,
|
|
17
|
+
group: require_types.LispType.Group,
|
|
18
|
+
arrayProp: require_types.LispType.ArrayProp,
|
|
19
|
+
call: require_types.LispType.Call,
|
|
20
|
+
prop: require_types.LispType.Prop,
|
|
21
|
+
"?prop": require_types.LispType.PropOptional,
|
|
22
|
+
"?call": require_types.LispType.CallOptional
|
|
23
|
+
};
|
|
24
|
+
setLispType([
|
|
25
|
+
"createArray",
|
|
26
|
+
"createObject",
|
|
27
|
+
"group",
|
|
28
|
+
"arrayProp",
|
|
29
|
+
"call"
|
|
30
|
+
], (ctx) => {
|
|
31
|
+
const { constants, type, part, res, expect } = ctx;
|
|
32
|
+
let extract = emptyString;
|
|
33
|
+
const arg = [];
|
|
34
|
+
const argIsHole = [];
|
|
35
|
+
let end = false;
|
|
36
|
+
let i = res[0].length;
|
|
37
|
+
const start = i;
|
|
38
|
+
while (i < part.length && !end) {
|
|
39
|
+
extract = restOfExp(constants, part.substring(i), [closingsCreate[type], /^,/]);
|
|
40
|
+
i += extract.length;
|
|
41
|
+
if (extract.trim().length) {
|
|
42
|
+
arg.push(extract);
|
|
43
|
+
argIsHole.push(false);
|
|
44
|
+
} else if (type === "createArray" && part.char(i) === ",") {
|
|
45
|
+
arg.push(extract);
|
|
46
|
+
argIsHole.push(true);
|
|
47
|
+
}
|
|
48
|
+
if (part.char(i) !== ",") end = true;
|
|
49
|
+
else {
|
|
50
|
+
if (!extract.trim().length && type === "call") throw new SyntaxError("Unexpected end of expression");
|
|
51
|
+
if (!extract.trim().length && type === "createObject") throw new SyntaxError("Unexpected token ,");
|
|
52
|
+
i++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const next = type === "createArray" || type === "createObject" || type === "group" ? [
|
|
56
|
+
"value",
|
|
57
|
+
"modifier",
|
|
58
|
+
"prop",
|
|
59
|
+
"incrementerBefore",
|
|
60
|
+
"assignment",
|
|
61
|
+
"expEnd"
|
|
62
|
+
] : [
|
|
63
|
+
"value",
|
|
64
|
+
"modifier",
|
|
65
|
+
"prop",
|
|
66
|
+
"incrementerBefore",
|
|
67
|
+
"expEnd"
|
|
68
|
+
];
|
|
69
|
+
let l;
|
|
70
|
+
let funcFound;
|
|
71
|
+
switch (type) {
|
|
72
|
+
case "group": {
|
|
73
|
+
const groupContentStr = part.substring(start, i).trim().toString();
|
|
74
|
+
if (groupContentStr.startsWith("{") || groupContentStr.startsWith("[")) {
|
|
75
|
+
const patternEnd = findPatternEndIdx(groupContentStr);
|
|
76
|
+
const patternStr = groupContentStr.slice(0, patternEnd).trim();
|
|
77
|
+
const afterPattern = groupContentStr.slice(patternEnd).trimStart();
|
|
78
|
+
if (afterPattern.startsWith("=")) {
|
|
79
|
+
const rhsStr = afterPattern.slice(1).trim();
|
|
80
|
+
const tempName = `$$_da${Math.random().toString(36).slice(2)}`;
|
|
81
|
+
const expandedCode = `internal ${tempName} = (${rhsStr}); ${expandDestructure("", patternStr, tempName)}; ${tempName}`;
|
|
82
|
+
l = createLisp({
|
|
83
|
+
op: require_types.LispType.InternalBlock,
|
|
84
|
+
a: lispifyBlock(new require_CodeString.CodeString(expandedCode), constants, false, ctx),
|
|
85
|
+
b: require_types.LispType.None
|
|
86
|
+
});
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
case "arrayProp": {
|
|
92
|
+
const arrayPropExpr = part.substring(start, i);
|
|
93
|
+
if (!arrayPropExpr.trimStart().length) throw new SyntaxError("Unexpected end of expression");
|
|
94
|
+
l = lispifyExpr(constants, arrayPropExpr, void 0, {
|
|
95
|
+
...ctx,
|
|
96
|
+
lispDepth: ctx.lispDepth + 1
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case "call":
|
|
101
|
+
l = arg.map((e) => lispify(constants, e, [...next, "spreadArray"], void 0, false, ctx));
|
|
102
|
+
break;
|
|
103
|
+
case "createArray":
|
|
104
|
+
l = arg.map((e, idx) => argIsHole[idx] ? createLisp({
|
|
105
|
+
op: require_types.LispType.Hole,
|
|
106
|
+
a: require_types.LispType.None,
|
|
107
|
+
b: require_types.LispType.None
|
|
108
|
+
}) : lispify(constants, e, [...next, "spreadArray"], void 0, false, ctx));
|
|
109
|
+
break;
|
|
110
|
+
case "createObject":
|
|
111
|
+
l = arg.map((str) => {
|
|
112
|
+
str = str.trimStart();
|
|
113
|
+
let value;
|
|
114
|
+
let key = "";
|
|
115
|
+
if (str.char(0) === "[") {
|
|
116
|
+
const innerExpr = restOfExp(constants, str.substring(1), [], "[");
|
|
117
|
+
const afterBracket = str.substring(1 + innerExpr.length + 1).trimStart();
|
|
118
|
+
key = lispify(constants, innerExpr, next);
|
|
119
|
+
if (afterBracket.length > 0 && afterBracket.char(0) === ":") value = lispify(constants, afterBracket.substring(1));
|
|
120
|
+
else if (afterBracket.length > 0 && afterBracket.char(0) === "(") value = lispify(constants, new require_CodeString.CodeString("function" + afterBracket.toString()));
|
|
121
|
+
else throw new SyntaxError("Unexpected token in computed property");
|
|
122
|
+
return createLisp({
|
|
123
|
+
op: require_types.LispType.KeyVal,
|
|
124
|
+
a: key,
|
|
125
|
+
b: value
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
funcFound = expectTypes.expFunction.types.function.exec("function " + str);
|
|
129
|
+
if (funcFound) {
|
|
130
|
+
key = funcFound[3].trimStart();
|
|
131
|
+
value = lispify(constants, new require_CodeString.CodeString("function " + str.toString().replace(key, "")));
|
|
132
|
+
} else {
|
|
133
|
+
const extract = restOfExp(constants, str, [/^:/]);
|
|
134
|
+
key = lispify(constants, extract, [...next, "spreadObject"]);
|
|
135
|
+
if (require_ExecContext.isLisp(key) && key[0] === require_types.LispType.SpreadObject) value = NullLisp;
|
|
136
|
+
else {
|
|
137
|
+
if (key[0] === require_types.LispType.Prop) key = key[2];
|
|
138
|
+
if (str.length > extract.length && str.char(extract.length) === ":") value = lispify(constants, str.substring(extract.length + 1));
|
|
139
|
+
else value = lispify(constants, extract, next);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return createLisp({
|
|
143
|
+
op: require_types.LispType.KeyVal,
|
|
144
|
+
a: key,
|
|
145
|
+
b: value
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
const lisptype = type === "arrayProp" ? res[1] ? require_types.LispType.PropOptional : require_types.LispType.Prop : type === "call" ? res[1] ? require_types.LispType.CallOptional : require_types.LispType.Call : typesCreate[type];
|
|
151
|
+
const currentTree = createLisp({
|
|
152
|
+
op: lisptype,
|
|
153
|
+
a: ctx.lispTree,
|
|
154
|
+
b: l
|
|
155
|
+
});
|
|
156
|
+
if (lisptype === require_types.LispType.Group || lisptype === require_types.LispType.CreateArray || lisptype === require_types.LispType.CreateObject) currentTree.source = part.substring(start, i).toString();
|
|
157
|
+
ctx.lispTree = lispify(constants, part.substring(i + 1), expectTypes[expect].next, currentTree, false, ctx);
|
|
158
|
+
});
|
|
159
|
+
setLispType(["dot", "prop"], (ctx) => {
|
|
160
|
+
const { constants, type, part, res, expect } = ctx;
|
|
161
|
+
let prop = res[0];
|
|
162
|
+
let index = res[0].length;
|
|
163
|
+
let op = "prop";
|
|
164
|
+
if (type === "dot") {
|
|
165
|
+
if (res[1]) op = "?prop";
|
|
166
|
+
const matches = part.substring(res[0].length).toString().match(expectTypes.prop.types.prop);
|
|
167
|
+
if (matches && matches.length) {
|
|
168
|
+
prop = matches[0];
|
|
169
|
+
index = prop.length + res[0].length;
|
|
170
|
+
} else throw new SyntaxError("Hanging dot");
|
|
171
|
+
} else if (require_types.reservedWords.has(prop) && prop !== "this") throw new SyntaxError(`Unexpected token '${prop}'`);
|
|
172
|
+
ctx.lispTree = lispify(constants, part.substring(index), expectTypes[expect].next, createLisp({
|
|
173
|
+
op: typesCreate[op],
|
|
174
|
+
a: ctx.lispTree,
|
|
175
|
+
b: prop
|
|
176
|
+
}), false, ctx);
|
|
177
|
+
});
|
|
178
|
+
setLispType(["spreadArray", "spreadObject"], (ctx) => {
|
|
179
|
+
const { constants, type, part, res, expect } = ctx;
|
|
180
|
+
ctx.lispTree = createLisp({
|
|
181
|
+
op: type === "spreadArray" ? require_types.LispType.SpreadArray : require_types.LispType.SpreadObject,
|
|
182
|
+
a: require_types.LispType.None,
|
|
183
|
+
b: lispify(constants, part.substring(res[0].length), expectTypes[expect].next)
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
exports.registerStructureLispTypes = registerStructureLispTypes;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const require_types = require("../../utils/types.js");
|
|
2
|
+
require("../../utils/index.js");
|
|
3
|
+
//#region src/parser/lispTypes/values.ts
|
|
4
|
+
function registerValueLispTypes({ createLisp, expectTypes, lispify, lispifyExpr, restOfExp, semiColon, setLispType }) {
|
|
5
|
+
setLispType(["return", "throw"], (ctx) => {
|
|
6
|
+
const { constants, type, part, res } = ctx;
|
|
7
|
+
const expr = part.substring(res[0].length);
|
|
8
|
+
if (type === "throw" && !expr.trimStart().length) throw new SyntaxError("Unexpected end of expression");
|
|
9
|
+
ctx.lispTree = createLisp({
|
|
10
|
+
op: type === "return" ? require_types.LispType.Return : require_types.LispType.Throw,
|
|
11
|
+
a: require_types.LispType.None,
|
|
12
|
+
b: lispifyExpr(constants, expr, void 0, ctx)
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
setLispType([
|
|
16
|
+
"number",
|
|
17
|
+
"boolean",
|
|
18
|
+
"null",
|
|
19
|
+
"und",
|
|
20
|
+
"NaN",
|
|
21
|
+
"Infinity"
|
|
22
|
+
], (ctx) => {
|
|
23
|
+
const { constants, type, part, res, expect } = ctx;
|
|
24
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next, createLisp({
|
|
25
|
+
op: type === "number" ? res[12] ? require_types.LispType.BigInt : require_types.LispType.Number : require_types.LispType.GlobalSymbol,
|
|
26
|
+
a: require_types.LispType.None,
|
|
27
|
+
b: res[12] ? res[1] : res[0]
|
|
28
|
+
}), false, ctx);
|
|
29
|
+
});
|
|
30
|
+
setLispType([
|
|
31
|
+
"string",
|
|
32
|
+
"literal",
|
|
33
|
+
"regex"
|
|
34
|
+
], (ctx) => {
|
|
35
|
+
const { constants, type, part, res, expect } = ctx;
|
|
36
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length), expectTypes[expect].next, createLisp({
|
|
37
|
+
op: type === "string" ? require_types.LispType.StringIndex : type === "literal" ? require_types.LispType.LiteralIndex : require_types.LispType.RegexIndex,
|
|
38
|
+
a: require_types.LispType.None,
|
|
39
|
+
b: res[1]
|
|
40
|
+
}), false, ctx);
|
|
41
|
+
});
|
|
42
|
+
setLispType(["void", "await"], (ctx) => {
|
|
43
|
+
const { constants, type, part, res, expect } = ctx;
|
|
44
|
+
const extract = restOfExp(constants, part.substring(res[0].length), [/^([^\s.?\w$]|\?[^.])/]);
|
|
45
|
+
if (!extract.trimStart().length) throw new SyntaxError("Unexpected end of expression");
|
|
46
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length + extract.length), expectTypes[expect].next, createLisp({
|
|
47
|
+
op: type === "void" ? require_types.LispType.Void : require_types.LispType.Await,
|
|
48
|
+
a: lispify(constants, extract),
|
|
49
|
+
b: require_types.LispType.None
|
|
50
|
+
}), false, ctx);
|
|
51
|
+
});
|
|
52
|
+
setLispType(["yield"], (ctx) => {
|
|
53
|
+
const { constants, part, res, expect, generatorDepth } = ctx;
|
|
54
|
+
if (generatorDepth === 0) throw new SyntaxError("Unexpected token");
|
|
55
|
+
const isDelegate = res[0].trimEnd().endsWith("*");
|
|
56
|
+
const extract = restOfExp(constants, part.substring(res[0].length), [/^([^\s.?\w$]|\?[^.])/]);
|
|
57
|
+
if (isDelegate && !extract.trimStart().length) throw new SyntaxError("Unexpected end of expression");
|
|
58
|
+
ctx.lispTree = lispify(constants, part.substring(res[0].length + extract.length), expectTypes[expect].next, createLisp({
|
|
59
|
+
op: isDelegate ? require_types.LispType.YieldDelegate : require_types.LispType.Yield,
|
|
60
|
+
a: lispify(constants, extract),
|
|
61
|
+
b: require_types.LispType.None
|
|
62
|
+
}), false, ctx);
|
|
63
|
+
});
|
|
64
|
+
setLispType(["new"], (ctx) => {
|
|
65
|
+
const { constants, part, res } = ctx;
|
|
66
|
+
let i = res[0].length;
|
|
67
|
+
const obj = restOfExp(constants, part.substring(i), [], void 0, "(");
|
|
68
|
+
if (!obj.trimStart().length) throw new SyntaxError("Unexpected end of expression");
|
|
69
|
+
i += obj.length + 1;
|
|
70
|
+
const args = [];
|
|
71
|
+
if (part.char(i - 1) === "(") {
|
|
72
|
+
const argsString = restOfExp(constants, part.substring(i), [], "(");
|
|
73
|
+
i += argsString.length + 1;
|
|
74
|
+
let found;
|
|
75
|
+
let j = 0;
|
|
76
|
+
while ((found = restOfExp(constants, argsString.substring(j), [/^,/])).length) {
|
|
77
|
+
j += found.length + 1;
|
|
78
|
+
args.push(found.trim());
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
ctx.lispTree = lispify(constants, part.substring(i), expectTypes.expEdge.next, createLisp({
|
|
82
|
+
op: require_types.LispType.New,
|
|
83
|
+
a: lispify(constants, obj, expectTypes.initialize.next),
|
|
84
|
+
b: args.map((arg) => lispify(constants, arg, expectTypes.initialize.next))
|
|
85
|
+
}), false, ctx);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.registerValueLispTypes = registerValueLispTypes;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CodeString } from '../utils';
|
|
2
|
+
import { IConstants, IExecutionTree, IRegEx, Lisp, LispCallback, LispDepthCtx, Return } from './lisp';
|
|
3
|
+
export declare class ParseError extends Error {
|
|
4
|
+
code: string;
|
|
5
|
+
constructor(message: string, code: string);
|
|
6
|
+
}
|
|
7
|
+
export declare const expectTypes: Record<string, {
|
|
8
|
+
types: Record<string, RegExp>;
|
|
9
|
+
next: string[];
|
|
10
|
+
}>;
|
|
11
|
+
export declare function testMultiple(str: string, tests: RegExp[]): RegExpExecArray | null;
|
|
12
|
+
export interface restDetails {
|
|
13
|
+
oneliner?: boolean;
|
|
14
|
+
words?: string[];
|
|
15
|
+
lastWord?: string;
|
|
16
|
+
lastAnyWord?: string;
|
|
17
|
+
regRes?: RegExpExecArray;
|
|
18
|
+
bodyContentAfterKeyword?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function restOfExp(constants: IConstants, part: CodeString, tests?: RegExp[], quote?: string, firstOpening?: string, closingsTests?: RegExp[], details?: restDetails, depth?: number): CodeString;
|
|
21
|
+
export declare namespace restOfExp {
|
|
22
|
+
var next: string[];
|
|
23
|
+
}
|
|
24
|
+
export declare const setLispType: <T extends readonly string[]>(types: T, fn: LispCallback<T[number]>) => void;
|
|
25
|
+
export declare function lispifyReturnExpr(constants: IConstants, str: CodeString): Return;
|
|
26
|
+
export declare function lispifyBlock(str: CodeString, constants: IConstants, expression?: boolean, depthCtx?: LispDepthCtx): Lisp[];
|
|
27
|
+
export declare function lispifyFunction(str: CodeString, constants: IConstants, expression?: boolean, depthCtx?: LispDepthCtx): Lisp[];
|
|
28
|
+
export declare function insertSemicolons(constants: IConstants, str: CodeString): CodeString;
|
|
29
|
+
export declare function checkRegex(str: string): IRegEx | null;
|
|
30
|
+
export declare function extractConstants(constants: IConstants, str: string, currentEnclosure?: string, depth?: number): {
|
|
31
|
+
str: string;
|
|
32
|
+
length: number;
|
|
33
|
+
};
|
|
34
|
+
export default function parse(code: string, eager?: boolean, expression?: boolean, maxParserRecursionDepth?: number): IExecutionTree;
|