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
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ASTBase } from 'greybel-core';
|
|
2
|
-
import { Expression } from '../types/expression';
|
|
3
|
-
import { OperationContext } from '../context';
|
|
4
|
-
export interface PathEvaluationResult {
|
|
5
|
-
handle: any;
|
|
6
|
-
path: string[];
|
|
7
|
-
}
|
|
8
|
-
export declare class SliceSegment {
|
|
9
|
-
left: any;
|
|
10
|
-
right: any;
|
|
11
|
-
constructor(left: any, right: any);
|
|
12
|
-
}
|
|
13
|
-
export declare class IndexSegment {
|
|
14
|
-
value: any;
|
|
15
|
-
constructor(value: any);
|
|
16
|
-
}
|
|
17
|
-
export declare class PathSegment {
|
|
18
|
-
value: string;
|
|
19
|
-
constructor(value: string);
|
|
20
|
-
}
|
|
21
|
-
export declare class ExpressionSegment {
|
|
22
|
-
value: any[];
|
|
23
|
-
constructor();
|
|
24
|
-
append(val: any): ExpressionSegment;
|
|
25
|
-
}
|
|
26
|
-
export default class PathExpression extends Expression {
|
|
27
|
-
expr: ExpressionSegment;
|
|
28
|
-
constructor(ast: ASTBase);
|
|
29
|
-
prepare(visit: Function): Promise<PathExpression>;
|
|
30
|
-
get(operationContext: OperationContext, parentExpr: any): Promise<any>;
|
|
31
|
-
}
|
package/dist/expressions/path.js
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
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.ExpressionSegment = exports.PathSegment = exports.IndexSegment = exports.SliceSegment = void 0;
|
|
58
|
-
var greyscript_core_1 = require("greyscript-core");
|
|
59
|
-
var operation_1 = require("../types/operation");
|
|
60
|
-
var expression_1 = require("../types/expression");
|
|
61
|
-
var function_1 = __importDefault(require("../operations/function"));
|
|
62
|
-
var typer_1 = require("../typer");
|
|
63
|
-
var SliceSegment = /** @class */ (function () {
|
|
64
|
-
function SliceSegment(left, right) {
|
|
65
|
-
this.left = left;
|
|
66
|
-
this.right = right;
|
|
67
|
-
}
|
|
68
|
-
return SliceSegment;
|
|
69
|
-
}());
|
|
70
|
-
exports.SliceSegment = SliceSegment;
|
|
71
|
-
var IndexSegment = /** @class */ (function () {
|
|
72
|
-
function IndexSegment(value) {
|
|
73
|
-
this.value = value;
|
|
74
|
-
}
|
|
75
|
-
return IndexSegment;
|
|
76
|
-
}());
|
|
77
|
-
exports.IndexSegment = IndexSegment;
|
|
78
|
-
var PathSegment = /** @class */ (function () {
|
|
79
|
-
function PathSegment(value) {
|
|
80
|
-
this.value = value;
|
|
81
|
-
}
|
|
82
|
-
return PathSegment;
|
|
83
|
-
}());
|
|
84
|
-
exports.PathSegment = PathSegment;
|
|
85
|
-
var ExpressionSegment = /** @class */ (function () {
|
|
86
|
-
function ExpressionSegment() {
|
|
87
|
-
this.value = [];
|
|
88
|
-
}
|
|
89
|
-
ExpressionSegment.prototype.append = function (val) {
|
|
90
|
-
var me = this;
|
|
91
|
-
if (val instanceof ExpressionSegment) {
|
|
92
|
-
me.value = me.value.concat(val.value);
|
|
93
|
-
return me;
|
|
94
|
-
}
|
|
95
|
-
me.value = me.value.concat(val);
|
|
96
|
-
return me;
|
|
97
|
-
};
|
|
98
|
-
return ExpressionSegment;
|
|
99
|
-
}());
|
|
100
|
-
exports.ExpressionSegment = ExpressionSegment;
|
|
101
|
-
var PathExpression = /** @class */ (function (_super) {
|
|
102
|
-
__extends(PathExpression, _super);
|
|
103
|
-
function PathExpression(ast) {
|
|
104
|
-
var _this = _super.call(this) || this;
|
|
105
|
-
var me = _this;
|
|
106
|
-
me.ast = ast;
|
|
107
|
-
me.expr = null;
|
|
108
|
-
return _this;
|
|
109
|
-
}
|
|
110
|
-
PathExpression.prototype.prepare = function (visit) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
-
var me, buildExpression, _a;
|
|
113
|
-
return __generator(this, function (_b) {
|
|
114
|
-
switch (_b.label) {
|
|
115
|
-
case 0:
|
|
116
|
-
me = this;
|
|
117
|
-
buildExpression = function (node) {
|
|
118
|
-
var _a;
|
|
119
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
-
var expression, _b, memberExpression, _c, _d, _e, _f, indexExpression, _g, _h, sliceExpression, _j, _k, _l, _m, _o, _p, _q, identifier, _r, _s;
|
|
121
|
-
return __generator(this, function (_t) {
|
|
122
|
-
switch (_t.label) {
|
|
123
|
-
case 0:
|
|
124
|
-
expression = new ExpressionSegment();
|
|
125
|
-
_b = node.type;
|
|
126
|
-
switch (_b) {
|
|
127
|
-
case greyscript_core_1.ASTType.MemberExpression: return [3 /*break*/, 1];
|
|
128
|
-
case greyscript_core_1.ASTType.IndexExpression: return [3 /*break*/, 4];
|
|
129
|
-
case greyscript_core_1.ASTType.Identifier: return [3 /*break*/, 11];
|
|
130
|
-
}
|
|
131
|
-
return [3 /*break*/, 12];
|
|
132
|
-
case 1:
|
|
133
|
-
memberExpression = node;
|
|
134
|
-
_d = (_c = expression).append;
|
|
135
|
-
return [4 /*yield*/, buildExpression(memberExpression.base)];
|
|
136
|
-
case 2:
|
|
137
|
-
_d.apply(_c, [_t.sent()]);
|
|
138
|
-
_f = (_e = expression).append;
|
|
139
|
-
return [4 /*yield*/, buildExpression(memberExpression.identifier)];
|
|
140
|
-
case 3:
|
|
141
|
-
_f.apply(_e, [_t.sent()]);
|
|
142
|
-
return [3 /*break*/, 14];
|
|
143
|
-
case 4:
|
|
144
|
-
indexExpression = node;
|
|
145
|
-
_h = (_g = expression).append;
|
|
146
|
-
return [4 /*yield*/, buildExpression(indexExpression.base)];
|
|
147
|
-
case 5:
|
|
148
|
-
_h.apply(_g, [_t.sent()]);
|
|
149
|
-
if (!(((_a = indexExpression.index) === null || _a === void 0 ? void 0 : _a.type) === 'SliceExpression')) return [3 /*break*/, 8];
|
|
150
|
-
sliceExpression = indexExpression.index;
|
|
151
|
-
_k = (_j = expression).append;
|
|
152
|
-
_l = SliceSegment.bind;
|
|
153
|
-
return [4 /*yield*/, visit(sliceExpression.left)];
|
|
154
|
-
case 6:
|
|
155
|
-
_m = [void 0, _t.sent()];
|
|
156
|
-
return [4 /*yield*/, visit(sliceExpression.right)];
|
|
157
|
-
case 7:
|
|
158
|
-
_k.apply(_j, [new (_l.apply(SliceSegment, _m.concat([_t.sent()])))()]);
|
|
159
|
-
return [3 /*break*/, 10];
|
|
160
|
-
case 8:
|
|
161
|
-
_p = (_o = expression).append;
|
|
162
|
-
_q = IndexSegment.bind;
|
|
163
|
-
return [4 /*yield*/, visit(indexExpression.index)];
|
|
164
|
-
case 9:
|
|
165
|
-
_p.apply(_o, [new (_q.apply(IndexSegment, [void 0, _t.sent()]))()]);
|
|
166
|
-
_t.label = 10;
|
|
167
|
-
case 10: return [3 /*break*/, 14];
|
|
168
|
-
case 11:
|
|
169
|
-
identifier = node;
|
|
170
|
-
expression.append(new PathSegment(identifier.name));
|
|
171
|
-
return [3 /*break*/, 14];
|
|
172
|
-
case 12:
|
|
173
|
-
_s = (_r = expression).append;
|
|
174
|
-
return [4 /*yield*/, visit(node)];
|
|
175
|
-
case 13:
|
|
176
|
-
_s.apply(_r, [_t.sent()]);
|
|
177
|
-
_t.label = 14;
|
|
178
|
-
case 14: return [2 /*return*/, expression];
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
_a = me;
|
|
184
|
-
return [4 /*yield*/, buildExpression(me.ast)];
|
|
185
|
-
case 1:
|
|
186
|
-
_a.expr = _b.sent();
|
|
187
|
-
return [2 /*return*/, me];
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
PathExpression.prototype.get = function (operationContext, parentExpr) {
|
|
193
|
-
var _a;
|
|
194
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
-
var me, evaluate, resultExpr, context, value_1, _b, value, callable, _c;
|
|
196
|
-
return __generator(this, function (_d) {
|
|
197
|
-
switch (_d.label) {
|
|
198
|
-
case 0:
|
|
199
|
-
me = this;
|
|
200
|
-
evaluate = function (node) {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
-
var traverselPath, traversedPath, position, handle, current, functionContext, origin, _a, value, origin, left, right;
|
|
203
|
-
return __generator(this, function (_b) {
|
|
204
|
-
switch (_b.label) {
|
|
205
|
-
case 0:
|
|
206
|
-
traverselPath = [].concat(node.value);
|
|
207
|
-
traversedPath = [];
|
|
208
|
-
position = 0;
|
|
209
|
-
_b.label = 1;
|
|
210
|
-
case 1:
|
|
211
|
-
if (!(current = traverselPath.shift())) return [3 /*break*/, 30];
|
|
212
|
-
if (!(0, typer_1.isCustomValue)(current)) return [3 /*break*/, 2];
|
|
213
|
-
handle = current;
|
|
214
|
-
return [3 /*break*/, 29];
|
|
215
|
-
case 2:
|
|
216
|
-
if (!(current instanceof expression_1.Expression)) return [3 /*break*/, 4];
|
|
217
|
-
return [4 /*yield*/, current.get(operationContext, me.expr)];
|
|
218
|
-
case 3:
|
|
219
|
-
handle = _b.sent();
|
|
220
|
-
return [3 /*break*/, 29];
|
|
221
|
-
case 4:
|
|
222
|
-
if (!(current instanceof operation_1.Operation)) return [3 /*break*/, 6];
|
|
223
|
-
return [4 /*yield*/, current.get(operationContext)];
|
|
224
|
-
case 5:
|
|
225
|
-
handle = _b.sent();
|
|
226
|
-
return [3 /*break*/, 29];
|
|
227
|
-
case 6:
|
|
228
|
-
if (!(current instanceof PathSegment)) return [3 /*break*/, 12];
|
|
229
|
-
if (!(current.value === 'self' && position === 0)) return [3 /*break*/, 7];
|
|
230
|
-
functionContext = operationContext.getMemory('functionContext');
|
|
231
|
-
if (functionContext === null || functionContext === void 0 ? void 0 : functionContext.context) {
|
|
232
|
-
handle = functionContext.context;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
operationContext.debugger.raise('Unexpected self. Function does not appear to be bound to any context.', me, current);
|
|
236
|
-
}
|
|
237
|
-
return [3 /*break*/, 11];
|
|
238
|
-
case 7:
|
|
239
|
-
traversedPath.push(current.value);
|
|
240
|
-
if (!(traverselPath.length > 0)) return [3 /*break*/, 11];
|
|
241
|
-
return [4 /*yield*/, (handle || operationContext).get(traversedPath)];
|
|
242
|
-
case 8:
|
|
243
|
-
origin = _b.sent();
|
|
244
|
-
if (!(0, typer_1.isCustomValue)(origin)) return [3 /*break*/, 9];
|
|
245
|
-
handle = origin;
|
|
246
|
-
traversedPath = [];
|
|
247
|
-
return [3 /*break*/, 11];
|
|
248
|
-
case 9:
|
|
249
|
-
if (!(origin instanceof Function)) return [3 /*break*/, 11];
|
|
250
|
-
_a = typer_1.cast;
|
|
251
|
-
return [4 /*yield*/, origin.call(handle)];
|
|
252
|
-
case 10:
|
|
253
|
-
handle = _a.apply(void 0, [_b.sent()]);
|
|
254
|
-
traversedPath = [];
|
|
255
|
-
_b.label = 11;
|
|
256
|
-
case 11: return [3 /*break*/, 29];
|
|
257
|
-
case 12:
|
|
258
|
-
if (!(current instanceof IndexSegment)) return [3 /*break*/, 19];
|
|
259
|
-
current = current.value;
|
|
260
|
-
if (!(0, typer_1.isCustomValue)(current)) return [3 /*break*/, 13];
|
|
261
|
-
traversedPath.push(current.toString());
|
|
262
|
-
return [3 /*break*/, 16];
|
|
263
|
-
case 13:
|
|
264
|
-
if (!(current instanceof expression_1.Expression)) return [3 /*break*/, 15];
|
|
265
|
-
return [4 /*yield*/, current.get(operationContext)];
|
|
266
|
-
case 14:
|
|
267
|
-
value = _b.sent();
|
|
268
|
-
traversedPath.push(value.toString());
|
|
269
|
-
return [3 /*break*/, 16];
|
|
270
|
-
case 15:
|
|
271
|
-
operationContext.debugger.raise("Unexpected index with value ".concat(current === null || current === void 0 ? void 0 : current.toString(), " in path ").concat(traversedPath === null || traversedPath === void 0 ? void 0 : traversedPath.join('.'), " found."), me, current);
|
|
272
|
-
_b.label = 16;
|
|
273
|
-
case 16:
|
|
274
|
-
if (!(handle && !parentExpr)) return [3 /*break*/, 18];
|
|
275
|
-
return [4 /*yield*/, handle.get(traversedPath, me.expr)];
|
|
276
|
-
case 17:
|
|
277
|
-
origin = _b.sent();
|
|
278
|
-
if (origin instanceof Function || origin instanceof function_1.default) {
|
|
279
|
-
handle = origin;
|
|
280
|
-
traversedPath = [];
|
|
281
|
-
}
|
|
282
|
-
_b.label = 18;
|
|
283
|
-
case 18: return [3 /*break*/, 29];
|
|
284
|
-
case 19:
|
|
285
|
-
if (!(current instanceof SliceSegment)) return [3 /*break*/, 28];
|
|
286
|
-
if (!!handle) return [3 /*break*/, 21];
|
|
287
|
-
return [4 /*yield*/, operationContext.get(traversedPath)];
|
|
288
|
-
case 20:
|
|
289
|
-
handle = _b.sent();
|
|
290
|
-
traversedPath = [];
|
|
291
|
-
_b.label = 21;
|
|
292
|
-
case 21:
|
|
293
|
-
if (!(0, typer_1.isCustomList)(handle) && !(0, typer_1.isCustomString)(handle)) {
|
|
294
|
-
operationContext.debugger.raise("Unexpected slice attempt. ".concat(handle === null || handle === void 0 ? void 0 : handle.toString(), " does not seem to support slicing."), me, handle);
|
|
295
|
-
}
|
|
296
|
-
left = current.left;
|
|
297
|
-
if (!(0, typer_1.isCustomValue)(left)) return [3 /*break*/, 22];
|
|
298
|
-
left = left;
|
|
299
|
-
return [3 /*break*/, 24];
|
|
300
|
-
case 22:
|
|
301
|
-
if (!(left instanceof expression_1.Expression)) return [3 /*break*/, 24];
|
|
302
|
-
return [4 /*yield*/, left.get(operationContext)];
|
|
303
|
-
case 23:
|
|
304
|
-
left = _b.sent();
|
|
305
|
-
_b.label = 24;
|
|
306
|
-
case 24:
|
|
307
|
-
right = current.right;
|
|
308
|
-
if (!(0, typer_1.isCustomValue)(right)) return [3 /*break*/, 25];
|
|
309
|
-
right = right;
|
|
310
|
-
return [3 /*break*/, 27];
|
|
311
|
-
case 25:
|
|
312
|
-
if (!(right instanceof expression_1.Expression)) return [3 /*break*/, 27];
|
|
313
|
-
return [4 /*yield*/, right.get(operationContext)];
|
|
314
|
-
case 26:
|
|
315
|
-
right = _b.sent();
|
|
316
|
-
_b.label = 27;
|
|
317
|
-
case 27:
|
|
318
|
-
handle = handle.slice(left, right);
|
|
319
|
-
return [3 /*break*/, 29];
|
|
320
|
-
case 28:
|
|
321
|
-
operationContext.debugger.raise("Unexpected object in ".concat(traversedPath === null || traversedPath === void 0 ? void 0 : traversedPath.join('.'), ". Doesn't seem to be a function."), me, current);
|
|
322
|
-
_b.label = 29;
|
|
323
|
-
case 29:
|
|
324
|
-
position++;
|
|
325
|
-
return [3 /*break*/, 1];
|
|
326
|
-
case 30: return [2 /*return*/, {
|
|
327
|
-
handle: handle,
|
|
328
|
-
path: traversedPath
|
|
329
|
-
}];
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
};
|
|
334
|
-
operationContext.debugger.debug('Line', me.ast.start.line, 'PathExpression', 'get', 'expr', me.expr);
|
|
335
|
-
return [4 /*yield*/, evaluate(me.expr)];
|
|
336
|
-
case 1:
|
|
337
|
-
resultExpr = _d.sent();
|
|
338
|
-
if (!!parentExpr) return [3 /*break*/, 14];
|
|
339
|
-
if (!resultExpr.handle) return [3 /*break*/, 8];
|
|
340
|
-
if (!(resultExpr.path.length === 0)) return [3 /*break*/, 2];
|
|
341
|
-
return [2 /*return*/, resultExpr.handle];
|
|
342
|
-
case 2:
|
|
343
|
-
if (!((0, typer_1.isCustomMap)(resultExpr.handle) ||
|
|
344
|
-
(0, typer_1.isCustomList)(resultExpr.handle) ||
|
|
345
|
-
(0, typer_1.isCustomString)(resultExpr.handle))) return [3 /*break*/, 7];
|
|
346
|
-
context = resultExpr.handle;
|
|
347
|
-
return [4 /*yield*/, context.get(resultExpr.path)];
|
|
348
|
-
case 3:
|
|
349
|
-
value_1 = _d.sent();
|
|
350
|
-
if (!(value_1 instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
351
|
-
return [2 /*return*/, value_1.run(operationContext)];
|
|
352
|
-
case 4:
|
|
353
|
-
if (!(value_1 instanceof Function)) return [3 /*break*/, 6];
|
|
354
|
-
_b = typer_1.cast;
|
|
355
|
-
return [4 /*yield*/, value_1.call(context)];
|
|
356
|
-
case 5: return [2 /*return*/, _b.apply(void 0, [_d.sent()])];
|
|
357
|
-
case 6: return [2 /*return*/, value_1];
|
|
358
|
-
case 7:
|
|
359
|
-
operationContext.debugger.raise("Cannot call ".concat((_a = resultExpr.path) === null || _a === void 0 ? void 0 : _a.join('.'), ". Doesn't seem to be a function."), me, resultExpr);
|
|
360
|
-
_d.label = 8;
|
|
361
|
-
case 8: return [4 /*yield*/, operationContext.get(resultExpr.path)];
|
|
362
|
-
case 9:
|
|
363
|
-
value = _d.sent();
|
|
364
|
-
if (!(value instanceof Function)) return [3 /*break*/, 12];
|
|
365
|
-
return [4 /*yield*/, operationContext.getCallable(resultExpr.path)];
|
|
366
|
-
case 10:
|
|
367
|
-
callable = _d.sent();
|
|
368
|
-
_c = typer_1.cast;
|
|
369
|
-
return [4 /*yield*/, callable.origin.call(callable.context)];
|
|
370
|
-
case 11: return [2 /*return*/, _c.apply(void 0, [_d.sent()])];
|
|
371
|
-
case 12:
|
|
372
|
-
if (value instanceof operation_1.Operation) {
|
|
373
|
-
return [2 /*return*/, value.run(operationContext)];
|
|
374
|
-
}
|
|
375
|
-
_d.label = 13;
|
|
376
|
-
case 13: return [2 /*return*/, value];
|
|
377
|
-
case 14: return [2 /*return*/, resultExpr];
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
};
|
|
382
|
-
return PathExpression;
|
|
383
|
-
}(expression_1.Expression));
|
|
384
|
-
exports.default = PathExpression;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Operation } from '../types/operation';
|
|
2
|
-
import { ASTBase } from 'greybel-core';
|
|
3
|
-
import { OperationContext } from '../context';
|
|
4
|
-
export default class ArgumentOperation extends Operation {
|
|
5
|
-
stack: any[];
|
|
6
|
-
constructor(ast: ASTBase[]);
|
|
7
|
-
get(operationContext: OperationContext): Promise<any[]>;
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Operation } from '../types/operation';
|
|
2
|
-
import { ASTBase } from 'greybel-core';
|
|
3
|
-
import { OperationContext } from '../context';
|
|
4
|
-
export default class BodyOperation extends Operation {
|
|
5
|
-
stack: any[];
|
|
6
|
-
constructor(ast: ASTBase[]);
|
|
7
|
-
run(operationContext: OperationContext): Promise<void>;
|
|
8
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Operation } from '../types/operation';
|
|
2
|
-
import { OperationContext } from '../context';
|
|
3
|
-
import { ASTBase } from 'greybel-core';
|
|
4
|
-
export default class DebuggerOperation extends Operation {
|
|
5
|
-
constructor(ast: ASTBase);
|
|
6
|
-
run(operationContext: OperationContext): void;
|
|
7
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Operation } from '../types/operation';
|
|
2
|
-
import { ASTBase } from 'greybel-core';
|
|
3
|
-
import BodyOperation from './body';
|
|
4
|
-
export interface ElseIfOperationOptions {
|
|
5
|
-
condition: any;
|
|
6
|
-
body: BodyOperation;
|
|
7
|
-
}
|
|
8
|
-
export default class ElseIfOperation extends Operation {
|
|
9
|
-
condition: any;
|
|
10
|
-
body: any;
|
|
11
|
-
constructor(ast: ASTBase, options: ElseIfOperationOptions);
|
|
12
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Operation } from '../types/operation';
|
|
2
|
-
import { ASTBase } from 'greybel-core';
|
|
3
|
-
import BodyOperation from './body';
|
|
4
|
-
export interface ElseOperationOptions {
|
|
5
|
-
body: BodyOperation;
|
|
6
|
-
}
|
|
7
|
-
export default class ElseOperation extends Operation {
|
|
8
|
-
body: any;
|
|
9
|
-
constructor(ast: ASTBase, options: ElseOperationOptions);
|
|
10
|
-
}
|
package/dist/operations/if.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Operation } from '../types/operation';
|
|
2
|
-
import { ASTBase } from 'greybel-core';
|
|
3
|
-
import BodyOperation from './body';
|
|
4
|
-
export interface IfOperationOptions {
|
|
5
|
-
condition: any;
|
|
6
|
-
body: BodyOperation;
|
|
7
|
-
}
|
|
8
|
-
export default class IfOperation extends Operation {
|
|
9
|
-
condition: any;
|
|
10
|
-
body: BodyOperation;
|
|
11
|
-
constructor(ast: ASTBase, options: IfOperationOptions);
|
|
12
|
-
}
|
package/dist/operations/new.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Operation } from '../types/operation';
|
|
2
|
-
import { OperationContext } from '../context';
|
|
3
|
-
import { ASTBase } from 'greybel-core';
|
|
4
|
-
export interface NewOperationOptions {
|
|
5
|
-
arg: any;
|
|
6
|
-
}
|
|
7
|
-
export default class NewOperation extends Operation {
|
|
8
|
-
arg: any;
|
|
9
|
-
constructor(ast: ASTBase, options: NewOperationOptions);
|
|
10
|
-
get(operationContext: OperationContext): Promise<any>;
|
|
11
|
-
}
|
package/dist/resource.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export interface ResourceHandler {
|
|
2
|
-
getTargetRelativeTo(source: string, target: string): Promise<string>;
|
|
3
|
-
has(target: string): Promise<boolean>;
|
|
4
|
-
get(target: string): Promise<string>;
|
|
5
|
-
resolve(target: string): Promise<string>;
|
|
6
|
-
}
|
|
7
|
-
export declare class ResourceProvider {
|
|
8
|
-
getHandler(): ResourceHandler;
|
|
9
|
-
}
|
package/dist/resource.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceProvider = void 0;
|
|
4
|
-
var ResourceProvider = /** @class */ (function () {
|
|
5
|
-
function ResourceProvider() {
|
|
6
|
-
}
|
|
7
|
-
ResourceProvider.prototype.getHandler = function () {
|
|
8
|
-
var fs = require('fs');
|
|
9
|
-
var path = require('path');
|
|
10
|
-
return {
|
|
11
|
-
getTargetRelativeTo: function (source, target) {
|
|
12
|
-
var base = path.resolve(source, '..');
|
|
13
|
-
var result = path.resolve(base, target);
|
|
14
|
-
return Promise.resolve(fs.existsSync(result) ? result : result + '.src');
|
|
15
|
-
},
|
|
16
|
-
has: function (target) {
|
|
17
|
-
return Promise.resolve(fs.existsSync(target));
|
|
18
|
-
},
|
|
19
|
-
get: function (target) {
|
|
20
|
-
return Promise.resolve(fs.readFileSync(target, 'utf8'));
|
|
21
|
-
},
|
|
22
|
-
resolve: function (target) {
|
|
23
|
-
return Promise.resolve(path.resolve(target));
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
return ResourceProvider;
|
|
28
|
-
}());
|
|
29
|
-
exports.ResourceProvider = ResourceProvider;
|
package/dist/typer.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const isCustomValue: (value: any) => boolean;
|
|
2
|
-
export declare const isCustomMap: (value: any) => boolean;
|
|
3
|
-
export declare const isCustomList: (value: any) => boolean;
|
|
4
|
-
export declare const isCustomString: (value: any) => boolean;
|
|
5
|
-
export declare const isCustomNumber: (value: any) => boolean;
|
|
6
|
-
export declare const cast: (value: any) => any;
|
package/dist/typer.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.cast = exports.isCustomNumber = exports.isCustomString = exports.isCustomList = exports.isCustomMap = exports.isCustomValue = void 0;
|
|
23
|
-
var boolean_1 = __importDefault(require("./custom-types/boolean"));
|
|
24
|
-
var list_1 = __importDefault(require("./custom-types/list"));
|
|
25
|
-
var map_1 = __importDefault(require("./custom-types/map"));
|
|
26
|
-
var nil_1 = __importDefault(require("./custom-types/nil"));
|
|
27
|
-
var number_1 = __importDefault(require("./custom-types/number"));
|
|
28
|
-
var string_1 = __importDefault(require("./custom-types/string"));
|
|
29
|
-
var operation_1 = require("./types/operation");
|
|
30
|
-
var isCustomValue = function (value) {
|
|
31
|
-
return value instanceof boolean_1.default ||
|
|
32
|
-
value instanceof number_1.default ||
|
|
33
|
-
value instanceof list_1.default ||
|
|
34
|
-
value instanceof map_1.default ||
|
|
35
|
-
value instanceof nil_1.default ||
|
|
36
|
-
value instanceof string_1.default;
|
|
37
|
-
};
|
|
38
|
-
exports.isCustomValue = isCustomValue;
|
|
39
|
-
var isCustomMap = function (value) {
|
|
40
|
-
return value instanceof map_1.default;
|
|
41
|
-
};
|
|
42
|
-
exports.isCustomMap = isCustomMap;
|
|
43
|
-
var isCustomList = function (value) {
|
|
44
|
-
return value instanceof list_1.default;
|
|
45
|
-
};
|
|
46
|
-
exports.isCustomList = isCustomList;
|
|
47
|
-
var isCustomString = function (value) {
|
|
48
|
-
return value instanceof string_1.default;
|
|
49
|
-
};
|
|
50
|
-
exports.isCustomString = isCustomString;
|
|
51
|
-
var isCustomNumber = function (value) {
|
|
52
|
-
return value instanceof number_1.default;
|
|
53
|
-
};
|
|
54
|
-
exports.isCustomNumber = isCustomNumber;
|
|
55
|
-
var cast = function (value) {
|
|
56
|
-
if (value == null)
|
|
57
|
-
return new nil_1.default();
|
|
58
|
-
if ((0, exports.isCustomValue)(value) || value instanceof operation_1.Operation) {
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
var type = typeof value;
|
|
62
|
-
if (type === 'string') {
|
|
63
|
-
return new string_1.default(value);
|
|
64
|
-
}
|
|
65
|
-
else if (type === 'number') {
|
|
66
|
-
return new number_1.default(value);
|
|
67
|
-
}
|
|
68
|
-
else if (type === 'boolean') {
|
|
69
|
-
return new boolean_1.default(value);
|
|
70
|
-
}
|
|
71
|
-
else if (type === 'object') {
|
|
72
|
-
if (Array.isArray(value)) {
|
|
73
|
-
value = value.map(exports.cast);
|
|
74
|
-
return new list_1.default(value);
|
|
75
|
-
}
|
|
76
|
-
var result_1 = new Map();
|
|
77
|
-
if (value instanceof Map) {
|
|
78
|
-
value.forEach(function (item, key) {
|
|
79
|
-
result_1.set(key, (0, exports.cast)(item));
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
Object.entries(value).forEach(function (_a) {
|
|
84
|
-
var _b = __read(_a, 2), key = _b[0], item = _b[1];
|
|
85
|
-
result_1.set(key, (0, exports.cast)(item));
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return new map_1.default(result_1);
|
|
89
|
-
}
|
|
90
|
-
else if (type === 'function') {
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
throw new Error("Unexpected type ".concat(type));
|
|
94
|
-
};
|
|
95
|
-
exports.cast = cast;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare abstract class CustomType {
|
|
2
|
-
static intrinsics: Map<string, Function>;
|
|
3
|
-
getType(): string;
|
|
4
|
-
toNumber(): number;
|
|
5
|
-
toString(): string;
|
|
6
|
-
toTruthy(): boolean;
|
|
7
|
-
valueOf(): any;
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class CustomLiteralType extends CustomType {
|
|
10
|
-
value: any;
|
|
11
|
-
}
|
|
12
|
-
export declare abstract class CustomObjectType extends CustomType {
|
|
13
|
-
value: any;
|
|
14
|
-
has(path: any[]): Promise<boolean>;
|
|
15
|
-
set(path: any[], value: any): Promise<void>;
|
|
16
|
-
get(path: any[]): Promise<any>;
|
|
17
|
-
getCallable(path: any[]): Promise<Callable>;
|
|
18
|
-
}
|
|
19
|
-
export interface Callable {
|
|
20
|
-
origin: any;
|
|
21
|
-
context: any;
|
|
22
|
-
}
|