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