greybel-interpreter 0.7.2 → 1.0.0
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 +107 -98
- package/dist/context.js +358 -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 +101 -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,11 @@
|
|
|
1
|
+
import CustomBoolean from './boolean';
|
|
2
|
+
import CustomNil from './nil';
|
|
3
|
+
import CustomNumber from './number';
|
|
4
|
+
export default class Defaults {
|
|
5
|
+
static readonly Void: CustomNil;
|
|
6
|
+
static readonly True: CustomBoolean;
|
|
7
|
+
static readonly False: CustomBoolean;
|
|
8
|
+
static readonly NegativeOne: CustomNumber;
|
|
9
|
+
static readonly PositiveOne: CustomNumber;
|
|
10
|
+
static readonly Zero: CustomNumber;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
var boolean_1 = __importDefault(require("./boolean"));
|
|
7
|
+
var nil_1 = __importDefault(require("./nil"));
|
|
8
|
+
var number_1 = __importDefault(require("./number"));
|
|
9
|
+
var Defaults = /** @class */ (function () {
|
|
10
|
+
function Defaults() {
|
|
11
|
+
}
|
|
12
|
+
Defaults.Void = new nil_1.default();
|
|
13
|
+
Defaults.True = new boolean_1.default(true);
|
|
14
|
+
Defaults.False = new boolean_1.default(false);
|
|
15
|
+
Defaults.NegativeOne = new number_1.default(-1);
|
|
16
|
+
Defaults.PositiveOne = new number_1.default(1);
|
|
17
|
+
Defaults.Zero = new number_1.default(0);
|
|
18
|
+
return Defaults;
|
|
19
|
+
}());
|
|
20
|
+
exports.default = Defaults;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import OperationContext from '../context';
|
|
2
|
+
import Operation from '../operations/operation';
|
|
3
|
+
import { CustomValue } from './generics';
|
|
4
|
+
export interface Callback {
|
|
5
|
+
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<CustomValue>;
|
|
6
|
+
}
|
|
7
|
+
export declare class Argument {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly defaultValue: Operation;
|
|
10
|
+
static createWithCustomValue(name: string, defaultValue: CustomValue): Argument;
|
|
11
|
+
constructor(name: string, defaultValue?: Operation | CustomValue);
|
|
12
|
+
}
|
|
13
|
+
export default class CustomFunction extends CustomValue {
|
|
14
|
+
readonly scope?: OperationContext;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly callback: Callback;
|
|
17
|
+
private injectSelf;
|
|
18
|
+
readonly argumentDefs: Array<Argument>;
|
|
19
|
+
static createExternalAnonymous(callback: Callback): CustomFunction;
|
|
20
|
+
static createExternal(name: string, callback: Callback): CustomFunction;
|
|
21
|
+
static createExternalWithSelf(name: string, callback: Callback): CustomFunction;
|
|
22
|
+
constructor(scope: OperationContext, name: string, callback: Callback, injectSelf?: boolean);
|
|
23
|
+
setInjectSelf(injectSelf: boolean): CustomFunction;
|
|
24
|
+
addArgument(name: string, defaultValue?: Operation | CustomValue): CustomFunction;
|
|
25
|
+
fork(): CustomValue;
|
|
26
|
+
getCustomType(): string;
|
|
27
|
+
toNumber(): number;
|
|
28
|
+
toInt(): number;
|
|
29
|
+
toString(): string;
|
|
30
|
+
toTruthy(): boolean;
|
|
31
|
+
run(self: CustomValue, args: Array<CustomValue>, callContext?: OperationContext): Promise<CustomValue>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.Argument = void 0;
|
|
58
|
+
var context_1 = require("../context");
|
|
59
|
+
var operation_1 = __importDefault(require("../operations/operation"));
|
|
60
|
+
var reference_1 = __importDefault(require("../operations/reference"));
|
|
61
|
+
var default_1 = __importDefault(require("./default"));
|
|
62
|
+
var generics_1 = require("./generics");
|
|
63
|
+
var nil_1 = __importDefault(require("./nil"));
|
|
64
|
+
var Argument = /** @class */ (function () {
|
|
65
|
+
function Argument(name, defaultValue) {
|
|
66
|
+
if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
|
|
67
|
+
this.name = name;
|
|
68
|
+
if (defaultValue instanceof generics_1.CustomValue) {
|
|
69
|
+
this.defaultValue = new reference_1.default(defaultValue);
|
|
70
|
+
}
|
|
71
|
+
else if (defaultValue instanceof operation_1.default) {
|
|
72
|
+
this.defaultValue = defaultValue;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error('Invalid defaultValue in argument.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
Argument.createWithCustomValue = function (name, defaultValue) {
|
|
79
|
+
return new Argument(name, new reference_1.default(defaultValue));
|
|
80
|
+
};
|
|
81
|
+
return Argument;
|
|
82
|
+
}());
|
|
83
|
+
exports.Argument = Argument;
|
|
84
|
+
var CustomFunction = /** @class */ (function (_super) {
|
|
85
|
+
__extends(CustomFunction, _super);
|
|
86
|
+
function CustomFunction(scope, name, callback, injectSelf) {
|
|
87
|
+
if (injectSelf === void 0) { injectSelf = false; }
|
|
88
|
+
var _this = _super.call(this) || this;
|
|
89
|
+
_this.scope = scope;
|
|
90
|
+
_this.name = name;
|
|
91
|
+
_this.callback = callback;
|
|
92
|
+
_this.injectSelf = injectSelf;
|
|
93
|
+
_this.argumentDefs = [];
|
|
94
|
+
return _this;
|
|
95
|
+
}
|
|
96
|
+
CustomFunction.createExternalAnonymous = function (callback) {
|
|
97
|
+
return new CustomFunction(null, 'anonymous', callback);
|
|
98
|
+
};
|
|
99
|
+
CustomFunction.createExternal = function (name, callback) {
|
|
100
|
+
return new CustomFunction(null, name, callback);
|
|
101
|
+
};
|
|
102
|
+
CustomFunction.createExternalWithSelf = function (name, callback) {
|
|
103
|
+
return new CustomFunction(null, name, callback, true).addArgument('self');
|
|
104
|
+
};
|
|
105
|
+
CustomFunction.prototype.setInjectSelf = function (injectSelf) {
|
|
106
|
+
this.injectSelf = injectSelf;
|
|
107
|
+
return this;
|
|
108
|
+
};
|
|
109
|
+
CustomFunction.prototype.addArgument = function (name, defaultValue) {
|
|
110
|
+
if (defaultValue === void 0) { defaultValue = default_1.default.Void; }
|
|
111
|
+
this.argumentDefs.push(new Argument(name, defaultValue));
|
|
112
|
+
return this;
|
|
113
|
+
};
|
|
114
|
+
CustomFunction.prototype.fork = function () {
|
|
115
|
+
return new CustomFunction(this.scope, this.name, this.callback);
|
|
116
|
+
};
|
|
117
|
+
CustomFunction.prototype.getCustomType = function () {
|
|
118
|
+
return 'function';
|
|
119
|
+
};
|
|
120
|
+
CustomFunction.prototype.toNumber = function () {
|
|
121
|
+
return Number.NaN;
|
|
122
|
+
};
|
|
123
|
+
CustomFunction.prototype.toInt = function () {
|
|
124
|
+
return 0;
|
|
125
|
+
};
|
|
126
|
+
CustomFunction.prototype.toString = function () {
|
|
127
|
+
var args = this.argumentDefs.map(function (item) { return item.name; });
|
|
128
|
+
return "function ".concat(this.name, "(").concat(args.join(', '), ")");
|
|
129
|
+
};
|
|
130
|
+
CustomFunction.prototype.toTruthy = function () {
|
|
131
|
+
return true;
|
|
132
|
+
};
|
|
133
|
+
CustomFunction.prototype.run = function (self, args, callContext) {
|
|
134
|
+
var _a;
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var fnCtx, argMap, index, item, _b, _c, _d, _e;
|
|
137
|
+
return __generator(this, function (_f) {
|
|
138
|
+
switch (_f.label) {
|
|
139
|
+
case 0:
|
|
140
|
+
fnCtx = (_a = this.scope) === null || _a === void 0 ? void 0 : _a.fork({
|
|
141
|
+
type: context_1.ContextType.Function,
|
|
142
|
+
state: context_1.ContextState.Default
|
|
143
|
+
});
|
|
144
|
+
argMap = new Map();
|
|
145
|
+
if (this.injectSelf && !(self instanceof nil_1.default)) {
|
|
146
|
+
args.unshift(self);
|
|
147
|
+
}
|
|
148
|
+
index = 0;
|
|
149
|
+
_f.label = 1;
|
|
150
|
+
case 1:
|
|
151
|
+
if (!(index < this.argumentDefs.length)) return [3 /*break*/, 5];
|
|
152
|
+
item = this.argumentDefs[index];
|
|
153
|
+
_c = (_b = argMap).set;
|
|
154
|
+
_d = [item.name];
|
|
155
|
+
_e = args[index];
|
|
156
|
+
if (_e) return [3 /*break*/, 3];
|
|
157
|
+
return [4 /*yield*/, item.defaultValue.handle(fnCtx)];
|
|
158
|
+
case 2:
|
|
159
|
+
_e = (_f.sent());
|
|
160
|
+
_f.label = 3;
|
|
161
|
+
case 3:
|
|
162
|
+
_c.apply(_b, _d.concat([_e]));
|
|
163
|
+
_f.label = 4;
|
|
164
|
+
case 4:
|
|
165
|
+
index++;
|
|
166
|
+
return [3 /*break*/, 1];
|
|
167
|
+
case 5: return [2 /*return*/, this.callback(fnCtx || callContext, self, argMap)];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
return CustomFunction;
|
|
173
|
+
}(generics_1.CustomValue));
|
|
174
|
+
exports.default = CustomFunction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Path from '../utils/path';
|
|
2
|
+
export declare abstract class CustomValue {
|
|
3
|
+
abstract getCustomType(): string;
|
|
4
|
+
abstract toNumber(): number;
|
|
5
|
+
abstract toInt(): number;
|
|
6
|
+
abstract toString(): string;
|
|
7
|
+
abstract toTruthy(): boolean;
|
|
8
|
+
abstract fork(): CustomValue;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class CustomValueWithIntrinsics extends CustomValue {
|
|
11
|
+
abstract has(path: Path<string> | string): boolean;
|
|
12
|
+
abstract set(path: Path<string> | string, value: CustomValue): void;
|
|
13
|
+
abstract get(path: Path<string> | string): CustomValue;
|
|
14
|
+
abstract [Symbol.iterator](): Iterator<CustomValue>;
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class CustomObject extends CustomValueWithIntrinsics {
|
|
17
|
+
}
|
|
@@ -1,38 +1,40 @@
|
|
|
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
|
-
exports.
|
|
19
|
-
var
|
|
20
|
-
function
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
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
|
+
exports.CustomObject = exports.CustomValueWithIntrinsics = exports.CustomValue = void 0;
|
|
19
|
+
var CustomValue = /** @class */ (function () {
|
|
20
|
+
function CustomValue() {
|
|
21
|
+
}
|
|
22
|
+
return CustomValue;
|
|
23
|
+
}());
|
|
24
|
+
exports.CustomValue = CustomValue;
|
|
25
|
+
var CustomValueWithIntrinsics = /** @class */ (function (_super) {
|
|
26
|
+
__extends(CustomValueWithIntrinsics, _super);
|
|
27
|
+
function CustomValueWithIntrinsics() {
|
|
28
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
29
|
+
}
|
|
30
|
+
return CustomValueWithIntrinsics;
|
|
31
|
+
}(CustomValue));
|
|
32
|
+
exports.CustomValueWithIntrinsics = CustomValueWithIntrinsics;
|
|
33
|
+
var CustomObject = /** @class */ (function (_super) {
|
|
34
|
+
__extends(CustomObject, _super);
|
|
35
|
+
function CustomObject() {
|
|
36
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
37
|
+
}
|
|
38
|
+
return CustomObject;
|
|
39
|
+
}(CustomValueWithIntrinsics));
|
|
40
|
+
exports.CustomObject = CustomObject;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Path from '../utils/path';
|
|
2
|
+
import CustomFunction from './function';
|
|
3
|
+
import { CustomObject, CustomValue } from './generics';
|
|
4
|
+
export declare class CustomInterfaceIterator implements Iterator<CustomValue> {
|
|
5
|
+
next(): IteratorResult<CustomValue>;
|
|
6
|
+
}
|
|
7
|
+
export default class CustomInterface extends CustomObject {
|
|
8
|
+
private readonly interfaceFns;
|
|
9
|
+
private readonly type;
|
|
10
|
+
constructor(type: string);
|
|
11
|
+
getCustomType(): string;
|
|
12
|
+
toString(): string;
|
|
13
|
+
fork(): CustomInterface;
|
|
14
|
+
toNumber(): number;
|
|
15
|
+
toInt(): number;
|
|
16
|
+
toTruthy(): boolean;
|
|
17
|
+
[Symbol.iterator](): CustomInterfaceIterator;
|
|
18
|
+
has(path: Path<string> | string): boolean;
|
|
19
|
+
set(_path: Path<string> | string, _newValue: CustomValue): void;
|
|
20
|
+
get(path: Path<string> | string): CustomValue;
|
|
21
|
+
addFunction(name: string, fn: CustomFunction): CustomInterface;
|
|
22
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.CustomInterfaceIterator = void 0;
|
|
22
|
+
var path_1 = __importDefault(require("../utils/path"));
|
|
23
|
+
var default_1 = __importDefault(require("./default"));
|
|
24
|
+
var generics_1 = require("./generics");
|
|
25
|
+
var CustomInterfaceIterator = /** @class */ (function () {
|
|
26
|
+
function CustomInterfaceIterator() {
|
|
27
|
+
}
|
|
28
|
+
CustomInterfaceIterator.prototype.next = function () {
|
|
29
|
+
return {
|
|
30
|
+
value: default_1.default.Void,
|
|
31
|
+
done: true
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
return CustomInterfaceIterator;
|
|
35
|
+
}());
|
|
36
|
+
exports.CustomInterfaceIterator = CustomInterfaceIterator;
|
|
37
|
+
var CustomInterface = /** @class */ (function (_super) {
|
|
38
|
+
__extends(CustomInterface, _super);
|
|
39
|
+
function CustomInterface(type) {
|
|
40
|
+
var _this = _super.call(this) || this;
|
|
41
|
+
_this.type = type;
|
|
42
|
+
_this.interfaceFns = new Map();
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
CustomInterface.prototype.getCustomType = function () {
|
|
46
|
+
return this.type;
|
|
47
|
+
};
|
|
48
|
+
CustomInterface.prototype.toString = function () {
|
|
49
|
+
return this.type;
|
|
50
|
+
};
|
|
51
|
+
CustomInterface.prototype.fork = function () {
|
|
52
|
+
return this;
|
|
53
|
+
};
|
|
54
|
+
CustomInterface.prototype.toNumber = function () {
|
|
55
|
+
return Number.NaN;
|
|
56
|
+
};
|
|
57
|
+
CustomInterface.prototype.toInt = function () {
|
|
58
|
+
return 0;
|
|
59
|
+
};
|
|
60
|
+
CustomInterface.prototype.toTruthy = function () {
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
CustomInterface.prototype[Symbol.iterator] = function () {
|
|
64
|
+
return new CustomInterfaceIterator();
|
|
65
|
+
};
|
|
66
|
+
CustomInterface.prototype.has = function (path) {
|
|
67
|
+
if (typeof path === 'string') {
|
|
68
|
+
return this.has(new path_1.default([path]));
|
|
69
|
+
}
|
|
70
|
+
var traversalPath = path.clone();
|
|
71
|
+
var current = traversalPath.next();
|
|
72
|
+
if (current !== null) {
|
|
73
|
+
return this.interfaceFns.has(current);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
};
|
|
77
|
+
CustomInterface.prototype.set = function (_path, _newValue) {
|
|
78
|
+
throw new Error('Cannot set property on an interface.');
|
|
79
|
+
};
|
|
80
|
+
CustomInterface.prototype.get = function (path) {
|
|
81
|
+
if (typeof path === 'string') {
|
|
82
|
+
return this.get(new path_1.default([path]));
|
|
83
|
+
}
|
|
84
|
+
if (path.count() === 0) {
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
var traversalPath = path.clone();
|
|
88
|
+
var current = traversalPath.next();
|
|
89
|
+
if (current !== null) {
|
|
90
|
+
if (this.interfaceFns.has(current)) {
|
|
91
|
+
return this.interfaceFns.get(current);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
throw new Error("Unknown path in interface ".concat(path.toString(), "."));
|
|
95
|
+
};
|
|
96
|
+
CustomInterface.prototype.addFunction = function (name, fn) {
|
|
97
|
+
this.interfaceFns.set(name, fn);
|
|
98
|
+
return this;
|
|
99
|
+
};
|
|
100
|
+
return CustomInterface;
|
|
101
|
+
}(generics_1.CustomObject));
|
|
102
|
+
exports.default = CustomInterface;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 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 getItemIndex(item: CustomList, index: number): number;
|
|
13
|
+
private static intrinsics;
|
|
14
|
+
static getIntrinsics(): IntrinsicsContainer;
|
|
15
|
+
static addIntrinsic(name: string, fn: CustomFunction): void;
|
|
16
|
+
readonly value: Array<CustomValue>;
|
|
17
|
+
constructor(value?: Array<CustomValue>);
|
|
18
|
+
getCustomType(): string;
|
|
19
|
+
toString(): string;
|
|
20
|
+
fork(): CustomList;
|
|
21
|
+
toNumber(): number;
|
|
22
|
+
toInt(): number;
|
|
23
|
+
toTruthy(): boolean;
|
|
24
|
+
slice(a: CustomValue, b: CustomValue): CustomList;
|
|
25
|
+
extend(list: CustomList | Array<CustomValue>): CustomList;
|
|
26
|
+
[Symbol.iterator](): CustomListIterator;
|
|
27
|
+
getItemIndex(index: number): number;
|
|
28
|
+
has(path: Path<string> | string): boolean;
|
|
29
|
+
set(path: Path<string> | string, newValue: CustomValue): void;
|
|
30
|
+
get(path: Path<string> | string): CustomValue;
|
|
31
|
+
}
|