greybel-interpreter 0.5.7 → 0.6.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/dist/context.d.ts +9 -9
- package/dist/context.js +156 -102
- package/dist/custom-types/boolean.d.ts +2 -1
- package/dist/custom-types/boolean.js +6 -3
- package/dist/custom-types/list.d.ts +3 -3
- package/dist/custom-types/list.js +17 -67
- package/dist/custom-types/map.d.ts +3 -2
- package/dist/custom-types/map.js +45 -41
- package/dist/custom-types/nil.d.ts +2 -1
- package/dist/custom-types/nil.js +5 -2
- package/dist/custom-types/number.d.ts +2 -1
- package/dist/custom-types/number.js +6 -3
- package/dist/custom-types/string.d.ts +6 -3
- package/dist/custom-types/string.js +96 -58
- package/dist/expressions/binary-negated-expression.d.ts +0 -1
- package/dist/expressions/binary-negated-expression.js +3 -7
- package/dist/expressions/call.js +22 -21
- package/dist/expressions/logical-and-binary.d.ts +0 -1
- package/dist/expressions/logical-and-binary.js +43 -46
- package/dist/expressions/map.js +20 -13
- package/dist/expressions/path.js +27 -22
- package/dist/operations/argument.js +15 -15
- package/dist/operations/function.d.ts +2 -0
- package/dist/operations/function.js +6 -0
- package/dist/operations/if-statement.js +73 -39
- package/dist/operations/not.js +2 -2
- package/dist/operations/return.js +5 -1
- package/dist/operations/while.js +20 -11
- package/dist/types/custom-type.d.ts +3 -1
- package/dist/types/custom-type.js +8 -2
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ export declare enum ContextState {
|
|
|
18
18
|
export declare class Scope extends CustomMap {
|
|
19
19
|
context: OperationContext;
|
|
20
20
|
constructor(context: OperationContext);
|
|
21
|
-
set(path: string[], value: any): Promise<void>;
|
|
22
21
|
get(path: string[]): Promise<any>;
|
|
23
22
|
getCallable(path: string[]): Promise<Callable>;
|
|
24
23
|
}
|
|
@@ -70,9 +69,9 @@ export declare class OperationContext {
|
|
|
70
69
|
processState: OperationContextProcessState;
|
|
71
70
|
isProtected: boolean;
|
|
72
71
|
injected: boolean;
|
|
73
|
-
api:
|
|
74
|
-
locals:
|
|
75
|
-
globals:
|
|
72
|
+
api: OperationContext | null;
|
|
73
|
+
locals: OperationContext | null;
|
|
74
|
+
globals: OperationContext | null;
|
|
76
75
|
constructor(options: OperationContextOptions);
|
|
77
76
|
step(item: ASTBase): Promise<void>;
|
|
78
77
|
setLastActive(opc: OperationContext): OperationContext;
|
|
@@ -81,11 +80,12 @@ export declare class OperationContext {
|
|
|
81
80
|
exit(): Promise<OperationContext>;
|
|
82
81
|
isPending(): boolean;
|
|
83
82
|
setPending(pending: boolean): OperationContext;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
lookupAllOfType(validate: (type: ContextType) => boolean): OperationContext[];
|
|
84
|
+
lookupType(validate: (type: ContextType) => boolean): OperationContext;
|
|
85
|
+
lookupAllScopes(): OperationContext[];
|
|
86
|
+
lookupAPI(): OperationContext;
|
|
87
|
+
lookupGlobals(): OperationContext;
|
|
88
|
+
lookupLocals(): OperationContext;
|
|
89
89
|
extend(map: Map<string, any>): OperationContext;
|
|
90
90
|
set(path: any[], value: any): Promise<void>;
|
|
91
91
|
get(path: any[]): Promise<any>;
|
package/dist/context.js
CHANGED
|
@@ -14,6 +14,42 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
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
|
+
};
|
|
17
53
|
var __read = (this && this.__read) || function (o, n) {
|
|
18
54
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
55
|
if (!m) return o;
|
|
@@ -67,96 +103,81 @@ var Scope = /** @class */ (function (_super) {
|
|
|
67
103
|
_this.context = context;
|
|
68
104
|
return _this;
|
|
69
105
|
}
|
|
70
|
-
Scope.prototype.set = function (path, value) {
|
|
71
|
-
var me = this;
|
|
72
|
-
var traversalPath = [].concat(path);
|
|
73
|
-
var current = traversalPath.shift();
|
|
74
|
-
if (current != null) {
|
|
75
|
-
if (current === 'locals') {
|
|
76
|
-
return me.context.locals.set(traversalPath, value);
|
|
77
|
-
}
|
|
78
|
-
else if (current === 'globals') {
|
|
79
|
-
return me.context.globals.set(traversalPath, value);
|
|
80
|
-
}
|
|
81
|
-
else if (me.context.locals != null) {
|
|
82
|
-
return map_1.default.prototype.set.call(me.context.locals, path, value);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
106
|
Scope.prototype.get = function (path) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
: me.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
var me, traversalPath, current;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
switch (_a.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
me = this;
|
|
113
|
+
traversalPath = [].concat(path);
|
|
114
|
+
current = traversalPath.shift();
|
|
115
|
+
if (path.length === 0) {
|
|
116
|
+
return [2 /*return*/, Promise.resolve(me)];
|
|
117
|
+
}
|
|
118
|
+
if (!(current === 'locals' || current === 'globals')) return [3 /*break*/, 1];
|
|
119
|
+
return [2 /*return*/, me.context.get(path)];
|
|
120
|
+
case 1: return [4 /*yield*/, me.has(path)];
|
|
121
|
+
case 2:
|
|
122
|
+
if (!_a.sent()) return [3 /*break*/, 3];
|
|
123
|
+
return [2 /*return*/, _super.prototype.get.call(this, path)];
|
|
124
|
+
case 3: return [4 /*yield*/, me.context.api.scope.has(path)];
|
|
125
|
+
case 4:
|
|
126
|
+
if (_a.sent()) {
|
|
127
|
+
return [2 /*return*/, me.context.api.get(path)];
|
|
128
|
+
}
|
|
129
|
+
else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
|
|
130
|
+
return [2 /*return*/, Promise.resolve(map_1.default.intrinsics.get(current).bind(null, me))];
|
|
131
|
+
}
|
|
132
|
+
else if (me.context.previous) {
|
|
133
|
+
return [2 /*return*/, me.context.previous.get(path)];
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
137
|
+
}
|
|
138
|
+
_a.label = 5;
|
|
139
|
+
case 5: return [2 /*return*/];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
125
143
|
};
|
|
126
144
|
Scope.prototype.getCallable = function (path) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var me, traversalPath, current;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
switch (_a.label) {
|
|
149
|
+
case 0:
|
|
150
|
+
me = this;
|
|
151
|
+
traversalPath = [].concat(path);
|
|
152
|
+
current = traversalPath.shift();
|
|
153
|
+
if (current === 'locals' || current === 'globals') {
|
|
154
|
+
return [2 /*return*/, me.context.getCallable(path)];
|
|
155
|
+
}
|
|
156
|
+
return [4 /*yield*/, me.has(path)];
|
|
157
|
+
case 1:
|
|
158
|
+
if (!_a.sent()) return [3 /*break*/, 2];
|
|
159
|
+
return [2 /*return*/, _super.prototype.getCallable.call(this, path)];
|
|
160
|
+
case 2: return [4 /*yield*/, me.context.api.scope.has(path)];
|
|
161
|
+
case 3:
|
|
162
|
+
if (_a.sent()) {
|
|
163
|
+
return [2 /*return*/, me.context.api.getCallable(path)];
|
|
164
|
+
}
|
|
165
|
+
else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
|
|
166
|
+
return [2 /*return*/, Promise.resolve({
|
|
167
|
+
origin: map_1.default.intrinsics.get(current).bind(null, me),
|
|
168
|
+
context: me
|
|
169
|
+
})];
|
|
170
|
+
}
|
|
171
|
+
else if (me.context.previous) {
|
|
172
|
+
return [2 /*return*/, me.context.previous.getCallable(path)];
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
throw new Error("Cannot get callable path ".concat(path.join('.')));
|
|
176
|
+
}
|
|
177
|
+
_a.label = 4;
|
|
178
|
+
case 4: return [2 /*return*/];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
160
181
|
});
|
|
161
182
|
};
|
|
162
183
|
return Scope;
|
|
@@ -247,7 +268,7 @@ var OperationContext = /** @class */ (function () {
|
|
|
247
268
|
};
|
|
248
269
|
me.api = me.lookupAPI();
|
|
249
270
|
me.globals = me.lookupGlobals();
|
|
250
|
-
me.locals = me.lookupLocals();
|
|
271
|
+
me.locals = me.lookupLocals() || me;
|
|
251
272
|
}
|
|
252
273
|
OperationContext.prototype.step = function (item) {
|
|
253
274
|
var me = this;
|
|
@@ -303,20 +324,38 @@ var OperationContext = /** @class */ (function () {
|
|
|
303
324
|
me.processState.pending = pending;
|
|
304
325
|
return me;
|
|
305
326
|
};
|
|
327
|
+
OperationContext.prototype.lookupAllOfType = function (validate) {
|
|
328
|
+
var me = this;
|
|
329
|
+
var result = [];
|
|
330
|
+
if (validate(me.type)) {
|
|
331
|
+
result.push(me);
|
|
332
|
+
}
|
|
333
|
+
var current = me.previous;
|
|
334
|
+
while (current) {
|
|
335
|
+
if (validate(current.type)) {
|
|
336
|
+
result.push(current);
|
|
337
|
+
}
|
|
338
|
+
current = current.previous;
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
};
|
|
306
342
|
OperationContext.prototype.lookupType = function (validate) {
|
|
307
343
|
var me = this;
|
|
308
344
|
if (validate(me.type)) {
|
|
309
|
-
return me
|
|
345
|
+
return me;
|
|
310
346
|
}
|
|
311
347
|
var current = me.previous;
|
|
312
348
|
while (current) {
|
|
313
349
|
if (validate(current.type)) {
|
|
314
|
-
return current
|
|
350
|
+
return current;
|
|
315
351
|
}
|
|
316
352
|
current = current.previous;
|
|
317
353
|
}
|
|
318
354
|
return null;
|
|
319
355
|
};
|
|
356
|
+
OperationContext.prototype.lookupAllScopes = function () {
|
|
357
|
+
return this.lookupAllOfType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
|
|
358
|
+
};
|
|
320
359
|
OperationContext.prototype.lookupAPI = function () {
|
|
321
360
|
return this.lookupType(function (type) { return [ContextType.API].includes(type); });
|
|
322
361
|
};
|
|
@@ -326,9 +365,6 @@ var OperationContext = /** @class */ (function () {
|
|
|
326
365
|
OperationContext.prototype.lookupLocals = function () {
|
|
327
366
|
return this.lookupType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
|
|
328
367
|
};
|
|
329
|
-
OperationContext.prototype.valueOf = function () {
|
|
330
|
-
return this.scope.valueOf();
|
|
331
|
-
};
|
|
332
368
|
OperationContext.prototype.extend = function (map) {
|
|
333
369
|
var _a;
|
|
334
370
|
var me = this;
|
|
@@ -343,28 +379,46 @@ var OperationContext = /** @class */ (function () {
|
|
|
343
379
|
OperationContext.prototype.set = function (path, value) {
|
|
344
380
|
var _a;
|
|
345
381
|
var me = this;
|
|
382
|
+
var traversalPath = [].concat(path);
|
|
383
|
+
var current = traversalPath.shift();
|
|
384
|
+
if (current === 'locals') {
|
|
385
|
+
return me.locals.set(traversalPath, value);
|
|
386
|
+
}
|
|
387
|
+
else if (current === 'globals') {
|
|
388
|
+
return me.globals.set(traversalPath, value);
|
|
389
|
+
}
|
|
346
390
|
if (me.state === ContextState.TEMPORARY) {
|
|
347
391
|
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
|
|
348
392
|
}
|
|
349
|
-
|
|
350
|
-
return me.scope.set(path, value);
|
|
351
|
-
}
|
|
393
|
+
return me.locals.scope.set(path, value);
|
|
352
394
|
};
|
|
353
395
|
OperationContext.prototype.get = function (path) {
|
|
354
396
|
var _a;
|
|
355
397
|
var me = this;
|
|
356
|
-
|
|
398
|
+
var traversalPath = [].concat(path);
|
|
399
|
+
var current = traversalPath.shift();
|
|
400
|
+
if (current === 'locals') {
|
|
401
|
+
return me.locals.get(traversalPath);
|
|
402
|
+
}
|
|
403
|
+
else if (current === 'globals') {
|
|
404
|
+
return me.globals.get(traversalPath);
|
|
405
|
+
}
|
|
406
|
+
else if (me.state === ContextState.TEMPORARY) {
|
|
357
407
|
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.get(path);
|
|
358
408
|
}
|
|
359
|
-
return me.scope.get(path);
|
|
409
|
+
return me.locals.scope.get(path);
|
|
360
410
|
};
|
|
361
411
|
OperationContext.prototype.getCallable = function (path) {
|
|
362
|
-
var _a;
|
|
363
412
|
var me = this;
|
|
364
|
-
|
|
365
|
-
|
|
413
|
+
var traversalPath = [].concat(path);
|
|
414
|
+
var current = traversalPath.shift();
|
|
415
|
+
if (current === 'locals') {
|
|
416
|
+
return me.locals.getCallable(traversalPath);
|
|
417
|
+
}
|
|
418
|
+
else if (current === 'globals') {
|
|
419
|
+
return me.globals.getCallable(traversalPath);
|
|
366
420
|
}
|
|
367
|
-
return me.scope.getCallable(path);
|
|
421
|
+
return me.locals.scope.getCallable(path);
|
|
368
422
|
};
|
|
369
423
|
OperationContext.prototype.setMemory = function (key, value) {
|
|
370
424
|
var me = this;
|
|
@@ -26,15 +26,18 @@ var CustomBoolean = /** @class */ (function (_super) {
|
|
|
26
26
|
CustomBoolean.prototype.getType = function () {
|
|
27
27
|
return 'boolean';
|
|
28
28
|
};
|
|
29
|
-
CustomBoolean.prototype.valueOf = function () {
|
|
30
|
-
return this.value;
|
|
31
|
-
};
|
|
32
29
|
CustomBoolean.prototype.toString = function () {
|
|
33
30
|
return this.value.toString();
|
|
34
31
|
};
|
|
35
32
|
CustomBoolean.prototype.fork = function () {
|
|
36
33
|
return new CustomBoolean(this.value);
|
|
37
34
|
};
|
|
35
|
+
CustomBoolean.prototype.toNumber = function () {
|
|
36
|
+
return Number(this.value);
|
|
37
|
+
};
|
|
38
|
+
CustomBoolean.prototype.toTruthy = function () {
|
|
39
|
+
return this.value;
|
|
40
|
+
};
|
|
38
41
|
CustomBoolean.intrinsics = new Map();
|
|
39
42
|
return CustomBoolean;
|
|
40
43
|
}(custom_type_1.CustomLiteralType));
|
|
@@ -5,7 +5,7 @@ export declare class CustomListIterator implements Iterator<any> {
|
|
|
5
5
|
constructor(value: any);
|
|
6
6
|
next(): IteratorResult<any>;
|
|
7
7
|
}
|
|
8
|
-
export declare function itemAtIndex(list: any[], n: number): number;
|
|
8
|
+
export declare function itemAtIndex(list: any[], n: number): number | null;
|
|
9
9
|
export default class CustomList extends CustomObjectType {
|
|
10
10
|
static intrinsics: Map<string, Function>;
|
|
11
11
|
value: any[];
|
|
@@ -17,9 +17,9 @@ export default class CustomList extends CustomObjectType {
|
|
|
17
17
|
set(path: any[], value: any): Promise<void>;
|
|
18
18
|
get(path: any[]): Promise<any>;
|
|
19
19
|
getCallable(path: any[]): Promise<Callable>;
|
|
20
|
-
callMethod(method: string[], ...args: any[]): any;
|
|
21
20
|
getType(): string;
|
|
22
|
-
valueOf(): CustomList | null;
|
|
23
21
|
toString(): string;
|
|
22
|
+
toNumber(): number;
|
|
23
|
+
toTruthy(): boolean;
|
|
24
24
|
fork(): CustomList;
|
|
25
25
|
}
|
|
@@ -50,35 +50,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
50
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
if (!m) return o;
|
|
56
|
-
var i = m.call(o), r, ar = [], e;
|
|
57
|
-
try {
|
|
58
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
59
|
-
}
|
|
60
|
-
catch (error) { e = { error: error }; }
|
|
61
|
-
finally {
|
|
62
|
-
try {
|
|
63
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
64
|
-
}
|
|
65
|
-
finally { if (e) throw e.error; }
|
|
66
|
-
}
|
|
67
|
-
return ar;
|
|
68
|
-
};
|
|
69
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
70
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
-
if (ar || !(i in from)) {
|
|
72
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
-
ar[i] = from[i];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
77
55
|
};
|
|
78
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
57
|
exports.itemAtIndex = exports.CustomListIterator = void 0;
|
|
80
58
|
var operation_1 = require("../types/operation");
|
|
81
59
|
var custom_type_1 = require("../types/custom-type");
|
|
60
|
+
var string_1 = __importDefault(require("./string"));
|
|
82
61
|
var CustomListIterator = /** @class */ (function () {
|
|
83
62
|
function CustomListIterator(value) {
|
|
84
63
|
var me = this;
|
|
@@ -102,6 +81,8 @@ var CustomListIterator = /** @class */ (function () {
|
|
|
102
81
|
}());
|
|
103
82
|
exports.CustomListIterator = CustomListIterator;
|
|
104
83
|
function itemAtIndex(list, n) {
|
|
84
|
+
if (Number.isNaN(n))
|
|
85
|
+
return null;
|
|
105
86
|
n = Math.trunc(n) || 0;
|
|
106
87
|
if (n < 0)
|
|
107
88
|
n += list.length;
|
|
@@ -115,7 +96,7 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
115
96
|
function CustomList(value) {
|
|
116
97
|
var _this = _super.call(this) || this;
|
|
117
98
|
_this.slice = function (a, b) {
|
|
118
|
-
return new CustomList(this.value.slice(a
|
|
99
|
+
return new CustomList(this.value.slice(a.toNumber(), b.toNumber()));
|
|
119
100
|
};
|
|
120
101
|
_this.value = value;
|
|
121
102
|
return _this;
|
|
@@ -177,7 +158,8 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
177
158
|
currentIndex = itemAtIndex(refs, Number(current));
|
|
178
159
|
if (refs.hasOwnProperty(currentIndex)) {
|
|
179
160
|
sub = refs[currentIndex];
|
|
180
|
-
if (traversalPath.length > 0 &&
|
|
161
|
+
if (traversalPath.length > 0 &&
|
|
162
|
+
(sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default)) {
|
|
181
163
|
return [2 /*return*/, sub.get(traversalPath)];
|
|
182
164
|
}
|
|
183
165
|
if (traversalPath.length === 0) {
|
|
@@ -187,9 +169,6 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
187
169
|
else if (path.length === 1 && CustomList.intrinsics.has(current)) {
|
|
188
170
|
return [2 /*return*/, CustomList.intrinsics.get(current).bind(null, me)];
|
|
189
171
|
}
|
|
190
|
-
else {
|
|
191
|
-
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
192
|
-
}
|
|
193
172
|
}
|
|
194
173
|
return [2 /*return*/, null];
|
|
195
174
|
});
|
|
@@ -207,7 +186,7 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
207
186
|
currentIndex = itemAtIndex(refs, Number(current));
|
|
208
187
|
if (refs.hasOwnProperty(currentIndex)) {
|
|
209
188
|
sub = refs[currentIndex];
|
|
210
|
-
if (sub instanceof custom_type_1.CustomObjectType) {
|
|
189
|
+
if (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default) {
|
|
211
190
|
return [2 /*return*/, sub.getCallable(traversalPath)];
|
|
212
191
|
}
|
|
213
192
|
if (traversalPath.length === 0) {
|
|
@@ -223,57 +202,28 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
223
202
|
context: me
|
|
224
203
|
}];
|
|
225
204
|
}
|
|
226
|
-
else {
|
|
227
|
-
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
228
|
-
}
|
|
229
205
|
}
|
|
230
206
|
return [2 /*return*/, {
|
|
231
|
-
origin:
|
|
207
|
+
origin: null,
|
|
232
208
|
context: me
|
|
233
209
|
}];
|
|
234
210
|
});
|
|
235
211
|
});
|
|
236
212
|
};
|
|
237
|
-
CustomList.prototype.callMethod = function (method) {
|
|
238
|
-
var _a;
|
|
239
|
-
var _b;
|
|
240
|
-
var args = [];
|
|
241
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
242
|
-
args[_i - 1] = arguments[_i];
|
|
243
|
-
}
|
|
244
|
-
if (method.length === 0) {
|
|
245
|
-
throw new Error('Unexpected method length');
|
|
246
|
-
}
|
|
247
|
-
var me = this;
|
|
248
|
-
var member = (_b = method[0]) === null || _b === void 0 ? void 0 : _b.toString();
|
|
249
|
-
if (CustomList.isNumber(member)) {
|
|
250
|
-
var memberIndex = itemAtIndex(me.value, Number(member));
|
|
251
|
-
if (!me.value.hasOwnProperty(memberIndex)) {
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
if (method.length > 1) {
|
|
255
|
-
return (_a = me.value[memberIndex]).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
|
|
256
|
-
}
|
|
257
|
-
return me.value[memberIndex];
|
|
258
|
-
}
|
|
259
|
-
if (!CustomList.intrinsics.has(member)) {
|
|
260
|
-
throw new Error("Cannot access ".concat(member, " in list"));
|
|
261
|
-
}
|
|
262
|
-
return CustomList.intrinsics.get(member).apply(void 0, __spreadArray([me], __read(args), false));
|
|
263
|
-
};
|
|
264
213
|
CustomList.prototype.getType = function () {
|
|
265
214
|
return 'list';
|
|
266
215
|
};
|
|
267
|
-
CustomList.prototype.valueOf = function () {
|
|
268
|
-
var me = this;
|
|
269
|
-
var value = me.value;
|
|
270
|
-
return value.length === 0 ? null : me;
|
|
271
|
-
};
|
|
272
216
|
CustomList.prototype.toString = function () {
|
|
273
217
|
var me = this;
|
|
274
|
-
var body = me.value.map(function (item) {
|
|
218
|
+
var body = me.value.map(function (item) { return item === null || item === void 0 ? void 0 : item.toString(); });
|
|
275
219
|
return "[".concat(body.join(','), "]");
|
|
276
220
|
};
|
|
221
|
+
CustomList.prototype.toNumber = function () {
|
|
222
|
+
return 0;
|
|
223
|
+
};
|
|
224
|
+
CustomList.prototype.toTruthy = function () {
|
|
225
|
+
return this.value.length > 0;
|
|
226
|
+
};
|
|
277
227
|
CustomList.prototype.fork = function () {
|
|
278
228
|
return new CustomList(this.value);
|
|
279
229
|
};
|
|
@@ -16,13 +16,14 @@ export default class CustomMap extends CustomObjectType implements Iterable<Cust
|
|
|
16
16
|
constructor(value?: Map<string, any>);
|
|
17
17
|
[Symbol.iterator](): CustomMapIterator;
|
|
18
18
|
extend(value: Map<string, any>): CustomMap;
|
|
19
|
+
has(path: string[]): Promise<boolean>;
|
|
19
20
|
set(path: string[], value: any): Promise<void>;
|
|
20
21
|
get(path: string[]): Promise<any>;
|
|
21
22
|
getCallable(path: string[]): Promise<Callable>;
|
|
22
|
-
callMethod(method: string[], ...args: any[]): any;
|
|
23
23
|
createInstance(): CustomMap;
|
|
24
24
|
getType(): string;
|
|
25
|
-
|
|
25
|
+
toNumber(): number;
|
|
26
|
+
toTruthy(): boolean;
|
|
26
27
|
toString(): string;
|
|
27
28
|
fork(): CustomMap;
|
|
28
29
|
}
|