greybel-interpreter 1.4.6 → 1.4.7
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 +110 -110
- package/dist/context.js +306 -306
- package/dist/cps.d.ts +14 -14
- package/dist/cps.js +160 -160
- package/dist/handler/error.d.ts +6 -6
- package/dist/handler/error.js +12 -12
- package/dist/handler/output.d.ts +18 -18
- package/dist/handler/output.js +29 -29
- package/dist/handler/resource.d.ts +12 -12
- package/dist/handler/resource.js +28 -28
- package/dist/handler-container.d.ts +14 -14
- package/dist/handler-container.js +14 -14
- package/dist/index.d.ts +46 -46
- package/dist/index.js +132 -132
- package/dist/interpreter.d.ts +42 -42
- package/dist/interpreter.js +218 -218
- package/dist/operations/assign.d.ts +13 -13
- package/dist/operations/assign.js +46 -46
- package/dist/operations/block.d.ts +12 -12
- package/dist/operations/block.js +52 -52
- package/dist/operations/break.d.ts +10 -10
- package/dist/operations/break.js +23 -23
- package/dist/operations/call.d.ts +13 -13
- package/dist/operations/call.js +49 -49
- package/dist/operations/chunk.d.ts +12 -12
- package/dist/operations/chunk.js +33 -33
- package/dist/operations/continue.d.ts +10 -10
- package/dist/operations/continue.js +23 -23
- package/dist/operations/debugger-statement.d.ts +10 -10
- package/dist/operations/debugger-statement.js +21 -21
- package/dist/operations/evaluate.d.ts +40 -40
- package/dist/operations/evaluate.js +334 -334
- package/dist/operations/for.d.ts +14 -14
- package/dist/operations/for.js +81 -81
- package/dist/operations/function-reference.d.ts +12 -12
- package/dist/operations/function-reference.js +44 -44
- package/dist/operations/function.d.ts +14 -14
- package/dist/operations/function.js +72 -72
- package/dist/operations/if-statement.d.ts +19 -19
- package/dist/operations/if-statement.js +85 -85
- package/dist/operations/import.d.ts +17 -17
- package/dist/operations/import.js +57 -57
- package/dist/operations/include.d.ts +13 -13
- package/dist/operations/include.js +41 -41
- package/dist/operations/list.d.ts +11 -11
- package/dist/operations/list.js +42 -42
- package/dist/operations/literal.d.ts +11 -11
- package/dist/operations/literal.js +40 -40
- package/dist/operations/map.d.ts +11 -11
- package/dist/operations/map.js +44 -44
- package/dist/operations/negated-binary.d.ts +11 -11
- package/dist/operations/negated-binary.js +42 -42
- package/dist/operations/new-instance.d.ts +11 -11
- package/dist/operations/new-instance.js +39 -39
- package/dist/operations/noop.d.ts +9 -9
- package/dist/operations/noop.js +19 -19
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +35 -35
- package/dist/operations/operation.d.ts +13 -13
- package/dist/operations/operation.js +9 -9
- package/dist/operations/reference.d.ts +9 -9
- package/dist/operations/reference.js +19 -19
- package/dist/operations/resolve.d.ts +38 -38
- package/dist/operations/resolve.js +210 -210
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +45 -45
- package/dist/operations/while.d.ts +13 -13
- package/dist/operations/while.js +65 -65
- package/dist/types/base.d.ts +9 -9
- package/dist/types/base.js +5 -5
- package/dist/types/boolean.d.ts +13 -13
- package/dist/types/boolean.js +34 -34
- package/dist/types/default.d.ts +8 -8
- package/dist/types/default.js +14 -14
- package/dist/types/function.d.ts +32 -32
- package/dist/types/function.js +104 -104
- package/dist/types/interface.d.ts +24 -24
- package/dist/types/interface.js +83 -83
- package/dist/types/list.d.ts +29 -29
- package/dist/types/list.js +158 -158
- package/dist/types/map.d.ts +33 -33
- package/dist/types/map.js +200 -200
- package/dist/types/nil.d.ts +11 -11
- package/dist/types/nil.js +33 -33
- package/dist/types/number.d.ts +25 -25
- package/dist/types/number.js +69 -69
- package/dist/types/string.d.ts +31 -31
- package/dist/types/string.js +121 -121
- package/dist/types/with-intrinsics.d.ts +15 -15
- package/dist/types/with-intrinsics.js +19 -19
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +37 -37
- package/dist/utils/object-value.d.ts +7 -7
- package/dist/utils/object-value.js +42 -42
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +32 -32
- package/package.json +58 -58
package/dist/types/interface.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CustomInterfaceIterator = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("../utils/path"));
|
|
8
|
-
const base_1 = __importDefault(require("./base"));
|
|
9
|
-
const default_1 = __importDefault(require("./default"));
|
|
10
|
-
const with_intrinsics_1 = require("./with-intrinsics");
|
|
11
|
-
class CustomInterfaceIterator {
|
|
12
|
-
next() {
|
|
13
|
-
return {
|
|
14
|
-
value: default_1.default.Void,
|
|
15
|
-
done: true
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.CustomInterfaceIterator = CustomInterfaceIterator;
|
|
20
|
-
class CustomInterface extends with_intrinsics_1.CustomObject {
|
|
21
|
-
constructor(type) {
|
|
22
|
-
super();
|
|
23
|
-
this.value = {};
|
|
24
|
-
this.type = type;
|
|
25
|
-
this.interfaceFns = new Map();
|
|
26
|
-
}
|
|
27
|
-
getCustomType() {
|
|
28
|
-
return this.type;
|
|
29
|
-
}
|
|
30
|
-
toString() {
|
|
31
|
-
return this.type;
|
|
32
|
-
}
|
|
33
|
-
fork() {
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
toNumber() {
|
|
37
|
-
return Number.NaN;
|
|
38
|
-
}
|
|
39
|
-
toInt() {
|
|
40
|
-
return 0;
|
|
41
|
-
}
|
|
42
|
-
toTruthy() {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
[Symbol.iterator]() {
|
|
46
|
-
return new CustomInterfaceIterator();
|
|
47
|
-
}
|
|
48
|
-
has(path) {
|
|
49
|
-
if (path instanceof base_1.default) {
|
|
50
|
-
return this.has(new path_1.default([path]));
|
|
51
|
-
}
|
|
52
|
-
const traversalPath = path.clone();
|
|
53
|
-
const current = traversalPath.next();
|
|
54
|
-
if (current !== null) {
|
|
55
|
-
return this.interfaceFns.has(current.toString());
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
set(_path, _newValue) {
|
|
60
|
-
throw new Error('Cannot set property on an interface.');
|
|
61
|
-
}
|
|
62
|
-
get(path) {
|
|
63
|
-
if (path instanceof base_1.default) {
|
|
64
|
-
return this.get(new path_1.default([path]));
|
|
65
|
-
}
|
|
66
|
-
if (path.count() === 0) {
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
const traversalPath = path.clone();
|
|
70
|
-
const current = traversalPath.next();
|
|
71
|
-
if (current !== null) {
|
|
72
|
-
if (this.interfaceFns.has(current.toString())) {
|
|
73
|
-
return this.interfaceFns.get(current.toString());
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
throw new Error(`Unknown path in interface ${path.toString()}.`);
|
|
77
|
-
}
|
|
78
|
-
addFunction(name, fn) {
|
|
79
|
-
this.interfaceFns.set(name, fn);
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.default = CustomInterface;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CustomInterfaceIterator = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("../utils/path"));
|
|
8
|
+
const base_1 = __importDefault(require("./base"));
|
|
9
|
+
const default_1 = __importDefault(require("./default"));
|
|
10
|
+
const with_intrinsics_1 = require("./with-intrinsics");
|
|
11
|
+
class CustomInterfaceIterator {
|
|
12
|
+
next() {
|
|
13
|
+
return {
|
|
14
|
+
value: default_1.default.Void,
|
|
15
|
+
done: true
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CustomInterfaceIterator = CustomInterfaceIterator;
|
|
20
|
+
class CustomInterface extends with_intrinsics_1.CustomObject {
|
|
21
|
+
constructor(type) {
|
|
22
|
+
super();
|
|
23
|
+
this.value = {};
|
|
24
|
+
this.type = type;
|
|
25
|
+
this.interfaceFns = new Map();
|
|
26
|
+
}
|
|
27
|
+
getCustomType() {
|
|
28
|
+
return this.type;
|
|
29
|
+
}
|
|
30
|
+
toString() {
|
|
31
|
+
return this.type;
|
|
32
|
+
}
|
|
33
|
+
fork() {
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
toNumber() {
|
|
37
|
+
return Number.NaN;
|
|
38
|
+
}
|
|
39
|
+
toInt() {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
toTruthy() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
[Symbol.iterator]() {
|
|
46
|
+
return new CustomInterfaceIterator();
|
|
47
|
+
}
|
|
48
|
+
has(path) {
|
|
49
|
+
if (path instanceof base_1.default) {
|
|
50
|
+
return this.has(new path_1.default([path]));
|
|
51
|
+
}
|
|
52
|
+
const traversalPath = path.clone();
|
|
53
|
+
const current = traversalPath.next();
|
|
54
|
+
if (current !== null) {
|
|
55
|
+
return this.interfaceFns.has(current.toString());
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
set(_path, _newValue) {
|
|
60
|
+
throw new Error('Cannot set property on an interface.');
|
|
61
|
+
}
|
|
62
|
+
get(path) {
|
|
63
|
+
if (path instanceof base_1.default) {
|
|
64
|
+
return this.get(new path_1.default([path]));
|
|
65
|
+
}
|
|
66
|
+
if (path.count() === 0) {
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
const traversalPath = path.clone();
|
|
70
|
+
const current = traversalPath.next();
|
|
71
|
+
if (current !== null) {
|
|
72
|
+
if (this.interfaceFns.has(current.toString())) {
|
|
73
|
+
return this.interfaceFns.get(current.toString());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`Unknown path in interface ${path.toString()}.`);
|
|
77
|
+
}
|
|
78
|
+
addFunction(name, fn) {
|
|
79
|
+
this.interfaceFns.set(name, fn);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.default = CustomInterface;
|
package/dist/types/list.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import ObjectValue from '../utils/object-value';
|
|
2
|
-
import Path from '../utils/path';
|
|
3
|
-
import CustomValue from './base';
|
|
4
|
-
import { CustomObject } from './with-intrinsics';
|
|
5
|
-
export declare class CustomListIterator implements Iterator<CustomValue> {
|
|
6
|
-
value: Array<CustomValue>;
|
|
7
|
-
index: number;
|
|
8
|
-
constructor(value: Array<CustomValue>);
|
|
9
|
-
next(): IteratorResult<CustomValue>;
|
|
10
|
-
}
|
|
11
|
-
export default class CustomList extends CustomObject {
|
|
12
|
-
static readonly intrinsics: ObjectValue;
|
|
13
|
-
static getItemIndex(item: CustomList, index: number): number;
|
|
14
|
-
readonly value: Array<CustomValue>;
|
|
15
|
-
constructor(value?: Array<CustomValue>);
|
|
16
|
-
getCustomType(): string;
|
|
17
|
-
toString(): string;
|
|
18
|
-
fork(): CustomList;
|
|
19
|
-
toNumber(): number;
|
|
20
|
-
toInt(): number;
|
|
21
|
-
toTruthy(): boolean;
|
|
22
|
-
slice(a: CustomValue, b: CustomValue): CustomList;
|
|
23
|
-
extend(list: CustomList | Array<CustomValue>): CustomList;
|
|
24
|
-
[Symbol.iterator](): CustomListIterator;
|
|
25
|
-
getItemIndex(index: number): number;
|
|
26
|
-
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
27
|
-
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
28
|
-
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
29
|
-
}
|
|
1
|
+
import ObjectValue from '../utils/object-value';
|
|
2
|
+
import Path from '../utils/path';
|
|
3
|
+
import CustomValue from './base';
|
|
4
|
+
import { CustomObject } from './with-intrinsics';
|
|
5
|
+
export declare class CustomListIterator implements Iterator<CustomValue> {
|
|
6
|
+
value: Array<CustomValue>;
|
|
7
|
+
index: number;
|
|
8
|
+
constructor(value: Array<CustomValue>);
|
|
9
|
+
next(): IteratorResult<CustomValue>;
|
|
10
|
+
}
|
|
11
|
+
export default class CustomList extends CustomObject {
|
|
12
|
+
static readonly intrinsics: ObjectValue;
|
|
13
|
+
static getItemIndex(item: CustomList, index: number): number;
|
|
14
|
+
readonly value: Array<CustomValue>;
|
|
15
|
+
constructor(value?: Array<CustomValue>);
|
|
16
|
+
getCustomType(): string;
|
|
17
|
+
toString(): string;
|
|
18
|
+
fork(): CustomList;
|
|
19
|
+
toNumber(): number;
|
|
20
|
+
toInt(): number;
|
|
21
|
+
toTruthy(): boolean;
|
|
22
|
+
slice(a: CustomValue, b: CustomValue): CustomList;
|
|
23
|
+
extend(list: CustomList | Array<CustomValue>): CustomList;
|
|
24
|
+
[Symbol.iterator](): CustomListIterator;
|
|
25
|
+
getItemIndex(index: number): number;
|
|
26
|
+
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
27
|
+
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
28
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
29
|
+
}
|
package/dist/types/list.js
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CustomListIterator = void 0;
|
|
7
|
-
const object_value_1 = __importDefault(require("../utils/object-value"));
|
|
8
|
-
const path_1 = __importDefault(require("../utils/path"));
|
|
9
|
-
const base_1 = __importDefault(require("./base"));
|
|
10
|
-
const number_1 = __importDefault(require("./number"));
|
|
11
|
-
const with_intrinsics_1 = require("./with-intrinsics");
|
|
12
|
-
class CustomListIterator {
|
|
13
|
-
constructor(value) {
|
|
14
|
-
const me = this;
|
|
15
|
-
me.value = value;
|
|
16
|
-
me.index = 0;
|
|
17
|
-
}
|
|
18
|
-
next() {
|
|
19
|
-
const me = this;
|
|
20
|
-
if (me.index === me.value.length) {
|
|
21
|
-
return {
|
|
22
|
-
value: null,
|
|
23
|
-
done: true
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
value: me.value[me.index++],
|
|
28
|
-
done: false
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.CustomListIterator = CustomListIterator;
|
|
33
|
-
class CustomList extends with_intrinsics_1.CustomObject {
|
|
34
|
-
constructor(value = []) {
|
|
35
|
-
super();
|
|
36
|
-
this.value = [...value];
|
|
37
|
-
}
|
|
38
|
-
static getItemIndex(item, index) {
|
|
39
|
-
let n = index | 0;
|
|
40
|
-
if (n < 0)
|
|
41
|
-
n += item.value.length;
|
|
42
|
-
if (n < 0 || n >= item.value.length)
|
|
43
|
-
return -1;
|
|
44
|
-
return n;
|
|
45
|
-
}
|
|
46
|
-
getCustomType() {
|
|
47
|
-
return 'list';
|
|
48
|
-
}
|
|
49
|
-
toString() {
|
|
50
|
-
return `[ ${this.value.join(', ')} ]`;
|
|
51
|
-
}
|
|
52
|
-
fork() {
|
|
53
|
-
return new CustomList(this.value);
|
|
54
|
-
}
|
|
55
|
-
toNumber() {
|
|
56
|
-
return 0;
|
|
57
|
-
}
|
|
58
|
-
toInt() {
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
61
|
-
toTruthy() {
|
|
62
|
-
return this.value.length > 0;
|
|
63
|
-
}
|
|
64
|
-
slice(a, b) {
|
|
65
|
-
return new CustomList(this.value.slice(a.toNumber(), b.toNumber()));
|
|
66
|
-
}
|
|
67
|
-
extend(list) {
|
|
68
|
-
if (list instanceof CustomList) {
|
|
69
|
-
list = list.value;
|
|
70
|
-
}
|
|
71
|
-
for (let index = 0; index < list.length; index++) {
|
|
72
|
-
this.value.push(list[index]);
|
|
73
|
-
}
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
[Symbol.iterator]() {
|
|
77
|
-
return new CustomListIterator(this.value);
|
|
78
|
-
}
|
|
79
|
-
getItemIndex(index) {
|
|
80
|
-
return CustomList.getItemIndex(this, index);
|
|
81
|
-
}
|
|
82
|
-
has(path) {
|
|
83
|
-
if (path instanceof base_1.default) {
|
|
84
|
-
return this.has(new path_1.default([path]));
|
|
85
|
-
}
|
|
86
|
-
const traversalPath = path.clone();
|
|
87
|
-
const current = traversalPath.next();
|
|
88
|
-
if (current instanceof number_1.default) {
|
|
89
|
-
const currentIndex = this.getItemIndex(current.toInt());
|
|
90
|
-
const sub = this.value[currentIndex];
|
|
91
|
-
if (sub) {
|
|
92
|
-
if (traversalPath.count() > 0 &&
|
|
93
|
-
sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
94
|
-
return sub.has(traversalPath);
|
|
95
|
-
}
|
|
96
|
-
return traversalPath.count() === 0;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
set(path, newValue) {
|
|
102
|
-
if (path instanceof base_1.default) {
|
|
103
|
-
return this.set(new path_1.default([path]), newValue);
|
|
104
|
-
}
|
|
105
|
-
const traversalPath = path.clone();
|
|
106
|
-
const last = traversalPath.last();
|
|
107
|
-
const current = traversalPath.next();
|
|
108
|
-
if (current instanceof number_1.default) {
|
|
109
|
-
const currentIndex = this.getItemIndex(current.toInt());
|
|
110
|
-
const sub = this.value[currentIndex];
|
|
111
|
-
if (sub) {
|
|
112
|
-
if (traversalPath.count() > 0 &&
|
|
113
|
-
sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
114
|
-
sub.set(traversalPath, newValue);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
throw new Error(`Cannot set path ${path.toString()}.`);
|
|
119
|
-
}
|
|
120
|
-
if (last instanceof number_1.default) {
|
|
121
|
-
const lastIndex = this.getItemIndex(last.toInt());
|
|
122
|
-
if (lastIndex >= 0 && lastIndex < this.value.length) {
|
|
123
|
-
this.value[lastIndex] = newValue;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
throw new Error(`Index error (list index ${lastIndex} out of range).`);
|
|
127
|
-
}
|
|
128
|
-
throw new Error(`Index is not a number.`);
|
|
129
|
-
}
|
|
130
|
-
get(path) {
|
|
131
|
-
if (path instanceof base_1.default) {
|
|
132
|
-
return this.get(new path_1.default([path]));
|
|
133
|
-
}
|
|
134
|
-
const traversalPath = path.clone();
|
|
135
|
-
const current = traversalPath.next();
|
|
136
|
-
if (current instanceof number_1.default) {
|
|
137
|
-
const currentIndex = this.getItemIndex(current.toInt());
|
|
138
|
-
if (currentIndex >= 0 && currentIndex < this.value.length) {
|
|
139
|
-
const sub = this.value[currentIndex];
|
|
140
|
-
if (traversalPath.count() > 0) {
|
|
141
|
-
if (sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
142
|
-
return sub.get(traversalPath);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else if (traversalPath.count() === 0) {
|
|
146
|
-
return sub;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
throw new Error(`Index error (list index ${currentIndex} out of range).`);
|
|
150
|
-
}
|
|
151
|
-
else if (path.count() === 1 && CustomList.getIntrinsics().has(current)) {
|
|
152
|
-
return CustomList.getIntrinsics().get(current);
|
|
153
|
-
}
|
|
154
|
-
throw new Error(`Unknown path in list ${path.toString()}.`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.default = CustomList;
|
|
158
|
-
CustomList.intrinsics = new object_value_1.default();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CustomListIterator = void 0;
|
|
7
|
+
const object_value_1 = __importDefault(require("../utils/object-value"));
|
|
8
|
+
const path_1 = __importDefault(require("../utils/path"));
|
|
9
|
+
const base_1 = __importDefault(require("./base"));
|
|
10
|
+
const number_1 = __importDefault(require("./number"));
|
|
11
|
+
const with_intrinsics_1 = require("./with-intrinsics");
|
|
12
|
+
class CustomListIterator {
|
|
13
|
+
constructor(value) {
|
|
14
|
+
const me = this;
|
|
15
|
+
me.value = value;
|
|
16
|
+
me.index = 0;
|
|
17
|
+
}
|
|
18
|
+
next() {
|
|
19
|
+
const me = this;
|
|
20
|
+
if (me.index === me.value.length) {
|
|
21
|
+
return {
|
|
22
|
+
value: null,
|
|
23
|
+
done: true
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
value: me.value[me.index++],
|
|
28
|
+
done: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.CustomListIterator = CustomListIterator;
|
|
33
|
+
class CustomList extends with_intrinsics_1.CustomObject {
|
|
34
|
+
constructor(value = []) {
|
|
35
|
+
super();
|
|
36
|
+
this.value = [...value];
|
|
37
|
+
}
|
|
38
|
+
static getItemIndex(item, index) {
|
|
39
|
+
let n = index | 0;
|
|
40
|
+
if (n < 0)
|
|
41
|
+
n += item.value.length;
|
|
42
|
+
if (n < 0 || n >= item.value.length)
|
|
43
|
+
return -1;
|
|
44
|
+
return n;
|
|
45
|
+
}
|
|
46
|
+
getCustomType() {
|
|
47
|
+
return 'list';
|
|
48
|
+
}
|
|
49
|
+
toString() {
|
|
50
|
+
return `[ ${this.value.join(', ')} ]`;
|
|
51
|
+
}
|
|
52
|
+
fork() {
|
|
53
|
+
return new CustomList(this.value);
|
|
54
|
+
}
|
|
55
|
+
toNumber() {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
toInt() {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
toTruthy() {
|
|
62
|
+
return this.value.length > 0;
|
|
63
|
+
}
|
|
64
|
+
slice(a, b) {
|
|
65
|
+
return new CustomList(this.value.slice(a.toNumber(), b.toNumber()));
|
|
66
|
+
}
|
|
67
|
+
extend(list) {
|
|
68
|
+
if (list instanceof CustomList) {
|
|
69
|
+
list = list.value;
|
|
70
|
+
}
|
|
71
|
+
for (let index = 0; index < list.length; index++) {
|
|
72
|
+
this.value.push(list[index]);
|
|
73
|
+
}
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
[Symbol.iterator]() {
|
|
77
|
+
return new CustomListIterator(this.value);
|
|
78
|
+
}
|
|
79
|
+
getItemIndex(index) {
|
|
80
|
+
return CustomList.getItemIndex(this, index);
|
|
81
|
+
}
|
|
82
|
+
has(path) {
|
|
83
|
+
if (path instanceof base_1.default) {
|
|
84
|
+
return this.has(new path_1.default([path]));
|
|
85
|
+
}
|
|
86
|
+
const traversalPath = path.clone();
|
|
87
|
+
const current = traversalPath.next();
|
|
88
|
+
if (current instanceof number_1.default) {
|
|
89
|
+
const currentIndex = this.getItemIndex(current.toInt());
|
|
90
|
+
const sub = this.value[currentIndex];
|
|
91
|
+
if (sub) {
|
|
92
|
+
if (traversalPath.count() > 0 &&
|
|
93
|
+
sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
94
|
+
return sub.has(traversalPath);
|
|
95
|
+
}
|
|
96
|
+
return traversalPath.count() === 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
set(path, newValue) {
|
|
102
|
+
if (path instanceof base_1.default) {
|
|
103
|
+
return this.set(new path_1.default([path]), newValue);
|
|
104
|
+
}
|
|
105
|
+
const traversalPath = path.clone();
|
|
106
|
+
const last = traversalPath.last();
|
|
107
|
+
const current = traversalPath.next();
|
|
108
|
+
if (current instanceof number_1.default) {
|
|
109
|
+
const currentIndex = this.getItemIndex(current.toInt());
|
|
110
|
+
const sub = this.value[currentIndex];
|
|
111
|
+
if (sub) {
|
|
112
|
+
if (traversalPath.count() > 0 &&
|
|
113
|
+
sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
114
|
+
sub.set(traversalPath, newValue);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw new Error(`Cannot set path ${path.toString()}.`);
|
|
119
|
+
}
|
|
120
|
+
if (last instanceof number_1.default) {
|
|
121
|
+
const lastIndex = this.getItemIndex(last.toInt());
|
|
122
|
+
if (lastIndex >= 0 && lastIndex < this.value.length) {
|
|
123
|
+
this.value[lastIndex] = newValue;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
throw new Error(`Index error (list index ${lastIndex} out of range).`);
|
|
127
|
+
}
|
|
128
|
+
throw new Error(`Index is not a number.`);
|
|
129
|
+
}
|
|
130
|
+
get(path) {
|
|
131
|
+
if (path instanceof base_1.default) {
|
|
132
|
+
return this.get(new path_1.default([path]));
|
|
133
|
+
}
|
|
134
|
+
const traversalPath = path.clone();
|
|
135
|
+
const current = traversalPath.next();
|
|
136
|
+
if (current instanceof number_1.default) {
|
|
137
|
+
const currentIndex = this.getItemIndex(current.toInt());
|
|
138
|
+
if (currentIndex >= 0 && currentIndex < this.value.length) {
|
|
139
|
+
const sub = this.value[currentIndex];
|
|
140
|
+
if (traversalPath.count() > 0) {
|
|
141
|
+
if (sub instanceof with_intrinsics_1.CustomValueWithIntrinsics) {
|
|
142
|
+
return sub.get(traversalPath);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (traversalPath.count() === 0) {
|
|
146
|
+
return sub;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`Index error (list index ${currentIndex} out of range).`);
|
|
150
|
+
}
|
|
151
|
+
else if (path.count() === 1 && CustomList.getIntrinsics().has(current)) {
|
|
152
|
+
return CustomList.getIntrinsics().get(current);
|
|
153
|
+
}
|
|
154
|
+
throw new Error(`Unknown path in list ${path.toString()}.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.default = CustomList;
|
|
158
|
+
CustomList.intrinsics = new object_value_1.default();
|
package/dist/types/map.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import ObjectValue from '../utils/object-value';
|
|
2
|
-
import Path from '../utils/path';
|
|
3
|
-
import CustomValue from './base';
|
|
4
|
-
import CustomString from './string';
|
|
5
|
-
import { CustomObject } from './with-intrinsics';
|
|
6
|
-
export declare const CLASS_ID_PROPERTY: CustomString;
|
|
7
|
-
export declare const ISA_PROPERTY: CustomString;
|
|
8
|
-
export declare class CustomMapIterator implements Iterator<CustomValue> {
|
|
9
|
-
value: ObjectValue;
|
|
10
|
-
index: number;
|
|
11
|
-
constructor(value: ObjectValue);
|
|
12
|
-
next(): IteratorResult<CustomMap>;
|
|
13
|
-
}
|
|
14
|
-
export default class CustomMap extends CustomObject {
|
|
15
|
-
static readonly intrinsics: ObjectValue;
|
|
16
|
-
value: ObjectValue;
|
|
17
|
-
readonly isa: ObjectValue;
|
|
18
|
-
private isInstance;
|
|
19
|
-
static createWithInitialValue(value: ObjectValue): CustomMap;
|
|
20
|
-
constructor(value?: ObjectValue, isa?: ObjectValue);
|
|
21
|
-
getCustomType(): string;
|
|
22
|
-
toString(): string;
|
|
23
|
-
fork(): CustomMap;
|
|
24
|
-
toNumber(): number;
|
|
25
|
-
toInt(): number;
|
|
26
|
-
toTruthy(): boolean;
|
|
27
|
-
[Symbol.iterator](): CustomMapIterator;
|
|
28
|
-
extend(map: CustomMap | ObjectValue): CustomMap;
|
|
29
|
-
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
30
|
-
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
31
|
-
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
32
|
-
createInstance(): CustomMap;
|
|
33
|
-
}
|
|
1
|
+
import ObjectValue from '../utils/object-value';
|
|
2
|
+
import Path from '../utils/path';
|
|
3
|
+
import CustomValue from './base';
|
|
4
|
+
import CustomString from './string';
|
|
5
|
+
import { CustomObject } from './with-intrinsics';
|
|
6
|
+
export declare const CLASS_ID_PROPERTY: CustomString;
|
|
7
|
+
export declare const ISA_PROPERTY: CustomString;
|
|
8
|
+
export declare class CustomMapIterator implements Iterator<CustomValue> {
|
|
9
|
+
value: ObjectValue;
|
|
10
|
+
index: number;
|
|
11
|
+
constructor(value: ObjectValue);
|
|
12
|
+
next(): IteratorResult<CustomMap>;
|
|
13
|
+
}
|
|
14
|
+
export default class CustomMap extends CustomObject {
|
|
15
|
+
static readonly intrinsics: ObjectValue;
|
|
16
|
+
value: ObjectValue;
|
|
17
|
+
readonly isa: ObjectValue;
|
|
18
|
+
private isInstance;
|
|
19
|
+
static createWithInitialValue(value: ObjectValue): CustomMap;
|
|
20
|
+
constructor(value?: ObjectValue, isa?: ObjectValue);
|
|
21
|
+
getCustomType(): string;
|
|
22
|
+
toString(): string;
|
|
23
|
+
fork(): CustomMap;
|
|
24
|
+
toNumber(): number;
|
|
25
|
+
toInt(): number;
|
|
26
|
+
toTruthy(): boolean;
|
|
27
|
+
[Symbol.iterator](): CustomMapIterator;
|
|
28
|
+
extend(map: CustomMap | ObjectValue): CustomMap;
|
|
29
|
+
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
30
|
+
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
31
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
32
|
+
createInstance(): CustomMap;
|
|
33
|
+
}
|