greybel-interpreter 1.0.4 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +14 -14
- package/.eslintrc +47 -47
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +109 -109
- package/dist/context.js +378 -378
- package/dist/cps.d.ts +14 -15
- package/dist/cps.js +213 -220
- package/dist/handler/error.d.ts +6 -6
- package/dist/handler/error.js +35 -35
- package/dist/handler/output.d.ts +6 -6
- package/dist/handler/output.js +35 -35
- package/dist/handler/resource.d.ts +12 -12
- package/dist/handler/resource.js +51 -51
- package/dist/handler-container.d.ts +14 -14
- package/dist/handler-container.js +16 -16
- package/dist/index.d.ts +44 -44
- package/dist/index.js +129 -129
- package/dist/interpreter.d.ts +39 -39
- package/dist/interpreter.js +292 -292
- package/dist/intrinsics-container.d.ts +7 -7
- package/dist/intrinsics-container.js +19 -19
- package/dist/operations/assign.d.ts +13 -13
- package/dist/operations/assign.js +111 -111
- package/dist/operations/block.d.ts +12 -12
- package/dist/operations/block.js +108 -108
- package/dist/operations/break.d.ts +10 -10
- package/dist/operations/break.js +41 -41
- package/dist/operations/call.d.ts +13 -13
- package/dist/operations/call.js +124 -124
- package/dist/operations/chunk.d.ts +12 -12
- package/dist/operations/chunk.js +85 -85
- package/dist/operations/continue.d.ts +10 -10
- package/dist/operations/continue.js +41 -41
- package/dist/operations/debugger-statement.d.ts +10 -10
- package/dist/operations/debugger-statement.js +39 -39
- package/dist/operations/evaluate.d.ts +39 -39
- package/dist/operations/evaluate.js +366 -366
- package/dist/operations/for.d.ts +15 -15
- package/dist/operations/for.js +152 -146
- package/dist/operations/function-reference.d.ts +12 -12
- package/dist/operations/function-reference.js +103 -103
- package/dist/operations/function.d.ts +12 -12
- package/dist/operations/function.js +198 -198
- package/dist/operations/if-statement.d.ts +19 -19
- package/dist/operations/if-statement.js +181 -181
- package/dist/operations/import.d.ts +14 -14
- package/dist/operations/import.js +115 -115
- package/dist/operations/include.d.ts +13 -13
- package/dist/operations/include.js +95 -95
- package/dist/operations/list.d.ts +11 -11
- package/dist/operations/list.js +111 -111
- package/dist/operations/literal.d.ts +11 -11
- package/dist/operations/literal.js +58 -58
- package/dist/operations/map.d.ts +11 -11
- package/dist/operations/map.js +167 -167
- package/dist/operations/negated-binary.d.ts +11 -11
- package/dist/operations/negated-binary.js +109 -109
- package/dist/operations/new-instance.d.ts +11 -11
- package/dist/operations/new-instance.js +100 -100
- package/dist/operations/noop.d.ts +9 -9
- package/dist/operations/noop.js +36 -36
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -13
- package/dist/operations/operation.js +11 -11
- package/dist/operations/reference.d.ts +9 -9
- package/dist/operations/reference.js +37 -37
- package/dist/operations/resolve.d.ts +38 -38
- package/dist/operations/resolve.js +330 -330
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +107 -107
- package/dist/operations/while.d.ts +13 -13
- package/dist/operations/while.js +136 -129
- package/dist/types/boolean.d.ts +11 -11
- package/dist/types/boolean.js +46 -46
- package/dist/types/default.d.ts +11 -11
- package/dist/types/default.js +20 -20
- package/dist/types/function.d.ts +32 -32
- package/dist/types/function.js +174 -174
- package/dist/types/generics.d.ts +17 -17
- package/dist/types/generics.js +40 -40
- package/dist/types/interface.d.ts +22 -22
- package/dist/types/interface.js +102 -102
- package/dist/types/list.d.ts +31 -31
- package/dist/types/list.js +227 -227
- package/dist/types/map.d.ts +30 -30
- package/dist/types/map.js +224 -224
- package/dist/types/nil.d.ts +9 -9
- package/dist/types/nil.js +44 -44
- package/dist/types/number.d.ts +11 -11
- package/dist/types/number.js +46 -46
- package/dist/types/string.d.ts +33 -33
- package/dist/types/string.js +149 -149
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +59 -59
- package/package.json +58 -58
package/dist/types/list.js
CHANGED
|
@@ -1,227 +1,227 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
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;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
-
};
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.CustomListIterator = void 0;
|
|
47
|
-
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
48
|
-
var path_1 = __importDefault(require("../utils/path"));
|
|
49
|
-
var generics_1 = require("./generics");
|
|
50
|
-
var CustomListIterator = /** @class */ (function () {
|
|
51
|
-
function CustomListIterator(value) {
|
|
52
|
-
var me = this;
|
|
53
|
-
me.value = value;
|
|
54
|
-
me.index = 0;
|
|
55
|
-
}
|
|
56
|
-
CustomListIterator.prototype.next = function () {
|
|
57
|
-
var me = this;
|
|
58
|
-
if (me.index === me.value.length) {
|
|
59
|
-
return {
|
|
60
|
-
value: null,
|
|
61
|
-
done: true
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
value: me.value[me.index++],
|
|
66
|
-
done: false
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
return CustomListIterator;
|
|
70
|
-
}());
|
|
71
|
-
exports.CustomListIterator = CustomListIterator;
|
|
72
|
-
var CustomList = /** @class */ (function (_super) {
|
|
73
|
-
__extends(CustomList, _super);
|
|
74
|
-
function CustomList(value) {
|
|
75
|
-
if (value === void 0) { value = []; }
|
|
76
|
-
var _this = _super.call(this) || this;
|
|
77
|
-
_this.value = __spreadArray([], __read(value), false);
|
|
78
|
-
return _this;
|
|
79
|
-
}
|
|
80
|
-
CustomList.getItemIndex = function (item, index) {
|
|
81
|
-
var n = index | 0;
|
|
82
|
-
if (n < 0)
|
|
83
|
-
n += item.value.length;
|
|
84
|
-
if (n < 0 || n >= item.value.length)
|
|
85
|
-
return -1;
|
|
86
|
-
return n;
|
|
87
|
-
};
|
|
88
|
-
CustomList.getIntrinsics = function () {
|
|
89
|
-
return this.intrinsics;
|
|
90
|
-
};
|
|
91
|
-
CustomList.addIntrinsic = function (name, fn) {
|
|
92
|
-
this.intrinsics.add(name, fn);
|
|
93
|
-
};
|
|
94
|
-
CustomList.prototype.getCustomType = function () {
|
|
95
|
-
return 'list';
|
|
96
|
-
};
|
|
97
|
-
CustomList.prototype.toString = function () {
|
|
98
|
-
return "[ ".concat(this.value.join(', '), " ]");
|
|
99
|
-
};
|
|
100
|
-
CustomList.prototype.fork = function () {
|
|
101
|
-
return new CustomList(this.value);
|
|
102
|
-
};
|
|
103
|
-
CustomList.prototype.toNumber = function () {
|
|
104
|
-
return 0;
|
|
105
|
-
};
|
|
106
|
-
CustomList.prototype.toInt = function () {
|
|
107
|
-
return 0;
|
|
108
|
-
};
|
|
109
|
-
CustomList.prototype.toTruthy = function () {
|
|
110
|
-
return this.value.length > 0;
|
|
111
|
-
};
|
|
112
|
-
CustomList.prototype.slice = function (a, b) {
|
|
113
|
-
return new CustomList(this.value.slice(a.toNumber(), b.toNumber()));
|
|
114
|
-
};
|
|
115
|
-
CustomList.prototype.extend = function (list) {
|
|
116
|
-
if (list instanceof CustomList) {
|
|
117
|
-
list = list.value;
|
|
118
|
-
}
|
|
119
|
-
for (var index = 0; index < list.length; index++) {
|
|
120
|
-
this.value.push(list[index]);
|
|
121
|
-
}
|
|
122
|
-
return this;
|
|
123
|
-
};
|
|
124
|
-
CustomList.prototype[Symbol.iterator] = function () {
|
|
125
|
-
return new CustomListIterator(this.value);
|
|
126
|
-
};
|
|
127
|
-
CustomList.prototype.getItemIndex = function (index) {
|
|
128
|
-
return CustomList.getItemIndex(this, index);
|
|
129
|
-
};
|
|
130
|
-
CustomList.prototype.has = function (path) {
|
|
131
|
-
if (typeof path === 'string') {
|
|
132
|
-
return this.has(new path_1.default([path]));
|
|
133
|
-
}
|
|
134
|
-
var traversalPath = path.clone();
|
|
135
|
-
var current = traversalPath.next();
|
|
136
|
-
if (current !== null) {
|
|
137
|
-
var currentIndex = parseInt(current);
|
|
138
|
-
var isCurrentNumber = !Number.isNaN(currentIndex);
|
|
139
|
-
if (isCurrentNumber) {
|
|
140
|
-
currentIndex = this.getItemIndex(currentIndex);
|
|
141
|
-
}
|
|
142
|
-
if (isCurrentNumber) {
|
|
143
|
-
var sub = this.value[currentIndex];
|
|
144
|
-
if (traversalPath.count() > 0 &&
|
|
145
|
-
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
146
|
-
return sub.has(traversalPath);
|
|
147
|
-
}
|
|
148
|
-
return traversalPath.count() === 0;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
};
|
|
153
|
-
CustomList.prototype.set = function (path, newValue) {
|
|
154
|
-
if (typeof path === 'string') {
|
|
155
|
-
return this.set(new path_1.default([path]), newValue);
|
|
156
|
-
}
|
|
157
|
-
var traversalPath = path.clone();
|
|
158
|
-
var last = traversalPath.last();
|
|
159
|
-
var current = traversalPath.next();
|
|
160
|
-
if (current !== null) {
|
|
161
|
-
var currentIndex = parseInt(current);
|
|
162
|
-
var isCurrentNumber = !Number.isNaN(currentIndex);
|
|
163
|
-
if (isCurrentNumber) {
|
|
164
|
-
currentIndex = this.getItemIndex(currentIndex);
|
|
165
|
-
}
|
|
166
|
-
if (isCurrentNumber &&
|
|
167
|
-
currentIndex >= 0 &&
|
|
168
|
-
currentIndex < this.value.length) {
|
|
169
|
-
var sub = this.value[currentIndex];
|
|
170
|
-
if (traversalPath.count() > 0 &&
|
|
171
|
-
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
172
|
-
sub.set(traversalPath, newValue);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
177
|
-
}
|
|
178
|
-
var lastIndex = parseInt(last);
|
|
179
|
-
var isLastNumber = !Number.isNaN(lastIndex);
|
|
180
|
-
if (isLastNumber) {
|
|
181
|
-
lastIndex = this.getItemIndex(lastIndex);
|
|
182
|
-
}
|
|
183
|
-
if (isLastNumber && lastIndex >= 0 && lastIndex < this.value.length) {
|
|
184
|
-
this.value[lastIndex] = newValue;
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
throw new Error("Index error (list index ".concat(lastIndex, " out of range)."));
|
|
188
|
-
};
|
|
189
|
-
CustomList.prototype.get = function (path) {
|
|
190
|
-
if (typeof path === 'string') {
|
|
191
|
-
return this.get(new path_1.default([path]));
|
|
192
|
-
}
|
|
193
|
-
var traversalPath = path.clone();
|
|
194
|
-
var current = traversalPath.next();
|
|
195
|
-
if (current !== null) {
|
|
196
|
-
var currentIndex = parseInt(current);
|
|
197
|
-
var isCurrentNumber = !Number.isNaN(currentIndex);
|
|
198
|
-
if (isCurrentNumber) {
|
|
199
|
-
currentIndex = this.getItemIndex(currentIndex);
|
|
200
|
-
}
|
|
201
|
-
if (isCurrentNumber &&
|
|
202
|
-
currentIndex >= 0 &&
|
|
203
|
-
currentIndex < this.value.length) {
|
|
204
|
-
var sub = this.value[currentIndex];
|
|
205
|
-
if (traversalPath.count() > 0) {
|
|
206
|
-
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
207
|
-
return sub.get(traversalPath);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else if (traversalPath.count() === 0) {
|
|
211
|
-
return sub;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else if (path.count() === 1 &&
|
|
215
|
-
CustomList.getIntrinsics().has(current)) {
|
|
216
|
-
return CustomList.getIntrinsics().get(current);
|
|
217
|
-
}
|
|
218
|
-
if (isCurrentNumber) {
|
|
219
|
-
throw new Error("Index error (list index ".concat(currentIndex, " out of range)."));
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
throw new Error("Unknown path in list ".concat(path.toString(), "."));
|
|
223
|
-
};
|
|
224
|
-
CustomList.intrinsics = new intrinsics_container_1.default();
|
|
225
|
-
return CustomList;
|
|
226
|
-
}(generics_1.CustomObject));
|
|
227
|
-
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 __read = (this && this.__read) || function (o, n) {
|
|
18
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
+
if (!m) return o;
|
|
20
|
+
var i = m.call(o), r, ar = [], e;
|
|
21
|
+
try {
|
|
22
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
+
}
|
|
24
|
+
catch (error) { e = { error: error }; }
|
|
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;
|
|
32
|
+
};
|
|
33
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
+
if (ar || !(i in from)) {
|
|
36
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
+
ar[i] = from[i];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
+
};
|
|
42
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
|
+
};
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.CustomListIterator = void 0;
|
|
47
|
+
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
48
|
+
var path_1 = __importDefault(require("../utils/path"));
|
|
49
|
+
var generics_1 = require("./generics");
|
|
50
|
+
var CustomListIterator = /** @class */ (function () {
|
|
51
|
+
function CustomListIterator(value) {
|
|
52
|
+
var me = this;
|
|
53
|
+
me.value = value;
|
|
54
|
+
me.index = 0;
|
|
55
|
+
}
|
|
56
|
+
CustomListIterator.prototype.next = function () {
|
|
57
|
+
var me = this;
|
|
58
|
+
if (me.index === me.value.length) {
|
|
59
|
+
return {
|
|
60
|
+
value: null,
|
|
61
|
+
done: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
value: me.value[me.index++],
|
|
66
|
+
done: false
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
return CustomListIterator;
|
|
70
|
+
}());
|
|
71
|
+
exports.CustomListIterator = CustomListIterator;
|
|
72
|
+
var CustomList = /** @class */ (function (_super) {
|
|
73
|
+
__extends(CustomList, _super);
|
|
74
|
+
function CustomList(value) {
|
|
75
|
+
if (value === void 0) { value = []; }
|
|
76
|
+
var _this = _super.call(this) || this;
|
|
77
|
+
_this.value = __spreadArray([], __read(value), false);
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
CustomList.getItemIndex = function (item, index) {
|
|
81
|
+
var n = index | 0;
|
|
82
|
+
if (n < 0)
|
|
83
|
+
n += item.value.length;
|
|
84
|
+
if (n < 0 || n >= item.value.length)
|
|
85
|
+
return -1;
|
|
86
|
+
return n;
|
|
87
|
+
};
|
|
88
|
+
CustomList.getIntrinsics = function () {
|
|
89
|
+
return this.intrinsics;
|
|
90
|
+
};
|
|
91
|
+
CustomList.addIntrinsic = function (name, fn) {
|
|
92
|
+
this.intrinsics.add(name, fn);
|
|
93
|
+
};
|
|
94
|
+
CustomList.prototype.getCustomType = function () {
|
|
95
|
+
return 'list';
|
|
96
|
+
};
|
|
97
|
+
CustomList.prototype.toString = function () {
|
|
98
|
+
return "[ ".concat(this.value.join(', '), " ]");
|
|
99
|
+
};
|
|
100
|
+
CustomList.prototype.fork = function () {
|
|
101
|
+
return new CustomList(this.value);
|
|
102
|
+
};
|
|
103
|
+
CustomList.prototype.toNumber = function () {
|
|
104
|
+
return 0;
|
|
105
|
+
};
|
|
106
|
+
CustomList.prototype.toInt = function () {
|
|
107
|
+
return 0;
|
|
108
|
+
};
|
|
109
|
+
CustomList.prototype.toTruthy = function () {
|
|
110
|
+
return this.value.length > 0;
|
|
111
|
+
};
|
|
112
|
+
CustomList.prototype.slice = function (a, b) {
|
|
113
|
+
return new CustomList(this.value.slice(a.toNumber(), b.toNumber()));
|
|
114
|
+
};
|
|
115
|
+
CustomList.prototype.extend = function (list) {
|
|
116
|
+
if (list instanceof CustomList) {
|
|
117
|
+
list = list.value;
|
|
118
|
+
}
|
|
119
|
+
for (var index = 0; index < list.length; index++) {
|
|
120
|
+
this.value.push(list[index]);
|
|
121
|
+
}
|
|
122
|
+
return this;
|
|
123
|
+
};
|
|
124
|
+
CustomList.prototype[Symbol.iterator] = function () {
|
|
125
|
+
return new CustomListIterator(this.value);
|
|
126
|
+
};
|
|
127
|
+
CustomList.prototype.getItemIndex = function (index) {
|
|
128
|
+
return CustomList.getItemIndex(this, index);
|
|
129
|
+
};
|
|
130
|
+
CustomList.prototype.has = function (path) {
|
|
131
|
+
if (typeof path === 'string') {
|
|
132
|
+
return this.has(new path_1.default([path]));
|
|
133
|
+
}
|
|
134
|
+
var traversalPath = path.clone();
|
|
135
|
+
var current = traversalPath.next();
|
|
136
|
+
if (current !== null) {
|
|
137
|
+
var currentIndex = parseInt(current);
|
|
138
|
+
var isCurrentNumber = !Number.isNaN(currentIndex);
|
|
139
|
+
if (isCurrentNumber) {
|
|
140
|
+
currentIndex = this.getItemIndex(currentIndex);
|
|
141
|
+
}
|
|
142
|
+
if (isCurrentNumber) {
|
|
143
|
+
var sub = this.value[currentIndex];
|
|
144
|
+
if (traversalPath.count() > 0 &&
|
|
145
|
+
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
146
|
+
return sub.has(traversalPath);
|
|
147
|
+
}
|
|
148
|
+
return traversalPath.count() === 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
};
|
|
153
|
+
CustomList.prototype.set = function (path, newValue) {
|
|
154
|
+
if (typeof path === 'string') {
|
|
155
|
+
return this.set(new path_1.default([path]), newValue);
|
|
156
|
+
}
|
|
157
|
+
var traversalPath = path.clone();
|
|
158
|
+
var last = traversalPath.last();
|
|
159
|
+
var current = traversalPath.next();
|
|
160
|
+
if (current !== null) {
|
|
161
|
+
var currentIndex = parseInt(current);
|
|
162
|
+
var isCurrentNumber = !Number.isNaN(currentIndex);
|
|
163
|
+
if (isCurrentNumber) {
|
|
164
|
+
currentIndex = this.getItemIndex(currentIndex);
|
|
165
|
+
}
|
|
166
|
+
if (isCurrentNumber &&
|
|
167
|
+
currentIndex >= 0 &&
|
|
168
|
+
currentIndex < this.value.length) {
|
|
169
|
+
var sub = this.value[currentIndex];
|
|
170
|
+
if (traversalPath.count() > 0 &&
|
|
171
|
+
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
172
|
+
sub.set(traversalPath, newValue);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
177
|
+
}
|
|
178
|
+
var lastIndex = parseInt(last);
|
|
179
|
+
var isLastNumber = !Number.isNaN(lastIndex);
|
|
180
|
+
if (isLastNumber) {
|
|
181
|
+
lastIndex = this.getItemIndex(lastIndex);
|
|
182
|
+
}
|
|
183
|
+
if (isLastNumber && lastIndex >= 0 && lastIndex < this.value.length) {
|
|
184
|
+
this.value[lastIndex] = newValue;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
throw new Error("Index error (list index ".concat(lastIndex, " out of range)."));
|
|
188
|
+
};
|
|
189
|
+
CustomList.prototype.get = function (path) {
|
|
190
|
+
if (typeof path === 'string') {
|
|
191
|
+
return this.get(new path_1.default([path]));
|
|
192
|
+
}
|
|
193
|
+
var traversalPath = path.clone();
|
|
194
|
+
var current = traversalPath.next();
|
|
195
|
+
if (current !== null) {
|
|
196
|
+
var currentIndex = parseInt(current);
|
|
197
|
+
var isCurrentNumber = !Number.isNaN(currentIndex);
|
|
198
|
+
if (isCurrentNumber) {
|
|
199
|
+
currentIndex = this.getItemIndex(currentIndex);
|
|
200
|
+
}
|
|
201
|
+
if (isCurrentNumber &&
|
|
202
|
+
currentIndex >= 0 &&
|
|
203
|
+
currentIndex < this.value.length) {
|
|
204
|
+
var sub = this.value[currentIndex];
|
|
205
|
+
if (traversalPath.count() > 0) {
|
|
206
|
+
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
207
|
+
return sub.get(traversalPath);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (traversalPath.count() === 0) {
|
|
211
|
+
return sub;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else if (path.count() === 1 &&
|
|
215
|
+
CustomList.getIntrinsics().has(current)) {
|
|
216
|
+
return CustomList.getIntrinsics().get(current);
|
|
217
|
+
}
|
|
218
|
+
if (isCurrentNumber) {
|
|
219
|
+
throw new Error("Index error (list index ".concat(currentIndex, " out of range)."));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
throw new Error("Unknown path in list ".concat(path.toString(), "."));
|
|
223
|
+
};
|
|
224
|
+
CustomList.intrinsics = new intrinsics_container_1.default();
|
|
225
|
+
return CustomList;
|
|
226
|
+
}(generics_1.CustomObject));
|
|
227
|
+
exports.default = CustomList;
|
package/dist/types/map.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import IntrinsicsContainer from '../intrinsics-container';
|
|
2
|
-
import Path from '../utils/path';
|
|
3
|
-
import CustomFunction from './function';
|
|
4
|
-
import { CustomObject, CustomValue } from './generics';
|
|
5
|
-
export declare class CustomMapIterator implements Iterator<CustomValue> {
|
|
6
|
-
value: Map<string, CustomValue>;
|
|
7
|
-
index: number;
|
|
8
|
-
constructor(value: Map<string, CustomValue>);
|
|
9
|
-
next(): IteratorResult<CustomMap>;
|
|
10
|
-
}
|
|
11
|
-
export default class CustomMap extends CustomObject {
|
|
12
|
-
private static intrinsics;
|
|
13
|
-
static getIntrinsics(): IntrinsicsContainer;
|
|
14
|
-
static addIntrinsic(name: string, fn: CustomFunction): void;
|
|
15
|
-
readonly value: Map<string, CustomValue>;
|
|
16
|
-
private isInstance;
|
|
17
|
-
constructor(value?: Map<string, CustomValue>);
|
|
18
|
-
getCustomType(): string;
|
|
19
|
-
toString(): string;
|
|
20
|
-
fork(): CustomMap;
|
|
21
|
-
toNumber(): number;
|
|
22
|
-
toInt(): number;
|
|
23
|
-
toTruthy(): boolean;
|
|
24
|
-
[Symbol.iterator](): CustomMapIterator;
|
|
25
|
-
extend(map: CustomMap | Map<string, CustomValue>): CustomMap;
|
|
26
|
-
has(path: Path<string> | string): boolean;
|
|
27
|
-
set(path: Path<string> | string, newValue: CustomValue): void;
|
|
28
|
-
get(path: Path<string> | string): CustomValue;
|
|
29
|
-
createInstance(): CustomMap;
|
|
30
|
-
}
|
|
1
|
+
import IntrinsicsContainer from '../intrinsics-container';
|
|
2
|
+
import Path from '../utils/path';
|
|
3
|
+
import CustomFunction from './function';
|
|
4
|
+
import { CustomObject, CustomValue } from './generics';
|
|
5
|
+
export declare class CustomMapIterator implements Iterator<CustomValue> {
|
|
6
|
+
value: Map<string, CustomValue>;
|
|
7
|
+
index: number;
|
|
8
|
+
constructor(value: Map<string, CustomValue>);
|
|
9
|
+
next(): IteratorResult<CustomMap>;
|
|
10
|
+
}
|
|
11
|
+
export default class CustomMap extends CustomObject {
|
|
12
|
+
private static intrinsics;
|
|
13
|
+
static getIntrinsics(): IntrinsicsContainer;
|
|
14
|
+
static addIntrinsic(name: string, fn: CustomFunction): void;
|
|
15
|
+
readonly value: Map<string, CustomValue>;
|
|
16
|
+
private isInstance;
|
|
17
|
+
constructor(value?: Map<string, CustomValue>);
|
|
18
|
+
getCustomType(): string;
|
|
19
|
+
toString(): string;
|
|
20
|
+
fork(): CustomMap;
|
|
21
|
+
toNumber(): number;
|
|
22
|
+
toInt(): number;
|
|
23
|
+
toTruthy(): boolean;
|
|
24
|
+
[Symbol.iterator](): CustomMapIterator;
|
|
25
|
+
extend(map: CustomMap | Map<string, CustomValue>): CustomMap;
|
|
26
|
+
has(path: Path<string> | string): boolean;
|
|
27
|
+
set(path: Path<string> | string, newValue: CustomValue): void;
|
|
28
|
+
get(path: Path<string> | string): CustomValue;
|
|
29
|
+
createInstance(): CustomMap;
|
|
30
|
+
}
|