greybel-interpreter 0.7.2 → 1.0.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 +15 -0
- package/.eslintrc +48 -0
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +109 -98
- package/dist/context.js +378 -456
- package/dist/cps.d.ts +15 -17
- package/dist/cps.js +220 -872
- package/dist/handler/error.d.ts +6 -0
- package/dist/{operations/debugger.js → handler/error.js} +35 -32
- package/dist/handler/output.d.ts +6 -0
- package/dist/{operations/if.js → handler/output.js} +35 -31
- package/dist/handler/resource.d.ts +12 -0
- package/dist/handler/resource.js +51 -0
- package/dist/handler-container.d.ts +14 -0
- package/dist/handler-container.js +16 -0
- package/dist/index.d.ts +44 -36
- package/dist/index.js +129 -93
- package/dist/interpreter.d.ts +39 -29
- package/dist/interpreter.js +292 -210
- package/dist/intrinsics-container.d.ts +7 -0
- package/dist/intrinsics-container.js +19 -0
- package/dist/operations/assign.d.ts +13 -0
- package/dist/operations/assign.js +111 -0
- package/dist/operations/block.d.ts +12 -0
- package/dist/operations/{body.js → block.js} +108 -140
- package/dist/operations/break.d.ts +10 -7
- package/dist/operations/break.js +41 -34
- package/dist/operations/call.d.ts +13 -0
- package/dist/operations/call.js +124 -0
- package/dist/operations/chunk.d.ts +12 -0
- package/dist/operations/chunk.js +85 -0
- package/dist/operations/continue.d.ts +10 -7
- package/dist/operations/continue.js +41 -34
- package/dist/operations/debugger-statement.d.ts +10 -0
- package/dist/operations/{else-if.js → debugger-statement.js} +39 -31
- package/dist/operations/evaluate.d.ts +39 -0
- package/dist/operations/evaluate.js +366 -0
- package/dist/operations/for.d.ts +15 -16
- package/dist/operations/for.js +146 -143
- package/dist/operations/function-reference.d.ts +12 -0
- package/dist/operations/function-reference.js +103 -0
- package/dist/operations/function.d.ts +12 -26
- package/dist/operations/function.js +198 -145
- package/dist/operations/if-statement.d.ts +19 -8
- package/dist/operations/if-statement.js +181 -169
- package/dist/operations/import.d.ts +14 -0
- package/dist/{expressions/include.js → operations/import.js} +115 -132
- package/dist/operations/include.d.ts +13 -0
- package/dist/operations/include.js +95 -0
- package/dist/operations/list.d.ts +11 -0
- package/dist/{expressions → operations}/list.js +111 -142
- package/dist/operations/literal.d.ts +11 -0
- package/dist/operations/literal.js +58 -0
- package/dist/operations/map.d.ts +11 -0
- package/dist/operations/{argument.js → map.js} +167 -145
- package/dist/operations/negated-binary.d.ts +11 -0
- package/dist/{expressions/binary-negated-expression.js → operations/negated-binary.js} +109 -127
- package/dist/operations/new-instance.d.ts +11 -0
- package/dist/operations/{new.js → new-instance.js} +100 -97
- package/dist/operations/noop.d.ts +9 -0
- package/dist/operations/{else.js → noop.js} +36 -30
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -0
- package/dist/operations/operation.js +11 -0
- package/dist/operations/reference.d.ts +9 -11
- package/dist/operations/reference.js +37 -103
- package/dist/operations/resolve.d.ts +38 -0
- package/dist/operations/resolve.js +330 -0
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +107 -106
- package/dist/operations/while.d.ts +13 -14
- package/dist/operations/while.js +129 -145
- package/dist/types/boolean.d.ts +11 -0
- package/dist/{custom-types → types}/boolean.js +46 -47
- package/dist/types/default.d.ts +11 -0
- package/dist/types/default.js +20 -0
- package/dist/types/function.d.ts +32 -0
- package/dist/types/function.js +174 -0
- package/dist/types/generics.d.ts +17 -0
- package/dist/types/{operation.js → generics.js} +40 -38
- package/dist/types/interface.d.ts +22 -0
- package/dist/types/interface.js +102 -0
- package/dist/types/list.d.ts +31 -0
- package/dist/types/list.js +227 -0
- package/dist/types/map.d.ts +30 -0
- package/dist/types/map.js +224 -0
- package/dist/types/nil.d.ts +9 -0
- package/dist/{custom-types → types}/nil.js +44 -44
- package/dist/types/number.d.ts +11 -0
- package/dist/{custom-types → types}/number.js +46 -47
- package/dist/types/string.d.ts +33 -0
- package/dist/types/string.js +149 -0
- package/dist/utils/path.d.ts +10 -0
- package/dist/utils/path.js +59 -0
- package/package.json +58 -44
- package/dist/custom-types/boolean.d.ts +0 -12
- package/dist/custom-types/list.d.ts +0 -26
- package/dist/custom-types/list.js +0 -236
- package/dist/custom-types/map.d.ts +0 -26
- package/dist/custom-types/map.js +0 -245
- package/dist/custom-types/nil.d.ts +0 -10
- package/dist/custom-types/number.d.ts +0 -12
- package/dist/custom-types/string.d.ts +0 -25
- package/dist/custom-types/string.js +0 -172
- package/dist/expressions/assign.d.ts +0 -13
- package/dist/expressions/assign.js +0 -174
- package/dist/expressions/binary-negated-expression.d.ts +0 -18
- package/dist/expressions/call.d.ts +0 -14
- package/dist/expressions/call.js +0 -209
- package/dist/expressions/import.d.ts +0 -14
- package/dist/expressions/import.js +0 -155
- package/dist/expressions/include.d.ts +0 -13
- package/dist/expressions/list.d.ts +0 -14
- package/dist/expressions/logical-and-binary.d.ts +0 -22
- package/dist/expressions/logical-and-binary.js +0 -222
- package/dist/expressions/map.d.ts +0 -19
- package/dist/expressions/map.js +0 -197
- package/dist/expressions/path.d.ts +0 -31
- package/dist/expressions/path.js +0 -384
- package/dist/operations/argument.d.ts +0 -8
- package/dist/operations/body.d.ts +0 -8
- package/dist/operations/debugger.d.ts +0 -7
- package/dist/operations/else-if.d.ts +0 -12
- package/dist/operations/else.d.ts +0 -10
- package/dist/operations/if.d.ts +0 -12
- package/dist/operations/new.d.ts +0 -11
- package/dist/resource.d.ts +0 -9
- package/dist/resource.js +0 -29
- package/dist/typer.d.ts +0 -6
- package/dist/typer.js +0 -95
- package/dist/types/custom-type.d.ts +0 -22
- package/dist/types/custom-type.js +0 -67
- package/dist/types/expression.d.ts +0 -7
- package/dist/types/expression.js +0 -9
- package/dist/types/operation.d.ts +0 -10
|
@@ -0,0 +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;
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
18
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
+
if (m) return m.call(o);
|
|
20
|
+
if (o && typeof o.length === "number") return {
|
|
21
|
+
next: function () {
|
|
22
|
+
if (o && i >= o.length) o = void 0;
|
|
23
|
+
return { value: o && o[i++], done: !o };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
+
};
|
|
28
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
+
if (!m) return o;
|
|
31
|
+
var i = m.call(o), r, ar = [], e;
|
|
32
|
+
try {
|
|
33
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
34
|
+
}
|
|
35
|
+
catch (error) { e = { error: error }; }
|
|
36
|
+
finally {
|
|
37
|
+
try {
|
|
38
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
+
}
|
|
40
|
+
finally { if (e) throw e.error; }
|
|
41
|
+
}
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.CustomMapIterator = void 0;
|
|
49
|
+
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
50
|
+
var path_1 = __importDefault(require("../utils/path"));
|
|
51
|
+
var generics_1 = require("./generics");
|
|
52
|
+
var nil_1 = __importDefault(require("./nil"));
|
|
53
|
+
var string_1 = __importDefault(require("./string"));
|
|
54
|
+
var CustomMapIterator = /** @class */ (function () {
|
|
55
|
+
function CustomMapIterator(value) {
|
|
56
|
+
var me = this;
|
|
57
|
+
me.value = value;
|
|
58
|
+
me.index = 0;
|
|
59
|
+
}
|
|
60
|
+
CustomMapIterator.prototype.next = function () {
|
|
61
|
+
var me = this;
|
|
62
|
+
var keys = Array.from(me.value.keys());
|
|
63
|
+
if (me.index === keys.length) {
|
|
64
|
+
return {
|
|
65
|
+
value: new nil_1.default(),
|
|
66
|
+
done: true
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var key = keys[me.index++];
|
|
70
|
+
return {
|
|
71
|
+
value: new CustomMap(new Map([
|
|
72
|
+
['key', new string_1.default(key)],
|
|
73
|
+
['value', me.value.get(key)]
|
|
74
|
+
])),
|
|
75
|
+
done: false
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
return CustomMapIterator;
|
|
79
|
+
}());
|
|
80
|
+
exports.CustomMapIterator = CustomMapIterator;
|
|
81
|
+
var CustomMap = /** @class */ (function (_super) {
|
|
82
|
+
__extends(CustomMap, _super);
|
|
83
|
+
function CustomMap(value) {
|
|
84
|
+
if (value === void 0) { value = new Map(); }
|
|
85
|
+
var _this = _super.call(this) || this;
|
|
86
|
+
_this.isInstance = false;
|
|
87
|
+
_this.value = new Map(value);
|
|
88
|
+
return _this;
|
|
89
|
+
}
|
|
90
|
+
CustomMap.getIntrinsics = function () {
|
|
91
|
+
return this.intrinsics;
|
|
92
|
+
};
|
|
93
|
+
CustomMap.addIntrinsic = function (name, fn) {
|
|
94
|
+
this.intrinsics.add(name, fn);
|
|
95
|
+
};
|
|
96
|
+
CustomMap.prototype.getCustomType = function () {
|
|
97
|
+
if (this.has('classID')) {
|
|
98
|
+
return this.get('classID').toString();
|
|
99
|
+
}
|
|
100
|
+
return 'map';
|
|
101
|
+
};
|
|
102
|
+
CustomMap.prototype.toString = function () {
|
|
103
|
+
var e_1, _a;
|
|
104
|
+
var values = [];
|
|
105
|
+
try {
|
|
106
|
+
for (var _b = __values(this.value), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
107
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
108
|
+
values.push("".concat(key, ": ").concat(value.toString()));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
112
|
+
finally {
|
|
113
|
+
try {
|
|
114
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
115
|
+
}
|
|
116
|
+
finally { if (e_1) throw e_1.error; }
|
|
117
|
+
}
|
|
118
|
+
return "{ ".concat(values.join(', '), " }");
|
|
119
|
+
};
|
|
120
|
+
CustomMap.prototype.fork = function () {
|
|
121
|
+
return new CustomMap(this.value);
|
|
122
|
+
};
|
|
123
|
+
CustomMap.prototype.toNumber = function () {
|
|
124
|
+
return 0;
|
|
125
|
+
};
|
|
126
|
+
CustomMap.prototype.toInt = function () {
|
|
127
|
+
return 0;
|
|
128
|
+
};
|
|
129
|
+
CustomMap.prototype.toTruthy = function () {
|
|
130
|
+
return this.value.size > 0;
|
|
131
|
+
};
|
|
132
|
+
CustomMap.prototype[Symbol.iterator] = function () {
|
|
133
|
+
return new CustomMapIterator(this.value);
|
|
134
|
+
};
|
|
135
|
+
CustomMap.prototype.extend = function (map) {
|
|
136
|
+
var e_2, _a;
|
|
137
|
+
if (map instanceof CustomMap) {
|
|
138
|
+
map = map.value;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
for (var map_1 = __values(map), map_1_1 = map_1.next(); !map_1_1.done; map_1_1 = map_1.next()) {
|
|
142
|
+
var _b = __read(map_1_1.value, 2), key = _b[0], value = _b[1];
|
|
143
|
+
this.value.set(key, value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
147
|
+
finally {
|
|
148
|
+
try {
|
|
149
|
+
if (map_1_1 && !map_1_1.done && (_a = map_1.return)) _a.call(map_1);
|
|
150
|
+
}
|
|
151
|
+
finally { if (e_2) throw e_2.error; }
|
|
152
|
+
}
|
|
153
|
+
return this;
|
|
154
|
+
};
|
|
155
|
+
CustomMap.prototype.has = function (path) {
|
|
156
|
+
if (typeof path === 'string') {
|
|
157
|
+
return this.has(new path_1.default([path]));
|
|
158
|
+
}
|
|
159
|
+
var traversalPath = path.clone();
|
|
160
|
+
var current = traversalPath.next();
|
|
161
|
+
if (current !== null) {
|
|
162
|
+
if (this.value.has(current)) {
|
|
163
|
+
var sub = this.value.get(current);
|
|
164
|
+
if (traversalPath.count() > 0 &&
|
|
165
|
+
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
166
|
+
return sub.has(traversalPath);
|
|
167
|
+
}
|
|
168
|
+
return traversalPath.count() === 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
};
|
|
173
|
+
CustomMap.prototype.set = function (path, newValue) {
|
|
174
|
+
if (typeof path === 'string') {
|
|
175
|
+
return this.set(new path_1.default([path]), newValue);
|
|
176
|
+
}
|
|
177
|
+
var traversalPath = path.clone();
|
|
178
|
+
var last = traversalPath.last();
|
|
179
|
+
var current = traversalPath.next();
|
|
180
|
+
if (current !== null) {
|
|
181
|
+
if (this.value.has(current)) {
|
|
182
|
+
var sub = this.value.get(current);
|
|
183
|
+
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
184
|
+
sub.set(traversalPath, newValue);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
189
|
+
}
|
|
190
|
+
this.value.set(last, newValue);
|
|
191
|
+
};
|
|
192
|
+
CustomMap.prototype.get = function (path) {
|
|
193
|
+
if (typeof path === 'string') {
|
|
194
|
+
return this.get(new path_1.default([path]));
|
|
195
|
+
}
|
|
196
|
+
var traversalPath = path.clone();
|
|
197
|
+
var current = traversalPath.next();
|
|
198
|
+
if (current !== null) {
|
|
199
|
+
if (this.value.has(current)) {
|
|
200
|
+
var sub = this.value.get(current);
|
|
201
|
+
if (traversalPath.count() > 0) {
|
|
202
|
+
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
203
|
+
return sub.get(traversalPath);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (traversalPath.count() === 0) {
|
|
207
|
+
return sub;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (path.count() === 1 && CustomMap.getIntrinsics().has(current)) {
|
|
211
|
+
return CustomMap.getIntrinsics().get(current);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
throw new Error("Unknown path in map ".concat(path.toString(), "."));
|
|
215
|
+
};
|
|
216
|
+
CustomMap.prototype.createInstance = function () {
|
|
217
|
+
var newInstance = new CustomMap(this.value);
|
|
218
|
+
newInstance.isInstance = true;
|
|
219
|
+
return newInstance;
|
|
220
|
+
};
|
|
221
|
+
CustomMap.intrinsics = new intrinsics_container_1.default();
|
|
222
|
+
return CustomMap;
|
|
223
|
+
}(generics_1.CustomObject));
|
|
224
|
+
exports.default = CustomMap;
|
|
@@ -1,44 +1,44 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
var
|
|
19
|
-
var CustomNil = /** @class */ (function (_super) {
|
|
20
|
-
__extends(CustomNil, _super);
|
|
21
|
-
function CustomNil() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return CustomNil;
|
|
43
|
-
}(
|
|
44
|
-
exports.default = CustomNil;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
var generics_1 = require("./generics");
|
|
19
|
+
var CustomNil = /** @class */ (function (_super) {
|
|
20
|
+
__extends(CustomNil, _super);
|
|
21
|
+
function CustomNil() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
CustomNil.prototype.getCustomType = function () {
|
|
25
|
+
return 'null';
|
|
26
|
+
};
|
|
27
|
+
CustomNil.prototype.toString = function () {
|
|
28
|
+
return '';
|
|
29
|
+
};
|
|
30
|
+
CustomNil.prototype.fork = function () {
|
|
31
|
+
return new CustomNil();
|
|
32
|
+
};
|
|
33
|
+
CustomNil.prototype.toNumber = function () {
|
|
34
|
+
return undefined;
|
|
35
|
+
};
|
|
36
|
+
CustomNil.prototype.toInt = function () {
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
39
|
+
CustomNil.prototype.toTruthy = function () {
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
return CustomNil;
|
|
43
|
+
}(generics_1.CustomValue));
|
|
44
|
+
exports.default = CustomNil;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CustomValue } from './generics';
|
|
2
|
+
export default class CustomNumber extends CustomValue {
|
|
3
|
+
readonly value: number;
|
|
4
|
+
constructor(value: number);
|
|
5
|
+
getCustomType(): string;
|
|
6
|
+
toString(): string;
|
|
7
|
+
fork(): CustomNumber;
|
|
8
|
+
toInt(): number;
|
|
9
|
+
toNumber(): number;
|
|
10
|
+
toTruthy(): boolean;
|
|
11
|
+
}
|