greybel-interpreter 0.4.9 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +96 -96
- package/dist/context.js +392 -392
- package/dist/cps.d.ts +15 -15
- package/dist/cps.js +849 -849
- package/dist/custom-types/boolean.d.ts +10 -10
- package/dist/custom-types/boolean.js +41 -41
- package/dist/custom-types/list.d.ts +25 -25
- package/dist/custom-types/list.js +288 -289
- package/dist/custom-types/map.d.ts +28 -28
- package/dist/custom-types/map.js +238 -238
- package/dist/custom-types/nil.d.ts +8 -8
- package/dist/custom-types/nil.js +38 -38
- package/dist/custom-types/number.d.ts +10 -10
- package/dist/custom-types/number.js +41 -41
- package/dist/custom-types/string.d.ts +21 -21
- package/dist/custom-types/string.js +131 -131
- package/dist/expressions/assign.d.ts +13 -13
- package/dist/expressions/assign.js +174 -174
- package/dist/expressions/binary-negated-expression.d.ts +19 -19
- package/dist/expressions/binary-negated-expression.js +131 -131
- package/dist/expressions/call.d.ts +14 -14
- package/dist/expressions/call.js +207 -207
- package/dist/expressions/import.d.ts +14 -14
- package/dist/expressions/import.js +155 -155
- package/dist/expressions/include.d.ts +13 -13
- package/dist/expressions/include.js +132 -132
- package/dist/expressions/list.d.ts +14 -14
- package/dist/expressions/list.js +134 -134
- package/dist/expressions/logical-and-binary.d.ts +23 -23
- package/dist/expressions/logical-and-binary.js +216 -212
- package/dist/expressions/map.d.ts +19 -19
- package/dist/expressions/map.js +190 -190
- package/dist/expressions/path.d.ts +31 -31
- package/dist/expressions/path.js +364 -364
- package/dist/index.d.ts +36 -36
- package/dist/index.js +89 -89
- package/dist/interpreter.d.ts +29 -29
- package/dist/interpreter.js +210 -210
- package/dist/operations/argument.d.ts +8 -8
- package/dist/operations/argument.js +145 -145
- package/dist/operations/body.d.ts +8 -8
- package/dist/operations/body.js +140 -140
- package/dist/operations/break.d.ts +7 -7
- package/dist/operations/break.js +34 -34
- package/dist/operations/continue.d.ts +7 -7
- package/dist/operations/continue.js +34 -34
- package/dist/operations/debugger.d.ts +7 -7
- package/dist/operations/debugger.js +32 -32
- package/dist/operations/else-if.d.ts +12 -12
- package/dist/operations/else-if.js +31 -31
- package/dist/operations/else.d.ts +10 -10
- package/dist/operations/else.js +30 -30
- package/dist/operations/for.d.ts +16 -16
- package/dist/operations/for.js +143 -143
- package/dist/operations/function.d.ts +21 -21
- package/dist/operations/function.js +133 -133
- package/dist/operations/if-statement.d.ts +8 -8
- package/dist/operations/if-statement.js +153 -153
- package/dist/operations/if.d.ts +12 -12
- package/dist/operations/if.js +31 -31
- package/dist/operations/new.d.ts +11 -11
- package/dist/operations/new.js +96 -96
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +95 -95
- package/dist/operations/reference.d.ts +11 -11
- package/dist/operations/reference.js +102 -102
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +102 -102
- package/dist/operations/while.d.ts +14 -14
- package/dist/operations/while.js +127 -127
- package/dist/resource.d.ts +9 -9
- package/dist/resource.js +29 -29
- package/dist/typer.d.ts +6 -6
- package/dist/typer.js +95 -95
- package/dist/types/custom-type.d.ts +19 -19
- package/dist/types/custom-type.js +58 -58
- package/dist/types/expression.d.ts +6 -6
- package/dist/types/expression.js +9 -9
- package/dist/types/operation.d.ts +9 -9
- package/dist/types/operation.js +38 -38
- package/package.json +45 -45
|
@@ -1,289 +1,288 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
54
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
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));
|
|
77
|
-
};
|
|
78
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
-
exports.CustomListIterator = void 0;
|
|
80
|
-
var operation_1 = require("../types/operation");
|
|
81
|
-
var custom_type_1 = require("../types/custom-type");
|
|
82
|
-
var CustomListIterator = /** @class */ (function () {
|
|
83
|
-
function CustomListIterator(value) {
|
|
84
|
-
var me = this;
|
|
85
|
-
me.value = value;
|
|
86
|
-
me.index = 0;
|
|
87
|
-
}
|
|
88
|
-
CustomListIterator.prototype.next = function () {
|
|
89
|
-
var me = this;
|
|
90
|
-
if (me.index === me.value.length) {
|
|
91
|
-
return {
|
|
92
|
-
value: null,
|
|
93
|
-
done: true
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
value: me.value[me.index++],
|
|
98
|
-
done: false
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
return CustomListIterator;
|
|
102
|
-
}());
|
|
103
|
-
exports.CustomListIterator = CustomListIterator;
|
|
104
|
-
var CustomList = /** @class */ (function (_super) {
|
|
105
|
-
__extends(CustomList, _super);
|
|
106
|
-
function CustomList(value) {
|
|
107
|
-
var _this = _super.call(this) || this;
|
|
108
|
-
_this.slice = function (a, b) {
|
|
109
|
-
return new CustomList(this.value.slice(a.valueOf(), b.valueOf()));
|
|
110
|
-
};
|
|
111
|
-
_this.value = value;
|
|
112
|
-
return _this;
|
|
113
|
-
}
|
|
114
|
-
CustomList.isNumber = function (value) {
|
|
115
|
-
return !Number.isNaN(Number(value));
|
|
116
|
-
};
|
|
117
|
-
CustomList.prototype[Symbol.iterator] = function () {
|
|
118
|
-
return new CustomListIterator(this.value);
|
|
119
|
-
};
|
|
120
|
-
CustomList.prototype.concat = function (list) {
|
|
121
|
-
return new CustomList(this.value.concat(list.value));
|
|
122
|
-
};
|
|
123
|
-
CustomList.prototype.toIndex = function (value) {
|
|
124
|
-
var me = this;
|
|
125
|
-
var casted = Number(value);
|
|
126
|
-
var result = casted < 0 ? me.value.length + casted : casted;
|
|
127
|
-
if (result < 0) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
131
|
-
};
|
|
132
|
-
CustomList.prototype.set = function (path, value) {
|
|
133
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
-
var me, traversalPath, refs, last, current, origin, index, setterIndex;
|
|
135
|
-
return __generator(this, function (_a) {
|
|
136
|
-
me = this;
|
|
137
|
-
traversalPath = [].concat(path);
|
|
138
|
-
refs = me.value;
|
|
139
|
-
last = traversalPath.pop();
|
|
140
|
-
current = traversalPath.shift();
|
|
141
|
-
origin = refs;
|
|
142
|
-
if (current != null) {
|
|
143
|
-
index = me.toIndex(current);
|
|
144
|
-
if (origin.hasOwnProperty(index)) {
|
|
145
|
-
origin = origin[index];
|
|
146
|
-
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
147
|
-
return [2 /*return*/, origin.set(traversalPath.concat([last]), value)];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (origin) {
|
|
155
|
-
setterIndex = me.toIndex(last);
|
|
156
|
-
if (!origin.hasOwnProperty(setterIndex)) {
|
|
157
|
-
throw new Error("Index error (list index ".concat(setterIndex, " out of range)"));
|
|
158
|
-
}
|
|
159
|
-
if (value instanceof operation_1.FunctionOperationBase) {
|
|
160
|
-
origin[setterIndex] = value.fork(me);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
origin[setterIndex] = value;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
168
|
-
}
|
|
169
|
-
return [2 /*return*/];
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
CustomList.prototype.get = function (path) {
|
|
174
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
-
var me, traversalPath, refs, current, currentValue, origin, index;
|
|
176
|
-
return __generator(this, function (_a) {
|
|
177
|
-
me = this;
|
|
178
|
-
if (path.length === 0) {
|
|
179
|
-
return [2 /*return*/, me];
|
|
180
|
-
}
|
|
181
|
-
traversalPath = [].concat(path);
|
|
182
|
-
refs = me.value;
|
|
183
|
-
current = traversalPath.shift();
|
|
184
|
-
currentValue = current.valueOf();
|
|
185
|
-
origin = refs;
|
|
186
|
-
if (currentValue != null) {
|
|
187
|
-
index = me.toIndex(current);
|
|
188
|
-
if (origin.hasOwnProperty(index)) {
|
|
189
|
-
origin = origin[index];
|
|
190
|
-
if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
|
|
191
|
-
return [2 /*return*/, origin.get(traversalPath)];
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
else if (path.length === 1 && CustomList.intrinsics.has(currentValue)) {
|
|
195
|
-
return [2 /*return*/, CustomList.intrinsics.get(currentValue).bind(null, me)];
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
return [2 /*return*/, null];
|
|
203
|
-
}
|
|
204
|
-
return [2 /*return*/, origin];
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
CustomList.prototype.getCallable = function (path) {
|
|
209
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
210
|
-
var me, traversalPath, refs, current, origin, context, index;
|
|
211
|
-
return __generator(this, function (_a) {
|
|
212
|
-
me = this;
|
|
213
|
-
traversalPath = [].concat(path);
|
|
214
|
-
refs = me.value;
|
|
215
|
-
current = traversalPath.shift();
|
|
216
|
-
origin = refs;
|
|
217
|
-
if (current != null) {
|
|
218
|
-
index = me.toIndex(current);
|
|
219
|
-
if (origin.hasOwnProperty(index)) {
|
|
220
|
-
context = origin;
|
|
221
|
-
origin = origin[index];
|
|
222
|
-
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
223
|
-
return [2 /*return*/, origin.getCallable(traversalPath)];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
else if (path.length === 1 && CustomList.intrinsics.has(current)) {
|
|
227
|
-
return [2 /*return*/, {
|
|
228
|
-
origin: CustomList.intrinsics.get(current).bind(null, me),
|
|
229
|
-
context: me
|
|
230
|
-
}];
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return [2 /*return*/, {
|
|
237
|
-
origin: origin,
|
|
238
|
-
context: context
|
|
239
|
-
}];
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
CustomList.prototype.callMethod = function (method) {
|
|
244
|
-
var _a;
|
|
245
|
-
var args = [];
|
|
246
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
247
|
-
args[_i - 1] = arguments[_i];
|
|
248
|
-
}
|
|
249
|
-
if (method.length === 0) {
|
|
250
|
-
throw new Error('Unexpected method length');
|
|
251
|
-
}
|
|
252
|
-
var me = this;
|
|
253
|
-
var member = method[0].valueOf();
|
|
254
|
-
if (CustomList.isNumber(member)) {
|
|
255
|
-
var index = me.toIndex(member);
|
|
256
|
-
if (!me.value.hasOwnProperty(index)) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
var me =
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
CustomList
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
exports.default = CustomList;
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
54
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
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));
|
|
77
|
+
};
|
|
78
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
+
exports.CustomListIterator = void 0;
|
|
80
|
+
var operation_1 = require("../types/operation");
|
|
81
|
+
var custom_type_1 = require("../types/custom-type");
|
|
82
|
+
var CustomListIterator = /** @class */ (function () {
|
|
83
|
+
function CustomListIterator(value) {
|
|
84
|
+
var me = this;
|
|
85
|
+
me.value = value;
|
|
86
|
+
me.index = 0;
|
|
87
|
+
}
|
|
88
|
+
CustomListIterator.prototype.next = function () {
|
|
89
|
+
var me = this;
|
|
90
|
+
if (me.index === me.value.length) {
|
|
91
|
+
return {
|
|
92
|
+
value: null,
|
|
93
|
+
done: true
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
value: me.value[me.index++],
|
|
98
|
+
done: false
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
return CustomListIterator;
|
|
102
|
+
}());
|
|
103
|
+
exports.CustomListIterator = CustomListIterator;
|
|
104
|
+
var CustomList = /** @class */ (function (_super) {
|
|
105
|
+
__extends(CustomList, _super);
|
|
106
|
+
function CustomList(value) {
|
|
107
|
+
var _this = _super.call(this) || this;
|
|
108
|
+
_this.slice = function (a, b) {
|
|
109
|
+
return new CustomList(this.value.slice(a === null || a === void 0 ? void 0 : a.valueOf(), b === null || b === void 0 ? void 0 : b.valueOf()));
|
|
110
|
+
};
|
|
111
|
+
_this.value = value;
|
|
112
|
+
return _this;
|
|
113
|
+
}
|
|
114
|
+
CustomList.isNumber = function (value) {
|
|
115
|
+
return !Number.isNaN(Number(value));
|
|
116
|
+
};
|
|
117
|
+
CustomList.prototype[Symbol.iterator] = function () {
|
|
118
|
+
return new CustomListIterator(this.value);
|
|
119
|
+
};
|
|
120
|
+
CustomList.prototype.concat = function (list) {
|
|
121
|
+
return new CustomList(this.value.concat(list.value));
|
|
122
|
+
};
|
|
123
|
+
CustomList.prototype.toIndex = function (value) {
|
|
124
|
+
var me = this;
|
|
125
|
+
var casted = Number(value);
|
|
126
|
+
var result = casted < 0 ? me.value.length + casted : casted;
|
|
127
|
+
if (result < 0) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
CustomList.prototype.set = function (path, value) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var me, traversalPath, refs, last, current, origin, index, setterIndex;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
me = this;
|
|
137
|
+
traversalPath = [].concat(path);
|
|
138
|
+
refs = me.value;
|
|
139
|
+
last = traversalPath.pop();
|
|
140
|
+
current = traversalPath.shift();
|
|
141
|
+
origin = refs;
|
|
142
|
+
if (current != null) {
|
|
143
|
+
index = me.toIndex(current);
|
|
144
|
+
if (origin.hasOwnProperty(index)) {
|
|
145
|
+
origin = origin[index];
|
|
146
|
+
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
147
|
+
return [2 /*return*/, origin.set(traversalPath.concat([last]), value)];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (origin) {
|
|
155
|
+
setterIndex = me.toIndex(last);
|
|
156
|
+
if (!origin.hasOwnProperty(setterIndex)) {
|
|
157
|
+
throw new Error("Index error (list index ".concat(setterIndex, " out of range)"));
|
|
158
|
+
}
|
|
159
|
+
if (value instanceof operation_1.FunctionOperationBase) {
|
|
160
|
+
origin[setterIndex] = value.fork(me);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
origin[setterIndex] = value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
168
|
+
}
|
|
169
|
+
return [2 /*return*/];
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
CustomList.prototype.get = function (path) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var me, traversalPath, refs, current, currentValue, origin, index;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
me = this;
|
|
178
|
+
if (path.length === 0) {
|
|
179
|
+
return [2 /*return*/, me];
|
|
180
|
+
}
|
|
181
|
+
traversalPath = [].concat(path);
|
|
182
|
+
refs = me.value;
|
|
183
|
+
current = traversalPath.shift();
|
|
184
|
+
currentValue = current.valueOf();
|
|
185
|
+
origin = refs;
|
|
186
|
+
if (currentValue != null) {
|
|
187
|
+
index = me.toIndex(current);
|
|
188
|
+
if (origin.hasOwnProperty(index)) {
|
|
189
|
+
origin = origin[index];
|
|
190
|
+
if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
|
|
191
|
+
return [2 /*return*/, origin.get(traversalPath)];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else if (path.length === 1 && CustomList.intrinsics.has(currentValue)) {
|
|
195
|
+
return [2 /*return*/, CustomList.intrinsics.get(currentValue).bind(null, me)];
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
return [2 /*return*/, null];
|
|
203
|
+
}
|
|
204
|
+
return [2 /*return*/, origin];
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
CustomList.prototype.getCallable = function (path) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
210
|
+
var me, traversalPath, refs, current, origin, context, index;
|
|
211
|
+
return __generator(this, function (_a) {
|
|
212
|
+
me = this;
|
|
213
|
+
traversalPath = [].concat(path);
|
|
214
|
+
refs = me.value;
|
|
215
|
+
current = traversalPath.shift();
|
|
216
|
+
origin = refs;
|
|
217
|
+
if (current != null) {
|
|
218
|
+
index = me.toIndex(current);
|
|
219
|
+
if (origin.hasOwnProperty(index)) {
|
|
220
|
+
context = origin;
|
|
221
|
+
origin = origin[index];
|
|
222
|
+
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
223
|
+
return [2 /*return*/, origin.getCallable(traversalPath)];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (path.length === 1 && CustomList.intrinsics.has(current)) {
|
|
227
|
+
return [2 /*return*/, {
|
|
228
|
+
origin: CustomList.intrinsics.get(current).bind(null, me),
|
|
229
|
+
context: me
|
|
230
|
+
}];
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return [2 /*return*/, {
|
|
237
|
+
origin: origin,
|
|
238
|
+
context: context
|
|
239
|
+
}];
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
CustomList.prototype.callMethod = function (method) {
|
|
244
|
+
var _a;
|
|
245
|
+
var args = [];
|
|
246
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
247
|
+
args[_i - 1] = arguments[_i];
|
|
248
|
+
}
|
|
249
|
+
if (method.length === 0) {
|
|
250
|
+
throw new Error('Unexpected method length');
|
|
251
|
+
}
|
|
252
|
+
var me = this;
|
|
253
|
+
var member = method[0].valueOf();
|
|
254
|
+
if (CustomList.isNumber(member)) {
|
|
255
|
+
var index = me.toIndex(member);
|
|
256
|
+
if (!me.value.hasOwnProperty(index)) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
if (method.length > 1) {
|
|
260
|
+
return (_a = me.value[index]).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
|
|
261
|
+
}
|
|
262
|
+
return me.value[index];
|
|
263
|
+
}
|
|
264
|
+
if (!CustomList.intrinsics.has(member)) {
|
|
265
|
+
throw new Error("Cannot access ".concat(member, " in list"));
|
|
266
|
+
}
|
|
267
|
+
return CustomList.intrinsics.get(member).apply(void 0, __spreadArray([me], __read(args), false));
|
|
268
|
+
};
|
|
269
|
+
CustomList.prototype.getType = function () {
|
|
270
|
+
return 'list';
|
|
271
|
+
};
|
|
272
|
+
CustomList.prototype.valueOf = function () {
|
|
273
|
+
var me = this;
|
|
274
|
+
var value = me.value;
|
|
275
|
+
return value.length === 0 ? null : me;
|
|
276
|
+
};
|
|
277
|
+
CustomList.prototype.toString = function () {
|
|
278
|
+
var me = this;
|
|
279
|
+
var body = me.value.map(function (item) { var _a; return (_a = item === null || item === void 0 ? void 0 : item.valueOf()) === null || _a === void 0 ? void 0 : _a.toString(); });
|
|
280
|
+
return "[".concat(body.join(','), "]");
|
|
281
|
+
};
|
|
282
|
+
CustomList.prototype.fork = function () {
|
|
283
|
+
return new CustomList(this.value);
|
|
284
|
+
};
|
|
285
|
+
CustomList.intrinsics = new Map();
|
|
286
|
+
return CustomList;
|
|
287
|
+
}(custom_type_1.CustomObjectType));
|
|
288
|
+
exports.default = CustomList;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { CustomObjectType, Callable } from '../types/custom-type';
|
|
2
|
-
export interface CustomMapIterableItem {
|
|
3
|
-
key: string;
|
|
4
|
-
value: any;
|
|
5
|
-
}
|
|
6
|
-
export declare class CustomMapIterator implements Iterator<CustomMapIterableItem> {
|
|
7
|
-
value: any;
|
|
8
|
-
index: number;
|
|
9
|
-
constructor(value: any);
|
|
10
|
-
next(): IteratorResult<CustomMapIterableItem>;
|
|
11
|
-
}
|
|
12
|
-
export default class CustomMap extends CustomObjectType implements Iterable<CustomMapIterableItem> {
|
|
13
|
-
static intrinsics: Map<string, Function>;
|
|
14
|
-
value: Map<string, any>;
|
|
15
|
-
isInstance: boolean;
|
|
16
|
-
constructor(value?: Map<string, any>);
|
|
17
|
-
[Symbol.iterator](): CustomMapIterator;
|
|
18
|
-
extend(value: Map<string, any>): CustomMap;
|
|
19
|
-
set(path: string[], value: any): Promise<void>;
|
|
20
|
-
get(path: string[]): Promise<any>;
|
|
21
|
-
getCallable(path: string[]): Promise<Callable>;
|
|
22
|
-
callMethod(method: string[], ...args: any[]): any;
|
|
23
|
-
createInstance(): CustomMap;
|
|
24
|
-
getType(): string;
|
|
25
|
-
valueOf(): CustomMap | null;
|
|
26
|
-
toString(): string;
|
|
27
|
-
fork(): CustomMap;
|
|
28
|
-
}
|
|
1
|
+
import { CustomObjectType, Callable } from '../types/custom-type';
|
|
2
|
+
export interface CustomMapIterableItem {
|
|
3
|
+
key: string;
|
|
4
|
+
value: any;
|
|
5
|
+
}
|
|
6
|
+
export declare class CustomMapIterator implements Iterator<CustomMapIterableItem> {
|
|
7
|
+
value: any;
|
|
8
|
+
index: number;
|
|
9
|
+
constructor(value: any);
|
|
10
|
+
next(): IteratorResult<CustomMapIterableItem>;
|
|
11
|
+
}
|
|
12
|
+
export default class CustomMap extends CustomObjectType implements Iterable<CustomMapIterableItem> {
|
|
13
|
+
static intrinsics: Map<string, Function>;
|
|
14
|
+
value: Map<string, any>;
|
|
15
|
+
isInstance: boolean;
|
|
16
|
+
constructor(value?: Map<string, any>);
|
|
17
|
+
[Symbol.iterator](): CustomMapIterator;
|
|
18
|
+
extend(value: Map<string, any>): CustomMap;
|
|
19
|
+
set(path: string[], value: any): Promise<void>;
|
|
20
|
+
get(path: string[]): Promise<any>;
|
|
21
|
+
getCallable(path: string[]): Promise<Callable>;
|
|
22
|
+
callMethod(method: string[], ...args: any[]): any;
|
|
23
|
+
createInstance(): CustomMap;
|
|
24
|
+
getType(): string;
|
|
25
|
+
valueOf(): CustomMap | null;
|
|
26
|
+
toString(): string;
|
|
27
|
+
fork(): CustomMap;
|
|
28
|
+
}
|