greybel-interpreter 0.5.5 → 0.5.9
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 -8
- package/dist/context.js +157 -91
- package/dist/custom-types/list.d.ts +1 -2
- package/dist/custom-types/list.js +9 -60
- package/dist/custom-types/map.d.ts +1 -1
- package/dist/custom-types/map.js +39 -36
- package/dist/custom-types/string.d.ts +4 -2
- package/dist/custom-types/string.js +89 -53
- package/dist/expressions/call.js +22 -21
- package/dist/expressions/logical-and-binary.js +14 -5
- package/dist/expressions/map.js +20 -13
- package/dist/expressions/path.js +6 -2
- package/dist/operations/argument.js +15 -15
- package/dist/operations/return.js +5 -1
- package/dist/operations/while.js +10 -4
- package/dist/types/custom-type.d.ts +1 -0
- package/dist/types/custom-type.js +3 -0
- 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,10 +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
|
-
|
|
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;
|
|
88
89
|
valueOf(): CustomMap;
|
|
89
90
|
extend(map: Map<string, any>): OperationContext;
|
|
90
91
|
set(path: any[], value: any): Promise<void>;
|
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,87 +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
|
-
|
|
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
|
+
});
|
|
122
143
|
};
|
|
123
144
|
Scope.prototype.getCallable = function (path) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
+
});
|
|
151
181
|
});
|
|
152
182
|
};
|
|
153
183
|
return Scope;
|
|
@@ -238,7 +268,7 @@ var OperationContext = /** @class */ (function () {
|
|
|
238
268
|
};
|
|
239
269
|
me.api = me.lookupAPI();
|
|
240
270
|
me.globals = me.lookupGlobals();
|
|
241
|
-
me.locals = me.lookupLocals();
|
|
271
|
+
me.locals = me.lookupLocals() || me;
|
|
242
272
|
}
|
|
243
273
|
OperationContext.prototype.step = function (item) {
|
|
244
274
|
var me = this;
|
|
@@ -294,20 +324,38 @@ var OperationContext = /** @class */ (function () {
|
|
|
294
324
|
me.processState.pending = pending;
|
|
295
325
|
return me;
|
|
296
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
|
+
};
|
|
297
342
|
OperationContext.prototype.lookupType = function (validate) {
|
|
298
343
|
var me = this;
|
|
299
344
|
if (validate(me.type)) {
|
|
300
|
-
return me
|
|
345
|
+
return me;
|
|
301
346
|
}
|
|
302
347
|
var current = me.previous;
|
|
303
348
|
while (current) {
|
|
304
349
|
if (validate(current.type)) {
|
|
305
|
-
return current
|
|
350
|
+
return current;
|
|
306
351
|
}
|
|
307
352
|
current = current.previous;
|
|
308
353
|
}
|
|
309
354
|
return null;
|
|
310
355
|
};
|
|
356
|
+
OperationContext.prototype.lookupAllScopes = function () {
|
|
357
|
+
return this.lookupAllOfType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
|
|
358
|
+
};
|
|
311
359
|
OperationContext.prototype.lookupAPI = function () {
|
|
312
360
|
return this.lookupType(function (type) { return [ContextType.API].includes(type); });
|
|
313
361
|
};
|
|
@@ -318,7 +366,7 @@ var OperationContext = /** @class */ (function () {
|
|
|
318
366
|
return this.lookupType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
|
|
319
367
|
};
|
|
320
368
|
OperationContext.prototype.valueOf = function () {
|
|
321
|
-
return this.scope
|
|
369
|
+
return this.scope;
|
|
322
370
|
};
|
|
323
371
|
OperationContext.prototype.extend = function (map) {
|
|
324
372
|
var _a;
|
|
@@ -334,28 +382,46 @@ var OperationContext = /** @class */ (function () {
|
|
|
334
382
|
OperationContext.prototype.set = function (path, value) {
|
|
335
383
|
var _a;
|
|
336
384
|
var me = this;
|
|
385
|
+
var traversalPath = [].concat(path);
|
|
386
|
+
var current = traversalPath.shift();
|
|
387
|
+
if (current === 'locals') {
|
|
388
|
+
return me.locals.set(traversalPath, value);
|
|
389
|
+
}
|
|
390
|
+
else if (current === 'globals') {
|
|
391
|
+
return me.globals.set(traversalPath, value);
|
|
392
|
+
}
|
|
337
393
|
if (me.state === ContextState.TEMPORARY) {
|
|
338
394
|
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
|
|
339
395
|
}
|
|
340
|
-
|
|
341
|
-
return me.scope.set(path, value);
|
|
342
|
-
}
|
|
396
|
+
return me.locals.scope.set(path, value);
|
|
343
397
|
};
|
|
344
398
|
OperationContext.prototype.get = function (path) {
|
|
345
399
|
var _a;
|
|
346
400
|
var me = this;
|
|
347
|
-
|
|
401
|
+
var traversalPath = [].concat(path);
|
|
402
|
+
var current = traversalPath.shift();
|
|
403
|
+
if (current === 'locals') {
|
|
404
|
+
return me.locals.get(traversalPath);
|
|
405
|
+
}
|
|
406
|
+
else if (current === 'globals') {
|
|
407
|
+
return me.globals.get(traversalPath);
|
|
408
|
+
}
|
|
409
|
+
else if (me.state === ContextState.TEMPORARY) {
|
|
348
410
|
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.get(path);
|
|
349
411
|
}
|
|
350
|
-
return me.scope.get(path);
|
|
412
|
+
return me.locals.scope.get(path);
|
|
351
413
|
};
|
|
352
414
|
OperationContext.prototype.getCallable = function (path) {
|
|
353
|
-
var _a;
|
|
354
415
|
var me = this;
|
|
355
|
-
|
|
356
|
-
|
|
416
|
+
var traversalPath = [].concat(path);
|
|
417
|
+
var current = traversalPath.shift();
|
|
418
|
+
if (current === 'locals') {
|
|
419
|
+
return me.locals.getCallable(traversalPath);
|
|
420
|
+
}
|
|
421
|
+
else if (current === 'globals') {
|
|
422
|
+
return me.globals.getCallable(traversalPath);
|
|
357
423
|
}
|
|
358
|
-
return me.scope.getCallable(path);
|
|
424
|
+
return me.locals.scope.getCallable(path);
|
|
359
425
|
};
|
|
360
426
|
OperationContext.prototype.setMemory = function (key, value) {
|
|
361
427
|
var me = this;
|
|
@@ -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,7 +17,6 @@ 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
21
|
valueOf(): CustomList | null;
|
|
23
22
|
toString(): string;
|
|
@@ -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;
|
|
@@ -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,44 +202,14 @@ 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
|
};
|
|
@@ -16,10 +16,10 @@ 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
|
valueOf(): CustomMap | null;
|
package/dist/custom-types/map.js
CHANGED
|
@@ -39,10 +39,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
39
39
|
}
|
|
40
40
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
41
|
};
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
42
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
46
|
exports.CustomMapIterator = void 0;
|
|
44
47
|
var custom_type_1 = require("../types/custom-type");
|
|
45
48
|
var operation_1 = require("../types/operation");
|
|
49
|
+
var string_1 = __importDefault(require("./string"));
|
|
46
50
|
var CustomMapIterator = /** @class */ (function () {
|
|
47
51
|
function CustomMapIterator(value) {
|
|
48
52
|
var me = this;
|
|
@@ -87,8 +91,33 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
87
91
|
me.value = new Map(__spreadArray(__spreadArray([], __read(me.value.entries()), false), __read(value.entries()), false));
|
|
88
92
|
return me;
|
|
89
93
|
};
|
|
94
|
+
CustomMap.prototype.has = function (path) {
|
|
95
|
+
var me = this;
|
|
96
|
+
if (path.length === 0) {
|
|
97
|
+
return Promise.resolve(true);
|
|
98
|
+
}
|
|
99
|
+
var traversalPath = [].concat(path);
|
|
100
|
+
var refs = me.value;
|
|
101
|
+
var current = traversalPath.shift();
|
|
102
|
+
if (current != null) {
|
|
103
|
+
if (refs.has(current)) {
|
|
104
|
+
var sub = refs.get(current);
|
|
105
|
+
if (traversalPath.length > 0 && sub instanceof custom_type_1.CustomObjectType) {
|
|
106
|
+
return sub.has(traversalPath);
|
|
107
|
+
}
|
|
108
|
+
if (traversalPath.length === 0) {
|
|
109
|
+
return Promise.resolve(true);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return Promise.resolve(false);
|
|
114
|
+
};
|
|
90
115
|
CustomMap.prototype.set = function (path, value) {
|
|
91
116
|
var me = this;
|
|
117
|
+
if (!path) {
|
|
118
|
+
console.warn('Cannot set empty path for ', me);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
92
121
|
var traversalPath = [].concat(path);
|
|
93
122
|
var refs = me.value;
|
|
94
123
|
var last = traversalPath.pop();
|
|
@@ -100,9 +129,8 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
100
129
|
return sub.set(traversalPath.concat(last), value);
|
|
101
130
|
}
|
|
102
131
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
132
|
+
console.warn("Cannot set path ".concat(path === null || path === void 0 ? void 0 : path.join('.')));
|
|
133
|
+
return;
|
|
106
134
|
}
|
|
107
135
|
if (value instanceof operation_1.FunctionOperationBase) {
|
|
108
136
|
refs.set(last, value.fork(me));
|
|
@@ -122,7 +150,8 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
122
150
|
if (current != null) {
|
|
123
151
|
if (refs.has(current)) {
|
|
124
152
|
var sub = refs.get(current);
|
|
125
|
-
if (traversalPath.length > 0 &&
|
|
153
|
+
if (traversalPath.length > 0 &&
|
|
154
|
+
(sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default)) {
|
|
126
155
|
return sub.get(traversalPath);
|
|
127
156
|
}
|
|
128
157
|
if (traversalPath.length === 0) {
|
|
@@ -140,19 +169,13 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
140
169
|
};
|
|
141
170
|
CustomMap.prototype.getCallable = function (path) {
|
|
142
171
|
var me = this;
|
|
143
|
-
if (path.length === 0) {
|
|
144
|
-
return Promise.resolve({
|
|
145
|
-
origin: me.value,
|
|
146
|
-
context: me
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
172
|
var traversalPath = [].concat(path);
|
|
150
173
|
var refs = me.value;
|
|
151
174
|
var current = traversalPath.shift();
|
|
152
175
|
if (current != null) {
|
|
153
176
|
if (refs.has(current)) {
|
|
154
177
|
var sub = refs.get(current);
|
|
155
|
-
if (sub instanceof custom_type_1.CustomObjectType) {
|
|
178
|
+
if (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default) {
|
|
156
179
|
return sub.getCallable(traversalPath);
|
|
157
180
|
}
|
|
158
181
|
if (traversalPath.length === 0) {
|
|
@@ -169,33 +192,13 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
169
192
|
});
|
|
170
193
|
}
|
|
171
194
|
else {
|
|
172
|
-
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
195
|
+
throw new Error("Cannot get callable path ".concat(path.join('.')));
|
|
173
196
|
}
|
|
174
197
|
}
|
|
175
|
-
return Promise.resolve(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var _b;
|
|
180
|
-
var args = [];
|
|
181
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
182
|
-
args[_i - 1] = arguments[_i];
|
|
183
|
-
}
|
|
184
|
-
if (method.length === 0) {
|
|
185
|
-
throw new Error('Unexpected method length');
|
|
186
|
-
}
|
|
187
|
-
var me = this;
|
|
188
|
-
var key = (_b = method[0]) === null || _b === void 0 ? void 0 : _b.toString();
|
|
189
|
-
if (method.length > 1) {
|
|
190
|
-
if (me.value.has(key)) {
|
|
191
|
-
return (_a = me.value.get(key)).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
|
|
192
|
-
}
|
|
193
|
-
throw new Error("Unexpected method path");
|
|
194
|
-
}
|
|
195
|
-
if (!CustomMap.intrinsics.has(key)) {
|
|
196
|
-
throw new Error("Cannot access ".concat(key, " in map"));
|
|
197
|
-
}
|
|
198
|
-
return CustomMap.intrinsics.get(key).apply(void 0, __spreadArray([me], __read(args), false));
|
|
198
|
+
return Promise.resolve({
|
|
199
|
+
origin: null,
|
|
200
|
+
context: me
|
|
201
|
+
});
|
|
199
202
|
};
|
|
200
203
|
CustomMap.prototype.createInstance = function () {
|
|
201
204
|
var me = this;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Callable } from '../types/custom-type';
|
|
1
2
|
import { CustomLiteralType } from '../types/custom-type';
|
|
2
3
|
export declare class CustomStringIterator implements Iterator<string> {
|
|
3
4
|
value: string;
|
|
@@ -5,6 +6,7 @@ export declare class CustomStringIterator implements Iterator<string> {
|
|
|
5
6
|
constructor(value: string);
|
|
6
7
|
next(): IteratorResult<string>;
|
|
7
8
|
}
|
|
9
|
+
export declare function itemAtIndex(str: any, n: number): number | null;
|
|
8
10
|
export default class CustomString extends CustomLiteralType {
|
|
9
11
|
static intrinsics: Map<string, Function>;
|
|
10
12
|
value: string;
|
|
@@ -12,8 +14,8 @@ export default class CustomString extends CustomLiteralType {
|
|
|
12
14
|
constructor(value: string);
|
|
13
15
|
slice(a: CustomLiteralType, b: CustomLiteralType): CustomString;
|
|
14
16
|
[Symbol.iterator](): CustomStringIterator;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
get(path: any[]): Promise<any>;
|
|
18
|
+
getCallable(path: any[]): Promise<Callable>;
|
|
17
19
|
getType(): string;
|
|
18
20
|
valueOf(): string | null;
|
|
19
21
|
toString(): string;
|
|
@@ -14,33 +14,44 @@ 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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
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
|
+
});
|
|
32
25
|
};
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 };
|
|
39
51
|
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
52
|
};
|
|
42
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.CustomStringIterator = void 0;
|
|
54
|
+
exports.itemAtIndex = exports.CustomStringIterator = void 0;
|
|
44
55
|
var custom_type_1 = require("../types/custom-type");
|
|
45
56
|
var CustomStringIterator = /** @class */ (function () {
|
|
46
57
|
function CustomStringIterator(value) {
|
|
@@ -64,6 +75,17 @@ var CustomStringIterator = /** @class */ (function () {
|
|
|
64
75
|
return CustomStringIterator;
|
|
65
76
|
}());
|
|
66
77
|
exports.CustomStringIterator = CustomStringIterator;
|
|
78
|
+
function itemAtIndex(str, n) {
|
|
79
|
+
if (Number.isNaN(n))
|
|
80
|
+
return null;
|
|
81
|
+
n = Math.trunc(n) || 0;
|
|
82
|
+
if (n < 0)
|
|
83
|
+
n += str.length;
|
|
84
|
+
if (n < 0 || n >= str.length)
|
|
85
|
+
return -1;
|
|
86
|
+
return n;
|
|
87
|
+
}
|
|
88
|
+
exports.itemAtIndex = itemAtIndex;
|
|
67
89
|
var CustomString = /** @class */ (function (_super) {
|
|
68
90
|
__extends(CustomString, _super);
|
|
69
91
|
function CustomString(value) {
|
|
@@ -80,37 +102,51 @@ var CustomString = /** @class */ (function (_super) {
|
|
|
80
102
|
CustomString.prototype[Symbol.iterator] = function () {
|
|
81
103
|
return new CustomStringIterator(this.value);
|
|
82
104
|
};
|
|
83
|
-
CustomString.prototype.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
CustomString.prototype.get = function (path) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var me, traversalPath, str, current, currentIndex;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
me = this;
|
|
110
|
+
if (path.length === 0) {
|
|
111
|
+
return [2 /*return*/, me];
|
|
112
|
+
}
|
|
113
|
+
traversalPath = [].concat(path);
|
|
114
|
+
str = me.value;
|
|
115
|
+
current = traversalPath.shift();
|
|
116
|
+
if (current != null) {
|
|
117
|
+
currentIndex = itemAtIndex(str, Number(current));
|
|
118
|
+
if (currentIndex != null && str.charAt(currentIndex) != null) {
|
|
119
|
+
return [2 /*return*/, new CustomString(str.charAt(currentIndex))];
|
|
120
|
+
}
|
|
121
|
+
else if (path.length === 1 && CustomString.intrinsics.has(current)) {
|
|
122
|
+
return [2 /*return*/, CustomString.intrinsics.get(current).bind(null, me)];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return [2 /*return*/, null];
|
|
126
|
+
});
|
|
127
|
+
});
|
|
87
128
|
};
|
|
88
|
-
CustomString.prototype.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
if (!CustomString.intrinsics.has(member)) {
|
|
111
|
-
throw new Error("Cannot access ".concat(member, " in string"));
|
|
112
|
-
}
|
|
113
|
-
return CustomString.intrinsics.get(member).apply(void 0, __spreadArray([me], __read(args), false));
|
|
129
|
+
CustomString.prototype.getCallable = function (path) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var me, traversalPath, current;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
me = this;
|
|
134
|
+
traversalPath = [].concat(path);
|
|
135
|
+
current = traversalPath.shift();
|
|
136
|
+
if (current != null) {
|
|
137
|
+
if (path.length === 1 && CustomString.intrinsics.has(current)) {
|
|
138
|
+
return [2 /*return*/, {
|
|
139
|
+
origin: CustomString.intrinsics.get(current).bind(null, me),
|
|
140
|
+
context: me
|
|
141
|
+
}];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return [2 /*return*/, {
|
|
145
|
+
origin: null,
|
|
146
|
+
context: me
|
|
147
|
+
}];
|
|
148
|
+
});
|
|
149
|
+
});
|
|
114
150
|
};
|
|
115
151
|
CustomString.prototype.getType = function () {
|
|
116
152
|
return 'string';
|
package/dist/expressions/call.js
CHANGED
|
@@ -152,25 +152,27 @@ var CallExpression = /** @class */ (function (_super) {
|
|
|
152
152
|
var evaluate = function (node) {
|
|
153
153
|
return __awaiter(this, void 0, void 0, function () {
|
|
154
154
|
var args, pathExpr, callable_1, _a, callable, _b;
|
|
155
|
-
var _c, _d
|
|
156
|
-
return __generator(this, function (
|
|
157
|
-
switch (
|
|
155
|
+
var _c, _d;
|
|
156
|
+
return __generator(this, function (_e) {
|
|
157
|
+
switch (_e.label) {
|
|
158
158
|
case 0:
|
|
159
159
|
if (node instanceof expression_1.Expression) {
|
|
160
160
|
return [2 /*return*/, node.get(opc)];
|
|
161
161
|
}
|
|
162
162
|
return [4 /*yield*/, node.resolveArgs(operationContext)];
|
|
163
163
|
case 1:
|
|
164
|
-
args =
|
|
164
|
+
args = _e.sent();
|
|
165
165
|
return [4 /*yield*/, node.path.get(opc, me.expr)];
|
|
166
166
|
case 2:
|
|
167
|
-
pathExpr =
|
|
167
|
+
pathExpr = _e.sent();
|
|
168
168
|
operationContext.debugger.debug('Line', me.ast.start.line, 'CallExpression', 'pathExpr', pathExpr);
|
|
169
|
-
if (!pathExpr.handle) return [3 /*break*/,
|
|
170
|
-
if (!(0, typer_1.isCustomMap)(pathExpr.handle)
|
|
169
|
+
if (!pathExpr.handle) return [3 /*break*/, 7];
|
|
170
|
+
if (!((0, typer_1.isCustomMap)(pathExpr.handle) ||
|
|
171
|
+
(0, typer_1.isCustomList)(pathExpr.handle) ||
|
|
172
|
+
(0, typer_1.isCustomString)(pathExpr.handle))) return [3 /*break*/, 6];
|
|
171
173
|
return [4 /*yield*/, pathExpr.handle.getCallable(pathExpr.path)];
|
|
172
174
|
case 3:
|
|
173
|
-
callable_1 =
|
|
175
|
+
callable_1 = _e.sent();
|
|
174
176
|
if (!(callable_1.origin instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
175
177
|
opc.setMemory('args', args);
|
|
176
178
|
return [2 /*return*/, callable_1.origin.run(opc)];
|
|
@@ -178,23 +180,22 @@ var CallExpression = /** @class */ (function (_super) {
|
|
|
178
180
|
if (!(callable_1.origin instanceof Function)) return [3 /*break*/, 6];
|
|
179
181
|
_a = typer_1.cast;
|
|
180
182
|
return [4 /*yield*/, (_c = callable_1.origin).call.apply(_c, __spreadArray([pathExpr.handle], __read(args), false))];
|
|
181
|
-
case 5: return [2 /*return*/, _a.apply(void 0, [
|
|
183
|
+
case 5: return [2 /*return*/, _a.apply(void 0, [_e.sent()])];
|
|
182
184
|
case 6:
|
|
183
|
-
operationContext.debugger.raise('Unexpected handle call', me,
|
|
184
|
-
|
|
185
|
-
case 7: return [
|
|
186
|
-
case 8:
|
|
187
|
-
|
|
188
|
-
callable = _f.sent();
|
|
185
|
+
operationContext.debugger.raise('Unexpected handle call', me, pathExpr);
|
|
186
|
+
_e.label = 7;
|
|
187
|
+
case 7: return [4 /*yield*/, opc.getCallable(pathExpr.path)];
|
|
188
|
+
case 8:
|
|
189
|
+
callable = _e.sent();
|
|
189
190
|
opc.setMemory('args', args);
|
|
190
|
-
if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/,
|
|
191
|
+
if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/, 9];
|
|
191
192
|
return [2 /*return*/, callable.origin.run(opc)];
|
|
192
|
-
case
|
|
193
|
-
if (!(callable.origin instanceof Function)) return [3 /*break*/,
|
|
193
|
+
case 9:
|
|
194
|
+
if (!(callable.origin instanceof Function)) return [3 /*break*/, 11];
|
|
194
195
|
_b = typer_1.cast;
|
|
195
|
-
return [4 /*yield*/, (
|
|
196
|
-
case
|
|
197
|
-
case
|
|
196
|
+
return [4 /*yield*/, (_d = callable.origin).call.apply(_d, __spreadArray([callable.context], __read(args), false))];
|
|
197
|
+
case 10: return [2 /*return*/, _b.apply(void 0, [_e.sent()])];
|
|
198
|
+
case 11: return [2 /*return*/, (0, typer_1.cast)(callable.origin)];
|
|
198
199
|
}
|
|
199
200
|
});
|
|
200
201
|
});
|
|
@@ -162,7 +162,7 @@ var LogicalAndBinaryExpression = /** @class */ (function (_super) {
|
|
|
162
162
|
case 0:
|
|
163
163
|
me = this;
|
|
164
164
|
evaluate = function (node) { return __awaiter(_this, void 0, void 0, function () {
|
|
165
|
-
var expr, _a, binaryResult, _b, _c, _d, logicalResult, _e, _f, _g;
|
|
165
|
+
var expr, _a, binaryResult, _b, _c, _d, logicalLeft, logicalResult, _e, _f, _g;
|
|
166
166
|
return __generator(this, function (_h) {
|
|
167
167
|
switch (_h.label) {
|
|
168
168
|
case 0:
|
|
@@ -189,11 +189,20 @@ var LogicalAndBinaryExpression = /** @class */ (function (_super) {
|
|
|
189
189
|
case 4:
|
|
190
190
|
binaryResult = _c.apply(_b, _d.concat([_h.sent()]));
|
|
191
191
|
return [2 /*return*/, Number.isNaN(binaryResult) ? null : binaryResult];
|
|
192
|
-
case 5:
|
|
193
|
-
_f = (_e = exports.OPERATIONS)[expr.operator];
|
|
194
|
-
return [4 /*yield*/, evaluate(expr.left)];
|
|
192
|
+
case 5: return [4 /*yield*/, evaluate(expr.left)];
|
|
195
193
|
case 6:
|
|
196
|
-
|
|
194
|
+
logicalLeft = _h.sent();
|
|
195
|
+
if ((0, typer_1.isCustomList)(logicalLeft) && !logicalLeft.valueOf()) {
|
|
196
|
+
logicalLeft = false;
|
|
197
|
+
}
|
|
198
|
+
if (expr.operator === greybel_core_1.Operator.And && !(0, exports.toPrimitive)(logicalLeft)) {
|
|
199
|
+
return [2 /*return*/, false];
|
|
200
|
+
}
|
|
201
|
+
else if (expr.operator === greybel_core_1.Operator.Or && (0, exports.toPrimitive)(logicalLeft)) {
|
|
202
|
+
return [2 /*return*/, true];
|
|
203
|
+
}
|
|
204
|
+
_f = (_e = exports.OPERATIONS)[expr.operator];
|
|
205
|
+
_g = [logicalLeft];
|
|
197
206
|
return [4 /*yield*/, evaluate(expr.right)];
|
|
198
207
|
case 7:
|
|
199
208
|
logicalResult = _f.apply(_e, _g.concat([_h.sent()]));
|
package/dist/expressions/map.js
CHANGED
|
@@ -67,6 +67,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
67
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
68
|
exports.ExpressionSegment = exports.ValuesSegment = void 0;
|
|
69
69
|
var expression_1 = require("../types/expression");
|
|
70
|
+
var operation_1 = require("../types/operation");
|
|
70
71
|
var map_1 = __importDefault(require("../custom-types/map"));
|
|
71
72
|
var typer_1 = require("../typer");
|
|
72
73
|
var ValuesSegment = /** @class */ (function () {
|
|
@@ -138,46 +139,52 @@ var MapExpression = /** @class */ (function (_super) {
|
|
|
138
139
|
map = new Map();
|
|
139
140
|
_b.label = 1;
|
|
140
141
|
case 1:
|
|
141
|
-
_b.trys.push([1,
|
|
142
|
+
_b.trys.push([1, 11, 12, 13]);
|
|
142
143
|
values_1 = __values(values), values_1_1 = values_1.next();
|
|
143
144
|
_b.label = 2;
|
|
144
145
|
case 2:
|
|
145
|
-
if (!!values_1_1.done) return [3 /*break*/,
|
|
146
|
+
if (!!values_1_1.done) return [3 /*break*/, 10];
|
|
146
147
|
current = values_1_1.value;
|
|
147
148
|
key = void 0;
|
|
148
149
|
value = void 0;
|
|
149
150
|
key = current.key;
|
|
150
151
|
if (!(0, typer_1.isCustomValue)(current.value)) return [3 /*break*/, 3];
|
|
151
152
|
value = current.value;
|
|
152
|
-
return [3 /*break*/,
|
|
153
|
+
return [3 /*break*/, 8];
|
|
153
154
|
case 3:
|
|
154
155
|
if (!(current.value instanceof expression_1.Expression)) return [3 /*break*/, 5];
|
|
155
156
|
return [4 /*yield*/, current.value.get(operationContext)];
|
|
156
157
|
case 4:
|
|
157
158
|
value = _b.sent();
|
|
158
|
-
return [3 /*break*/,
|
|
159
|
+
return [3 /*break*/, 8];
|
|
159
160
|
case 5:
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
if (!(current.value instanceof operation_1.Operation)) return [3 /*break*/, 7];
|
|
162
|
+
return [4 /*yield*/, current.value.get(operationContext)];
|
|
162
163
|
case 6:
|
|
164
|
+
value = _b.sent();
|
|
165
|
+
return [3 /*break*/, 8];
|
|
166
|
+
case 7:
|
|
167
|
+
operationContext.debugger.raise('Unexpected value', me, current.value);
|
|
168
|
+
_b.label = 8;
|
|
169
|
+
case 8:
|
|
163
170
|
// @ts-ignore: Key is always a literal
|
|
164
171
|
map.set(key, value);
|
|
165
|
-
_b.label =
|
|
166
|
-
case
|
|
172
|
+
_b.label = 9;
|
|
173
|
+
case 9:
|
|
167
174
|
values_1_1 = values_1.next();
|
|
168
175
|
return [3 /*break*/, 2];
|
|
169
|
-
case
|
|
170
|
-
case
|
|
176
|
+
case 10: return [3 /*break*/, 13];
|
|
177
|
+
case 11:
|
|
171
178
|
e_1_1 = _b.sent();
|
|
172
179
|
e_1 = { error: e_1_1 };
|
|
173
|
-
return [3 /*break*/,
|
|
174
|
-
case
|
|
180
|
+
return [3 /*break*/, 13];
|
|
181
|
+
case 12:
|
|
175
182
|
try {
|
|
176
183
|
if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
|
|
177
184
|
}
|
|
178
185
|
finally { if (e_1) throw e_1.error; }
|
|
179
186
|
return [7 /*endfinally*/];
|
|
180
|
-
case
|
|
187
|
+
case 13: return [2 /*return*/, new map_1.default(map)];
|
|
181
188
|
}
|
|
182
189
|
});
|
|
183
190
|
});
|
package/dist/expressions/path.js
CHANGED
|
@@ -338,7 +338,9 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
338
338
|
if (!(resultExpr.path.length === 0)) return [3 /*break*/, 2];
|
|
339
339
|
return [2 /*return*/, resultExpr.handle];
|
|
340
340
|
case 2:
|
|
341
|
-
if (!(0, typer_1.isCustomMap)(resultExpr.handle)
|
|
341
|
+
if (!((0, typer_1.isCustomMap)(resultExpr.handle) ||
|
|
342
|
+
(0, typer_1.isCustomList)(resultExpr.handle) ||
|
|
343
|
+
(0, typer_1.isCustomString)(resultExpr.handle))) return [3 /*break*/, 7];
|
|
342
344
|
context = resultExpr.handle;
|
|
343
345
|
return [4 /*yield*/, context.get(resultExpr.path)];
|
|
344
346
|
case 3:
|
|
@@ -351,7 +353,9 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
351
353
|
return [4 /*yield*/, value_1.call(context)];
|
|
352
354
|
case 5: return [2 /*return*/, _a.apply(void 0, [_c.sent()])];
|
|
353
355
|
case 6: return [2 /*return*/, value_1];
|
|
354
|
-
case 7:
|
|
356
|
+
case 7:
|
|
357
|
+
operationContext.debugger.raise('Unexpected handle get', me, resultExpr);
|
|
358
|
+
_c.label = 8;
|
|
355
359
|
case 8: return [4 /*yield*/, operationContext.get(resultExpr.path)];
|
|
356
360
|
case 9:
|
|
357
361
|
value = _c.sent();
|
|
@@ -81,19 +81,19 @@ var ArgumentOperation = /** @class */ (function (_super) {
|
|
|
81
81
|
}
|
|
82
82
|
ArgumentOperation.prototype.get = function (operationContext) {
|
|
83
83
|
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
-
var me, stack, args, stack_1, stack_1_1, entity,
|
|
85
|
-
var e_1,
|
|
86
|
-
return __generator(this, function (
|
|
87
|
-
switch (
|
|
84
|
+
var me, stack, args, stack_1, stack_1_1, entity, arg, arg, e_1_1;
|
|
85
|
+
var e_1, _a;
|
|
86
|
+
return __generator(this, function (_b) {
|
|
87
|
+
switch (_b.label) {
|
|
88
88
|
case 0:
|
|
89
89
|
me = this;
|
|
90
90
|
stack = me.stack;
|
|
91
91
|
args = [];
|
|
92
|
-
|
|
92
|
+
_b.label = 1;
|
|
93
93
|
case 1:
|
|
94
|
-
|
|
94
|
+
_b.trys.push([1, 11, 12, 13]);
|
|
95
95
|
stack_1 = __values(stack), stack_1_1 = stack_1.next();
|
|
96
|
-
|
|
96
|
+
_b.label = 2;
|
|
97
97
|
case 2:
|
|
98
98
|
if (!!stack_1_1.done) return [3 /*break*/, 10];
|
|
99
99
|
entity = stack_1_1.value;
|
|
@@ -104,34 +104,34 @@ var ArgumentOperation = /** @class */ (function (_super) {
|
|
|
104
104
|
if (!(entity instanceof assign_1.default)) return [3 /*break*/, 6];
|
|
105
105
|
return [4 /*yield*/, entity.get(operationContext, me)];
|
|
106
106
|
case 4:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return [4 /*yield*/, entity.expr.left.get(operationContext)];
|
|
107
|
+
_b.sent();
|
|
108
|
+
return [4 /*yield*/, entity.expr.left.get(operationContext, me)];
|
|
110
109
|
case 5:
|
|
111
|
-
_b.
|
|
110
|
+
arg = _b.sent();
|
|
111
|
+
args.push(arg);
|
|
112
112
|
return [3 /*break*/, 9];
|
|
113
113
|
case 6:
|
|
114
114
|
if (!(entity instanceof path_1.default)) return [3 /*break*/, 8];
|
|
115
115
|
return [4 /*yield*/, entity.get(operationContext, me)];
|
|
116
116
|
case 7:
|
|
117
|
-
arg =
|
|
117
|
+
arg = _b.sent();
|
|
118
118
|
operationContext.set(arg.path, new nil_1.default());
|
|
119
119
|
args.push(arg);
|
|
120
120
|
return [3 /*break*/, 9];
|
|
121
121
|
case 8:
|
|
122
122
|
operationContext.debugger.raise('Unexpected argument', me, entity);
|
|
123
|
-
|
|
123
|
+
_b.label = 9;
|
|
124
124
|
case 9:
|
|
125
125
|
stack_1_1 = stack_1.next();
|
|
126
126
|
return [3 /*break*/, 2];
|
|
127
127
|
case 10: return [3 /*break*/, 13];
|
|
128
128
|
case 11:
|
|
129
|
-
e_1_1 =
|
|
129
|
+
e_1_1 = _b.sent();
|
|
130
130
|
e_1 = { error: e_1_1 };
|
|
131
131
|
return [3 /*break*/, 13];
|
|
132
132
|
case 12:
|
|
133
133
|
try {
|
|
134
|
-
if (stack_1_1 && !stack_1_1.done && (
|
|
134
|
+
if (stack_1_1 && !stack_1_1.done && (_a = stack_1.return)) _a.call(stack_1);
|
|
135
135
|
}
|
|
136
136
|
finally { if (e_1) throw e_1.error; }
|
|
137
137
|
return [7 /*endfinally*/];
|
|
@@ -50,10 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
53
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
57
|
var operation_1 = require("../types/operation");
|
|
55
58
|
var expression_1 = require("../types/expression");
|
|
56
59
|
var typer_1 = require("../typer");
|
|
60
|
+
var nil_1 = __importDefault(require("../custom-types/nil"));
|
|
57
61
|
var ReturnOperation = /** @class */ (function (_super) {
|
|
58
62
|
__extends(ReturnOperation, _super);
|
|
59
63
|
function ReturnOperation(ast, options) {
|
|
@@ -87,7 +91,7 @@ var ReturnOperation = /** @class */ (function (_super) {
|
|
|
87
91
|
arg = _a.sent();
|
|
88
92
|
return [3 /*break*/, 6];
|
|
89
93
|
case 5:
|
|
90
|
-
|
|
94
|
+
arg = new nil_1.default();
|
|
91
95
|
_a.label = 6;
|
|
92
96
|
case 6:
|
|
93
97
|
functionContext.value = arg;
|
package/dist/operations/while.js
CHANGED
|
@@ -82,7 +82,7 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
82
82
|
};
|
|
83
83
|
resolveCondition = function () {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var value;
|
|
85
|
+
var value, value;
|
|
86
86
|
return __generator(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
@@ -90,13 +90,19 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
90
90
|
return [4 /*yield*/, me.condition.get(opc)];
|
|
91
91
|
case 1:
|
|
92
92
|
value = _a.sent();
|
|
93
|
-
return [2 /*return*/, value.valueOf()];
|
|
93
|
+
return [2 /*return*/, !!(value === null || value === void 0 ? void 0 : value.valueOf())];
|
|
94
94
|
case 2:
|
|
95
|
+
if (!(me.condition instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
96
|
+
return [4 /*yield*/, me.condition.get(opc)];
|
|
97
|
+
case 3:
|
|
98
|
+
value = _a.sent();
|
|
99
|
+
return [2 /*return*/, !!(value === null || value === void 0 ? void 0 : value.valueOf())];
|
|
100
|
+
case 4:
|
|
95
101
|
if ((0, typer_1.isCustomValue)(me.condition)) {
|
|
96
102
|
return [2 /*return*/, me.condition.valueOf()];
|
|
97
103
|
}
|
|
98
|
-
_a.label =
|
|
99
|
-
case
|
|
104
|
+
_a.label = 5;
|
|
105
|
+
case 5:
|
|
100
106
|
operationContext.debugger.raise('Unexpected condition', me, me.condition);
|
|
101
107
|
return [2 /*return*/];
|
|
102
108
|
}
|
|
@@ -9,6 +9,7 @@ export declare abstract class CustomLiteralType extends CustomType {
|
|
|
9
9
|
}
|
|
10
10
|
export declare abstract class CustomObjectType extends CustomType {
|
|
11
11
|
value: any;
|
|
12
|
+
has(path: any[]): Promise<boolean>;
|
|
12
13
|
set(path: any[], value: any): Promise<void>;
|
|
13
14
|
get(path: any[]): Promise<any>;
|
|
14
15
|
getCallable(path: any[]): Promise<Callable>;
|
|
@@ -44,6 +44,9 @@ var CustomObjectType = /** @class */ (function (_super) {
|
|
|
44
44
|
function CustomObjectType() {
|
|
45
45
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
46
46
|
}
|
|
47
|
+
CustomObjectType.prototype.has = function (path) {
|
|
48
|
+
throw new Error('Implentation of "has" missing');
|
|
49
|
+
};
|
|
47
50
|
CustomObjectType.prototype.set = function (path, value) {
|
|
48
51
|
throw new Error('Implentation of "set" missing');
|
|
49
52
|
};
|