greybel-interpreter 1.3.7 → 1.3.8
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/.editorconfig +14 -14
- package/.eslintrc +47 -47
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +109 -109
- package/dist/context.js +383 -382
- package/dist/cps.d.ts +14 -14
- package/dist/cps.js +213 -213
- package/dist/handler/error.d.ts +6 -6
- package/dist/handler/error.js +35 -35
- package/dist/handler/output.d.ts +18 -18
- package/dist/handler/output.js +52 -52
- package/dist/handler/resource.d.ts +12 -12
- package/dist/handler/resource.js +51 -51
- package/dist/handler-container.d.ts +14 -14
- package/dist/handler-container.js +16 -16
- package/dist/index.d.ts +45 -45
- package/dist/index.js +131 -131
- package/dist/interpreter.d.ts +41 -41
- package/dist/interpreter.js +312 -312
- package/dist/intrinsics-container.d.ts +7 -7
- package/dist/intrinsics-container.js +19 -19
- package/dist/operations/assign.d.ts +13 -13
- package/dist/operations/assign.js +111 -111
- package/dist/operations/block.d.ts +12 -12
- package/dist/operations/block.js +108 -108
- package/dist/operations/break.d.ts +10 -10
- package/dist/operations/break.js +41 -41
- package/dist/operations/call.d.ts +13 -13
- package/dist/operations/call.js +124 -124
- package/dist/operations/chunk.d.ts +12 -12
- package/dist/operations/chunk.js +85 -85
- package/dist/operations/continue.d.ts +10 -10
- package/dist/operations/continue.js +41 -41
- package/dist/operations/debugger-statement.d.ts +10 -10
- package/dist/operations/debugger-statement.js +39 -39
- package/dist/operations/evaluate.d.ts +41 -39
- package/dist/operations/evaluate.js +433 -367
- package/dist/operations/for.d.ts +14 -14
- package/dist/operations/for.js +152 -152
- package/dist/operations/function-reference.d.ts +12 -12
- package/dist/operations/function-reference.js +103 -103
- package/dist/operations/function.d.ts +14 -14
- package/dist/operations/function.js +200 -200
- package/dist/operations/if-statement.d.ts +19 -19
- package/dist/operations/if-statement.js +181 -181
- package/dist/operations/import.d.ts +17 -17
- package/dist/operations/import.js +119 -119
- package/dist/operations/include.d.ts +13 -13
- package/dist/operations/include.js +95 -95
- package/dist/operations/list.d.ts +11 -11
- package/dist/operations/list.js +111 -111
- package/dist/operations/literal.d.ts +11 -11
- package/dist/operations/literal.js +58 -58
- package/dist/operations/map.d.ts +11 -11
- package/dist/operations/map.js +171 -171
- package/dist/operations/negated-binary.d.ts +11 -11
- package/dist/operations/negated-binary.js +109 -109
- package/dist/operations/new-instance.d.ts +11 -11
- package/dist/operations/new-instance.js +100 -100
- package/dist/operations/noop.d.ts +9 -9
- package/dist/operations/noop.js +36 -36
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -13
- package/dist/operations/operation.js +11 -11
- package/dist/operations/reference.d.ts +9 -9
- package/dist/operations/reference.js +37 -37
- package/dist/operations/resolve.d.ts +38 -38
- package/dist/operations/resolve.js +330 -330
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +107 -107
- package/dist/operations/while.d.ts +13 -13
- package/dist/operations/while.js +136 -136
- package/dist/types/boolean.d.ts +11 -11
- package/dist/types/boolean.js +46 -46
- package/dist/types/default.d.ts +11 -11
- package/dist/types/default.js +20 -20
- package/dist/types/function.d.ts +32 -32
- package/dist/types/function.js +174 -174
- package/dist/types/generics.d.ts +18 -18
- package/dist/types/generics.js +40 -40
- package/dist/types/interface.d.ts +23 -23
- package/dist/types/interface.js +103 -103
- package/dist/types/list.d.ts +31 -31
- package/dist/types/list.js +209 -209
- package/dist/types/map.d.ts +37 -37
- package/dist/types/map.js +366 -366
- package/dist/types/nil.d.ts +10 -10
- package/dist/types/nil.js +46 -46
- package/dist/types/number.d.ts +11 -11
- package/dist/types/number.js +46 -46
- package/dist/types/string.d.ts +33 -33
- package/dist/types/string.js +145 -145
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +62 -62
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +59 -59
- package/package.json +58 -58
|
@@ -1,330 +1,330 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.ResolveResult = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.SliceSegment = void 0;
|
|
58
|
-
var greyscript_core_1 = require("greyscript-core");
|
|
59
|
-
var default_1 = __importDefault(require("../types/default"));
|
|
60
|
-
var function_1 = __importDefault(require("../types/function"));
|
|
61
|
-
var generics_1 = require("../types/generics");
|
|
62
|
-
var list_1 = __importDefault(require("../types/list"));
|
|
63
|
-
var string_1 = __importDefault(require("../types/string"));
|
|
64
|
-
var path_1 = __importDefault(require("../utils/path"));
|
|
65
|
-
var operation_1 = __importDefault(require("./operation"));
|
|
66
|
-
var SliceSegment = /** @class */ (function () {
|
|
67
|
-
function SliceSegment(left, right) {
|
|
68
|
-
this.left = left;
|
|
69
|
-
this.right = right;
|
|
70
|
-
}
|
|
71
|
-
return SliceSegment;
|
|
72
|
-
}());
|
|
73
|
-
exports.SliceSegment = SliceSegment;
|
|
74
|
-
var IdentifierSegment = /** @class */ (function () {
|
|
75
|
-
function IdentifierSegment(value) {
|
|
76
|
-
this.value = value;
|
|
77
|
-
}
|
|
78
|
-
return IdentifierSegment;
|
|
79
|
-
}());
|
|
80
|
-
exports.IdentifierSegment = IdentifierSegment;
|
|
81
|
-
var IndexSegment = /** @class */ (function () {
|
|
82
|
-
function IndexSegment(op) {
|
|
83
|
-
this.op = op;
|
|
84
|
-
}
|
|
85
|
-
return IndexSegment;
|
|
86
|
-
}());
|
|
87
|
-
exports.IndexSegment = IndexSegment;
|
|
88
|
-
var OperationSegment = /** @class */ (function () {
|
|
89
|
-
function OperationSegment(op) {
|
|
90
|
-
this.op = op;
|
|
91
|
-
}
|
|
92
|
-
return OperationSegment;
|
|
93
|
-
}());
|
|
94
|
-
exports.OperationSegment = OperationSegment;
|
|
95
|
-
var ResolveResult = /** @class */ (function () {
|
|
96
|
-
function ResolveResult(path, handle) {
|
|
97
|
-
this.path = path;
|
|
98
|
-
this.handle = handle;
|
|
99
|
-
}
|
|
100
|
-
return ResolveResult;
|
|
101
|
-
}());
|
|
102
|
-
exports.ResolveResult = ResolveResult;
|
|
103
|
-
var Resolve = /** @class */ (function (_super) {
|
|
104
|
-
__extends(Resolve, _super);
|
|
105
|
-
function Resolve(item, target) {
|
|
106
|
-
var _this = _super.call(this, null, target) || this;
|
|
107
|
-
_this.item = item;
|
|
108
|
-
return _this;
|
|
109
|
-
}
|
|
110
|
-
Resolve.prototype.buildProcessor = function (node, visit) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
-
var _a, memberExpr, indexExpr, sliceExpr, left, right, sliceSegment, indexSegment, _b, identifier, identifierSegment, opSegment, _c;
|
|
113
|
-
return __generator(this, function (_d) {
|
|
114
|
-
switch (_d.label) {
|
|
115
|
-
case 0:
|
|
116
|
-
_a = node.type;
|
|
117
|
-
switch (_a) {
|
|
118
|
-
case greyscript_core_1.ASTType.MemberExpression: return [3 /*break*/, 1];
|
|
119
|
-
case greyscript_core_1.ASTType.IndexExpression: return [3 /*break*/, 4];
|
|
120
|
-
case greyscript_core_1.ASTType.Identifier: return [3 /*break*/, 11];
|
|
121
|
-
}
|
|
122
|
-
return [3 /*break*/, 12];
|
|
123
|
-
case 1:
|
|
124
|
-
memberExpr = node;
|
|
125
|
-
return [4 /*yield*/, this.buildProcessor(memberExpr.base, visit)];
|
|
126
|
-
case 2:
|
|
127
|
-
_d.sent();
|
|
128
|
-
return [4 /*yield*/, this.buildProcessor(memberExpr.identifier, visit)];
|
|
129
|
-
case 3:
|
|
130
|
-
_d.sent();
|
|
131
|
-
return [3 /*break*/, 14];
|
|
132
|
-
case 4:
|
|
133
|
-
indexExpr = node;
|
|
134
|
-
return [4 /*yield*/, this.buildProcessor(indexExpr.base, visit)];
|
|
135
|
-
case 5:
|
|
136
|
-
_d.sent();
|
|
137
|
-
if (!(indexExpr.index.type === greyscript_core_1.ASTType.SliceExpression)) return [3 /*break*/, 8];
|
|
138
|
-
sliceExpr = indexExpr.index;
|
|
139
|
-
return [4 /*yield*/, visit(sliceExpr.left)];
|
|
140
|
-
case 6:
|
|
141
|
-
left = _d.sent();
|
|
142
|
-
return [4 /*yield*/, visit(sliceExpr.right)];
|
|
143
|
-
case 7:
|
|
144
|
-
right = _d.sent();
|
|
145
|
-
sliceSegment = new SliceSegment(left, right);
|
|
146
|
-
this.path.push(sliceSegment);
|
|
147
|
-
return [3 /*break*/, 10];
|
|
148
|
-
case 8:
|
|
149
|
-
_b = IndexSegment.bind;
|
|
150
|
-
return [4 /*yield*/, visit(indexExpr.index)];
|
|
151
|
-
case 9:
|
|
152
|
-
indexSegment = new (_b.apply(IndexSegment, [void 0, _d.sent()]))();
|
|
153
|
-
this.path.push(indexSegment);
|
|
154
|
-
_d.label = 10;
|
|
155
|
-
case 10: return [3 /*break*/, 14];
|
|
156
|
-
case 11:
|
|
157
|
-
{
|
|
158
|
-
identifier = node;
|
|
159
|
-
identifierSegment = new IdentifierSegment(identifier.name);
|
|
160
|
-
this.path.push(identifierSegment);
|
|
161
|
-
return [3 /*break*/, 14];
|
|
162
|
-
}
|
|
163
|
-
_d.label = 12;
|
|
164
|
-
case 12:
|
|
165
|
-
_c = OperationSegment.bind;
|
|
166
|
-
return [4 /*yield*/, visit(node)];
|
|
167
|
-
case 13:
|
|
168
|
-
opSegment = new (_c.apply(OperationSegment, [void 0, _d.sent()]))();
|
|
169
|
-
this.path.push(opSegment);
|
|
170
|
-
return [3 /*break*/, 14];
|
|
171
|
-
case 14: return [2 /*return*/];
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
Resolve.prototype.build = function (visit) {
|
|
177
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
-
return __generator(this, function (_a) {
|
|
179
|
-
switch (_a.label) {
|
|
180
|
-
case 0:
|
|
181
|
-
this.path = [];
|
|
182
|
-
return [4 /*yield*/, this.buildProcessor(this.item, visit)];
|
|
183
|
-
case 1:
|
|
184
|
-
_a.sent();
|
|
185
|
-
this.last = this.path[this.path.length - 1];
|
|
186
|
-
return [2 /*return*/, this];
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
};
|
|
191
|
-
Resolve.prototype.getResult = function (ctx) {
|
|
192
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
-
var traversedPath, handle, maxIndex, lastIndex, index, current, opSegment, identifierSegment, previous, customValueCtx, indexSegment, indexValue, customValueCtx, sliceSegment, left, right;
|
|
194
|
-
return __generator(this, function (_a) {
|
|
195
|
-
switch (_a.label) {
|
|
196
|
-
case 0:
|
|
197
|
-
traversedPath = new path_1.default();
|
|
198
|
-
handle = default_1.default.Void;
|
|
199
|
-
maxIndex = this.path.length;
|
|
200
|
-
lastIndex = maxIndex - 1;
|
|
201
|
-
index = 0;
|
|
202
|
-
_a.label = 1;
|
|
203
|
-
case 1:
|
|
204
|
-
if (!(index < maxIndex)) return [3 /*break*/, 12];
|
|
205
|
-
current = this.path[index];
|
|
206
|
-
if (!(current instanceof OperationSegment)) return [3 /*break*/, 3];
|
|
207
|
-
opSegment = current;
|
|
208
|
-
return [4 /*yield*/, opSegment.op.handle(ctx)];
|
|
209
|
-
case 2:
|
|
210
|
-
handle = _a.sent();
|
|
211
|
-
return [3 /*break*/, 11];
|
|
212
|
-
case 3:
|
|
213
|
-
if (!(current instanceof IdentifierSegment)) return [3 /*break*/, 6];
|
|
214
|
-
identifierSegment = current;
|
|
215
|
-
traversedPath.add(new string_1.default(identifierSegment.value));
|
|
216
|
-
if (index === lastIndex) {
|
|
217
|
-
return [3 /*break*/, 12];
|
|
218
|
-
}
|
|
219
|
-
previous = handle;
|
|
220
|
-
if (handle !== default_1.default.Void) {
|
|
221
|
-
if (handle instanceof generics_1.CustomValueWithIntrinsics) {
|
|
222
|
-
customValueCtx = handle;
|
|
223
|
-
handle = customValueCtx.get(traversedPath);
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
throw new Error('Handle has no properties.');
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
handle = ctx.get(traversedPath);
|
|
231
|
-
}
|
|
232
|
-
if (!(handle instanceof function_1.default)) return [3 /*break*/, 5];
|
|
233
|
-
return [4 /*yield*/, handle.run(previous || default_1.default.Void, [], ctx)];
|
|
234
|
-
case 4:
|
|
235
|
-
handle = _a.sent();
|
|
236
|
-
_a.label = 5;
|
|
237
|
-
case 5:
|
|
238
|
-
traversedPath = new path_1.default();
|
|
239
|
-
return [3 /*break*/, 11];
|
|
240
|
-
case 6:
|
|
241
|
-
if (!(current instanceof IndexSegment)) return [3 /*break*/, 8];
|
|
242
|
-
indexSegment = current;
|
|
243
|
-
return [4 /*yield*/, indexSegment.op.handle(ctx)];
|
|
244
|
-
case 7:
|
|
245
|
-
indexValue = _a.sent();
|
|
246
|
-
traversedPath.add(indexValue);
|
|
247
|
-
if (index === lastIndex) {
|
|
248
|
-
return [3 /*break*/, 12];
|
|
249
|
-
}
|
|
250
|
-
if (handle !== default_1.default.Void) {
|
|
251
|
-
if (handle instanceof generics_1.CustomValueWithIntrinsics) {
|
|
252
|
-
customValueCtx = handle;
|
|
253
|
-
handle = customValueCtx.get(traversedPath);
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
throw new Error('Handle has no properties.');
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
handle = ctx.get(traversedPath);
|
|
261
|
-
}
|
|
262
|
-
traversedPath = new path_1.default();
|
|
263
|
-
return [3 /*break*/, 11];
|
|
264
|
-
case 8:
|
|
265
|
-
if (!(current instanceof SliceSegment)) return [3 /*break*/, 11];
|
|
266
|
-
sliceSegment = current;
|
|
267
|
-
return [4 /*yield*/, sliceSegment.left.handle(ctx)];
|
|
268
|
-
case 9:
|
|
269
|
-
left = _a.sent();
|
|
270
|
-
return [4 /*yield*/, sliceSegment.right.handle(ctx)];
|
|
271
|
-
case 10:
|
|
272
|
-
right = _a.sent();
|
|
273
|
-
if (handle instanceof list_1.default || handle instanceof string_1.default) {
|
|
274
|
-
handle = handle.slice(left, right);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
throw new Error("Unexpected slice attempt. ".concat(handle.getCustomType(), " does not seem to support slicing."));
|
|
278
|
-
}
|
|
279
|
-
_a.label = 11;
|
|
280
|
-
case 11:
|
|
281
|
-
index++;
|
|
282
|
-
return [3 /*break*/, 1];
|
|
283
|
-
case 12: return [2 /*return*/, new ResolveResult(traversedPath, handle)];
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
Resolve.prototype.handle = function (ctx, result, autoCall) {
|
|
289
|
-
if (result === void 0) { result = null; }
|
|
290
|
-
if (autoCall === void 0) { autoCall = true; }
|
|
291
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
-
var customValueCtx, child, handle;
|
|
293
|
-
return __generator(this, function (_a) {
|
|
294
|
-
switch (_a.label) {
|
|
295
|
-
case 0:
|
|
296
|
-
if (!(result === null)) return [3 /*break*/, 2];
|
|
297
|
-
return [4 /*yield*/, this.getResult(ctx)];
|
|
298
|
-
case 1:
|
|
299
|
-
result = _a.sent();
|
|
300
|
-
_a.label = 2;
|
|
301
|
-
case 2:
|
|
302
|
-
if (result.handle !== default_1.default.Void) {
|
|
303
|
-
if (result.path.count() === 0) {
|
|
304
|
-
if (autoCall && result.handle instanceof function_1.default) {
|
|
305
|
-
return [2 /*return*/, result.handle.run(default_1.default.Void, [], ctx)];
|
|
306
|
-
}
|
|
307
|
-
return [2 /*return*/, result.handle];
|
|
308
|
-
}
|
|
309
|
-
customValueCtx = result.handle;
|
|
310
|
-
child = customValueCtx.get(result.path);
|
|
311
|
-
if (autoCall &&
|
|
312
|
-
child instanceof function_1.default &&
|
|
313
|
-
// support index bug in greyscript
|
|
314
|
-
!(this.last instanceof IndexSegment)) {
|
|
315
|
-
return [2 /*return*/, child.run(customValueCtx, [], ctx)];
|
|
316
|
-
}
|
|
317
|
-
return [2 /*return*/, child];
|
|
318
|
-
}
|
|
319
|
-
handle = ctx.get(result.path);
|
|
320
|
-
if (autoCall && handle instanceof function_1.default) {
|
|
321
|
-
return [2 /*return*/, handle.run(default_1.default.Void, [], ctx)];
|
|
322
|
-
}
|
|
323
|
-
return [2 /*return*/, handle];
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
};
|
|
328
|
-
return Resolve;
|
|
329
|
-
}(operation_1.default));
|
|
330
|
-
exports.default = Resolve;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.ResolveResult = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.SliceSegment = void 0;
|
|
58
|
+
var greyscript_core_1 = require("greyscript-core");
|
|
59
|
+
var default_1 = __importDefault(require("../types/default"));
|
|
60
|
+
var function_1 = __importDefault(require("../types/function"));
|
|
61
|
+
var generics_1 = require("../types/generics");
|
|
62
|
+
var list_1 = __importDefault(require("../types/list"));
|
|
63
|
+
var string_1 = __importDefault(require("../types/string"));
|
|
64
|
+
var path_1 = __importDefault(require("../utils/path"));
|
|
65
|
+
var operation_1 = __importDefault(require("./operation"));
|
|
66
|
+
var SliceSegment = /** @class */ (function () {
|
|
67
|
+
function SliceSegment(left, right) {
|
|
68
|
+
this.left = left;
|
|
69
|
+
this.right = right;
|
|
70
|
+
}
|
|
71
|
+
return SliceSegment;
|
|
72
|
+
}());
|
|
73
|
+
exports.SliceSegment = SliceSegment;
|
|
74
|
+
var IdentifierSegment = /** @class */ (function () {
|
|
75
|
+
function IdentifierSegment(value) {
|
|
76
|
+
this.value = value;
|
|
77
|
+
}
|
|
78
|
+
return IdentifierSegment;
|
|
79
|
+
}());
|
|
80
|
+
exports.IdentifierSegment = IdentifierSegment;
|
|
81
|
+
var IndexSegment = /** @class */ (function () {
|
|
82
|
+
function IndexSegment(op) {
|
|
83
|
+
this.op = op;
|
|
84
|
+
}
|
|
85
|
+
return IndexSegment;
|
|
86
|
+
}());
|
|
87
|
+
exports.IndexSegment = IndexSegment;
|
|
88
|
+
var OperationSegment = /** @class */ (function () {
|
|
89
|
+
function OperationSegment(op) {
|
|
90
|
+
this.op = op;
|
|
91
|
+
}
|
|
92
|
+
return OperationSegment;
|
|
93
|
+
}());
|
|
94
|
+
exports.OperationSegment = OperationSegment;
|
|
95
|
+
var ResolveResult = /** @class */ (function () {
|
|
96
|
+
function ResolveResult(path, handle) {
|
|
97
|
+
this.path = path;
|
|
98
|
+
this.handle = handle;
|
|
99
|
+
}
|
|
100
|
+
return ResolveResult;
|
|
101
|
+
}());
|
|
102
|
+
exports.ResolveResult = ResolveResult;
|
|
103
|
+
var Resolve = /** @class */ (function (_super) {
|
|
104
|
+
__extends(Resolve, _super);
|
|
105
|
+
function Resolve(item, target) {
|
|
106
|
+
var _this = _super.call(this, null, target) || this;
|
|
107
|
+
_this.item = item;
|
|
108
|
+
return _this;
|
|
109
|
+
}
|
|
110
|
+
Resolve.prototype.buildProcessor = function (node, visit) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var _a, memberExpr, indexExpr, sliceExpr, left, right, sliceSegment, indexSegment, _b, identifier, identifierSegment, opSegment, _c;
|
|
113
|
+
return __generator(this, function (_d) {
|
|
114
|
+
switch (_d.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
_a = node.type;
|
|
117
|
+
switch (_a) {
|
|
118
|
+
case greyscript_core_1.ASTType.MemberExpression: return [3 /*break*/, 1];
|
|
119
|
+
case greyscript_core_1.ASTType.IndexExpression: return [3 /*break*/, 4];
|
|
120
|
+
case greyscript_core_1.ASTType.Identifier: return [3 /*break*/, 11];
|
|
121
|
+
}
|
|
122
|
+
return [3 /*break*/, 12];
|
|
123
|
+
case 1:
|
|
124
|
+
memberExpr = node;
|
|
125
|
+
return [4 /*yield*/, this.buildProcessor(memberExpr.base, visit)];
|
|
126
|
+
case 2:
|
|
127
|
+
_d.sent();
|
|
128
|
+
return [4 /*yield*/, this.buildProcessor(memberExpr.identifier, visit)];
|
|
129
|
+
case 3:
|
|
130
|
+
_d.sent();
|
|
131
|
+
return [3 /*break*/, 14];
|
|
132
|
+
case 4:
|
|
133
|
+
indexExpr = node;
|
|
134
|
+
return [4 /*yield*/, this.buildProcessor(indexExpr.base, visit)];
|
|
135
|
+
case 5:
|
|
136
|
+
_d.sent();
|
|
137
|
+
if (!(indexExpr.index.type === greyscript_core_1.ASTType.SliceExpression)) return [3 /*break*/, 8];
|
|
138
|
+
sliceExpr = indexExpr.index;
|
|
139
|
+
return [4 /*yield*/, visit(sliceExpr.left)];
|
|
140
|
+
case 6:
|
|
141
|
+
left = _d.sent();
|
|
142
|
+
return [4 /*yield*/, visit(sliceExpr.right)];
|
|
143
|
+
case 7:
|
|
144
|
+
right = _d.sent();
|
|
145
|
+
sliceSegment = new SliceSegment(left, right);
|
|
146
|
+
this.path.push(sliceSegment);
|
|
147
|
+
return [3 /*break*/, 10];
|
|
148
|
+
case 8:
|
|
149
|
+
_b = IndexSegment.bind;
|
|
150
|
+
return [4 /*yield*/, visit(indexExpr.index)];
|
|
151
|
+
case 9:
|
|
152
|
+
indexSegment = new (_b.apply(IndexSegment, [void 0, _d.sent()]))();
|
|
153
|
+
this.path.push(indexSegment);
|
|
154
|
+
_d.label = 10;
|
|
155
|
+
case 10: return [3 /*break*/, 14];
|
|
156
|
+
case 11:
|
|
157
|
+
{
|
|
158
|
+
identifier = node;
|
|
159
|
+
identifierSegment = new IdentifierSegment(identifier.name);
|
|
160
|
+
this.path.push(identifierSegment);
|
|
161
|
+
return [3 /*break*/, 14];
|
|
162
|
+
}
|
|
163
|
+
_d.label = 12;
|
|
164
|
+
case 12:
|
|
165
|
+
_c = OperationSegment.bind;
|
|
166
|
+
return [4 /*yield*/, visit(node)];
|
|
167
|
+
case 13:
|
|
168
|
+
opSegment = new (_c.apply(OperationSegment, [void 0, _d.sent()]))();
|
|
169
|
+
this.path.push(opSegment);
|
|
170
|
+
return [3 /*break*/, 14];
|
|
171
|
+
case 14: return [2 /*return*/];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
Resolve.prototype.build = function (visit) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
switch (_a.label) {
|
|
180
|
+
case 0:
|
|
181
|
+
this.path = [];
|
|
182
|
+
return [4 /*yield*/, this.buildProcessor(this.item, visit)];
|
|
183
|
+
case 1:
|
|
184
|
+
_a.sent();
|
|
185
|
+
this.last = this.path[this.path.length - 1];
|
|
186
|
+
return [2 /*return*/, this];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
Resolve.prototype.getResult = function (ctx) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var traversedPath, handle, maxIndex, lastIndex, index, current, opSegment, identifierSegment, previous, customValueCtx, indexSegment, indexValue, customValueCtx, sliceSegment, left, right;
|
|
194
|
+
return __generator(this, function (_a) {
|
|
195
|
+
switch (_a.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
traversedPath = new path_1.default();
|
|
198
|
+
handle = default_1.default.Void;
|
|
199
|
+
maxIndex = this.path.length;
|
|
200
|
+
lastIndex = maxIndex - 1;
|
|
201
|
+
index = 0;
|
|
202
|
+
_a.label = 1;
|
|
203
|
+
case 1:
|
|
204
|
+
if (!(index < maxIndex)) return [3 /*break*/, 12];
|
|
205
|
+
current = this.path[index];
|
|
206
|
+
if (!(current instanceof OperationSegment)) return [3 /*break*/, 3];
|
|
207
|
+
opSegment = current;
|
|
208
|
+
return [4 /*yield*/, opSegment.op.handle(ctx)];
|
|
209
|
+
case 2:
|
|
210
|
+
handle = _a.sent();
|
|
211
|
+
return [3 /*break*/, 11];
|
|
212
|
+
case 3:
|
|
213
|
+
if (!(current instanceof IdentifierSegment)) return [3 /*break*/, 6];
|
|
214
|
+
identifierSegment = current;
|
|
215
|
+
traversedPath.add(new string_1.default(identifierSegment.value));
|
|
216
|
+
if (index === lastIndex) {
|
|
217
|
+
return [3 /*break*/, 12];
|
|
218
|
+
}
|
|
219
|
+
previous = handle;
|
|
220
|
+
if (handle !== default_1.default.Void) {
|
|
221
|
+
if (handle instanceof generics_1.CustomValueWithIntrinsics) {
|
|
222
|
+
customValueCtx = handle;
|
|
223
|
+
handle = customValueCtx.get(traversedPath);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
throw new Error('Handle has no properties.');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
handle = ctx.get(traversedPath);
|
|
231
|
+
}
|
|
232
|
+
if (!(handle instanceof function_1.default)) return [3 /*break*/, 5];
|
|
233
|
+
return [4 /*yield*/, handle.run(previous || default_1.default.Void, [], ctx)];
|
|
234
|
+
case 4:
|
|
235
|
+
handle = _a.sent();
|
|
236
|
+
_a.label = 5;
|
|
237
|
+
case 5:
|
|
238
|
+
traversedPath = new path_1.default();
|
|
239
|
+
return [3 /*break*/, 11];
|
|
240
|
+
case 6:
|
|
241
|
+
if (!(current instanceof IndexSegment)) return [3 /*break*/, 8];
|
|
242
|
+
indexSegment = current;
|
|
243
|
+
return [4 /*yield*/, indexSegment.op.handle(ctx)];
|
|
244
|
+
case 7:
|
|
245
|
+
indexValue = _a.sent();
|
|
246
|
+
traversedPath.add(indexValue);
|
|
247
|
+
if (index === lastIndex) {
|
|
248
|
+
return [3 /*break*/, 12];
|
|
249
|
+
}
|
|
250
|
+
if (handle !== default_1.default.Void) {
|
|
251
|
+
if (handle instanceof generics_1.CustomValueWithIntrinsics) {
|
|
252
|
+
customValueCtx = handle;
|
|
253
|
+
handle = customValueCtx.get(traversedPath);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
throw new Error('Handle has no properties.');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
handle = ctx.get(traversedPath);
|
|
261
|
+
}
|
|
262
|
+
traversedPath = new path_1.default();
|
|
263
|
+
return [3 /*break*/, 11];
|
|
264
|
+
case 8:
|
|
265
|
+
if (!(current instanceof SliceSegment)) return [3 /*break*/, 11];
|
|
266
|
+
sliceSegment = current;
|
|
267
|
+
return [4 /*yield*/, sliceSegment.left.handle(ctx)];
|
|
268
|
+
case 9:
|
|
269
|
+
left = _a.sent();
|
|
270
|
+
return [4 /*yield*/, sliceSegment.right.handle(ctx)];
|
|
271
|
+
case 10:
|
|
272
|
+
right = _a.sent();
|
|
273
|
+
if (handle instanceof list_1.default || handle instanceof string_1.default) {
|
|
274
|
+
handle = handle.slice(left, right);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
throw new Error("Unexpected slice attempt. ".concat(handle.getCustomType(), " does not seem to support slicing."));
|
|
278
|
+
}
|
|
279
|
+
_a.label = 11;
|
|
280
|
+
case 11:
|
|
281
|
+
index++;
|
|
282
|
+
return [3 /*break*/, 1];
|
|
283
|
+
case 12: return [2 /*return*/, new ResolveResult(traversedPath, handle)];
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
Resolve.prototype.handle = function (ctx, result, autoCall) {
|
|
289
|
+
if (result === void 0) { result = null; }
|
|
290
|
+
if (autoCall === void 0) { autoCall = true; }
|
|
291
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
+
var customValueCtx, child, handle;
|
|
293
|
+
return __generator(this, function (_a) {
|
|
294
|
+
switch (_a.label) {
|
|
295
|
+
case 0:
|
|
296
|
+
if (!(result === null)) return [3 /*break*/, 2];
|
|
297
|
+
return [4 /*yield*/, this.getResult(ctx)];
|
|
298
|
+
case 1:
|
|
299
|
+
result = _a.sent();
|
|
300
|
+
_a.label = 2;
|
|
301
|
+
case 2:
|
|
302
|
+
if (result.handle !== default_1.default.Void) {
|
|
303
|
+
if (result.path.count() === 0) {
|
|
304
|
+
if (autoCall && result.handle instanceof function_1.default) {
|
|
305
|
+
return [2 /*return*/, result.handle.run(default_1.default.Void, [], ctx)];
|
|
306
|
+
}
|
|
307
|
+
return [2 /*return*/, result.handle];
|
|
308
|
+
}
|
|
309
|
+
customValueCtx = result.handle;
|
|
310
|
+
child = customValueCtx.get(result.path);
|
|
311
|
+
if (autoCall &&
|
|
312
|
+
child instanceof function_1.default &&
|
|
313
|
+
// support index bug in greyscript
|
|
314
|
+
!(this.last instanceof IndexSegment)) {
|
|
315
|
+
return [2 /*return*/, child.run(customValueCtx, [], ctx)];
|
|
316
|
+
}
|
|
317
|
+
return [2 /*return*/, child];
|
|
318
|
+
}
|
|
319
|
+
handle = ctx.get(result.path);
|
|
320
|
+
if (autoCall && handle instanceof function_1.default) {
|
|
321
|
+
return [2 /*return*/, handle.run(default_1.default.Void, [], ctx)];
|
|
322
|
+
}
|
|
323
|
+
return [2 /*return*/, handle];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
return Resolve;
|
|
329
|
+
}(operation_1.default));
|
|
330
|
+
exports.default = Resolve;
|