greybel-interpreter 0.1.9 → 0.2.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/dist/context.js +9 -7
- package/dist/cps.d.ts +1 -1
- package/dist/cps.js +665 -287
- package/dist/expressions/assign.d.ts +2 -1
- package/dist/expressions/assign.js +23 -5
- package/dist/expressions/binary-negated-expression.d.ts +2 -1
- package/dist/expressions/binary-negated-expression.js +21 -5
- package/dist/expressions/call.d.ts +2 -1
- package/dist/expressions/call.js +37 -8
- package/dist/expressions/list.d.ts +2 -1
- package/dist/expressions/list.js +22 -7
- package/dist/expressions/logical-and-binary.d.ts +2 -1
- package/dist/expressions/logical-and-binary.js +25 -5
- package/dist/expressions/map.d.ts +2 -1
- package/dist/expressions/map.js +35 -10
- package/dist/expressions/path.d.ts +2 -1
- package/dist/expressions/path.js +84 -31
- package/dist/interpreter.d.ts +1 -1
- package/dist/interpreter.js +80 -23
- package/dist/resource.d.ts +4 -4
- package/dist/resource.js +4 -4
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ export declare class ExpressionSegment {
|
|
|
7
7
|
constructor(left: any, right: any);
|
|
8
8
|
}
|
|
9
9
|
export default class AssignExpression extends Expression {
|
|
10
|
-
constructor(ast: ASTAssignmentStatement
|
|
10
|
+
constructor(ast: ASTAssignmentStatement);
|
|
11
|
+
prepare(visit: Function): Promise<AssignExpression>;
|
|
11
12
|
get(operationContext: OperationContext, parentExpr: any): Promise<any>;
|
|
12
13
|
}
|
|
@@ -67,16 +67,34 @@ var ExpressionSegment = /** @class */ (function () {
|
|
|
67
67
|
exports.ExpressionSegment = ExpressionSegment;
|
|
68
68
|
var AssignExpression = /** @class */ (function (_super) {
|
|
69
69
|
__extends(AssignExpression, _super);
|
|
70
|
-
function AssignExpression(ast
|
|
70
|
+
function AssignExpression(ast) {
|
|
71
71
|
var _this = _super.call(this) || this;
|
|
72
72
|
var me = _this;
|
|
73
|
-
var buildExpression = function (node) {
|
|
74
|
-
return new ExpressionSegment(visit(node.variable), visit(node.init));
|
|
75
|
-
};
|
|
76
73
|
me.ast = ast;
|
|
77
|
-
me.expr =
|
|
74
|
+
me.expr = null;
|
|
78
75
|
return _this;
|
|
79
76
|
}
|
|
77
|
+
AssignExpression.prototype.prepare = function (visit) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var me, node, _a, _b, _c;
|
|
80
|
+
return __generator(this, function (_d) {
|
|
81
|
+
switch (_d.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
me = this;
|
|
84
|
+
node = me.ast;
|
|
85
|
+
_a = me;
|
|
86
|
+
_b = ExpressionSegment.bind;
|
|
87
|
+
return [4 /*yield*/, visit(node.variable)];
|
|
88
|
+
case 1:
|
|
89
|
+
_c = [void 0, _d.sent()];
|
|
90
|
+
return [4 /*yield*/, visit(node.init)];
|
|
91
|
+
case 2:
|
|
92
|
+
_a.expr = new (_b.apply(ExpressionSegment, _c.concat([_d.sent()])))();
|
|
93
|
+
return [2 /*return*/, me];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
80
98
|
AssignExpression.prototype.get = function (operationContext, parentExpr) {
|
|
81
99
|
return __awaiter(this, void 0, void 0, function () {
|
|
82
100
|
var me, evaluate;
|
|
@@ -13,6 +13,7 @@ export declare class ExpressionSegment {
|
|
|
13
13
|
}
|
|
14
14
|
export default class BinaryNegatedExpression extends Expression {
|
|
15
15
|
expr: ExpressionSegment;
|
|
16
|
-
constructor(ast: ASTUnaryExpression
|
|
16
|
+
constructor(ast: ASTUnaryExpression);
|
|
17
|
+
prepare(visit: Function): Promise<BinaryNegatedExpression>;
|
|
17
18
|
get(operationContext: OperationContext): any;
|
|
18
19
|
}
|
|
@@ -75,16 +75,32 @@ var ExpressionSegment = /** @class */ (function () {
|
|
|
75
75
|
exports.ExpressionSegment = ExpressionSegment;
|
|
76
76
|
var BinaryNegatedExpression = /** @class */ (function (_super) {
|
|
77
77
|
__extends(BinaryNegatedExpression, _super);
|
|
78
|
-
function BinaryNegatedExpression(ast
|
|
78
|
+
function BinaryNegatedExpression(ast) {
|
|
79
79
|
var _this = _super.call(this) || this;
|
|
80
80
|
var me = _this;
|
|
81
|
-
var buildExpression = function (node) {
|
|
82
|
-
return new ExpressionSegment(node.operator, visit(node.argument));
|
|
83
|
-
};
|
|
84
81
|
me.ast = ast;
|
|
85
|
-
me.expr =
|
|
82
|
+
me.expr = null;
|
|
86
83
|
return _this;
|
|
87
84
|
}
|
|
85
|
+
BinaryNegatedExpression.prototype.prepare = function (visit) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var me, node, _a, _b, _c;
|
|
88
|
+
return __generator(this, function (_d) {
|
|
89
|
+
switch (_d.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
me = this;
|
|
92
|
+
node = me.ast;
|
|
93
|
+
_a = me;
|
|
94
|
+
_b = ExpressionSegment.bind;
|
|
95
|
+
_c = [void 0, node.operator];
|
|
96
|
+
return [4 /*yield*/, visit(node.argument)];
|
|
97
|
+
case 1:
|
|
98
|
+
_a.expr = new (_b.apply(ExpressionSegment, _c.concat([_d.sent()])))();
|
|
99
|
+
return [2 /*return*/, me];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
};
|
|
88
104
|
BinaryNegatedExpression.prototype.get = function (operationContext) {
|
|
89
105
|
var me = this;
|
|
90
106
|
var evaluate = function (node) {
|
|
@@ -8,6 +8,7 @@ export declare class ExpressionSegment {
|
|
|
8
8
|
}
|
|
9
9
|
export default class CallExpression extends Expression {
|
|
10
10
|
expr: ExpressionSegment;
|
|
11
|
-
constructor(ast: any
|
|
11
|
+
constructor(ast: any);
|
|
12
|
+
prepare(visit: Function): Promise<CallExpression>;
|
|
12
13
|
get(operationContext: OperationContext, parentExpr: any): Promise<any>;
|
|
13
14
|
}
|
package/dist/expressions/call.js
CHANGED
|
@@ -105,19 +105,48 @@ var ExpressionSegment = /** @class */ (function () {
|
|
|
105
105
|
exports.ExpressionSegment = ExpressionSegment;
|
|
106
106
|
var CallExpression = /** @class */ (function (_super) {
|
|
107
107
|
__extends(CallExpression, _super);
|
|
108
|
-
function CallExpression(ast
|
|
108
|
+
function CallExpression(ast) {
|
|
109
109
|
var _this = _super.call(this) || this;
|
|
110
110
|
var me = _this;
|
|
111
|
-
var buildExpression = function (node) {
|
|
112
|
-
if (greyscript_core_1.ASTType.CallStatement === node.type) {
|
|
113
|
-
return buildExpression(node.expression);
|
|
114
|
-
}
|
|
115
|
-
return new ExpressionSegment(visit(node.base), node.arguments.map(function (item) { return visit(item); }));
|
|
116
|
-
};
|
|
117
111
|
me.ast = ast;
|
|
118
|
-
me.expr =
|
|
112
|
+
me.expr = null;
|
|
119
113
|
return _this;
|
|
120
114
|
}
|
|
115
|
+
CallExpression.prototype.prepare = function (visit) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
+
var me, buildExpression, _a;
|
|
118
|
+
return __generator(this, function (_b) {
|
|
119
|
+
switch (_b.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
me = this;
|
|
122
|
+
buildExpression = function (node) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
return __generator(this, function (_c) {
|
|
126
|
+
switch (_c.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
if (greyscript_core_1.ASTType.CallStatement === node.type) {
|
|
129
|
+
return [2 /*return*/, buildExpression(node.expression)];
|
|
130
|
+
}
|
|
131
|
+
_a = ExpressionSegment.bind;
|
|
132
|
+
return [4 /*yield*/, visit(node.base)];
|
|
133
|
+
case 1:
|
|
134
|
+
_b = [void 0, _c.sent()];
|
|
135
|
+
return [4 /*yield*/, Promise.all(node.arguments.map(function (item) { return visit(item); }))];
|
|
136
|
+
case 2: return [2 /*return*/, new (_a.apply(ExpressionSegment, _b.concat([_c.sent()])))()];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
_a = me;
|
|
142
|
+
return [4 /*yield*/, buildExpression(me.ast)];
|
|
143
|
+
case 1:
|
|
144
|
+
_a.expr = _b.sent();
|
|
145
|
+
return [2 /*return*/, me];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
121
150
|
CallExpression.prototype.get = function (operationContext, parentExpr) {
|
|
122
151
|
var me = this;
|
|
123
152
|
var opc = operationContext.fork(context_1.ContextType.CALL, context_1.ContextState.TEMPORARY);
|
|
@@ -8,6 +8,7 @@ export declare class ExpressionSegment {
|
|
|
8
8
|
}
|
|
9
9
|
export default class ListExpression extends Expression {
|
|
10
10
|
expr: ExpressionSegment;
|
|
11
|
-
constructor(ast: ASTListConstructorExpression
|
|
11
|
+
constructor(ast: ASTListConstructorExpression);
|
|
12
|
+
prepare(visit: Function): Promise<ListExpression>;
|
|
12
13
|
get(operationContext: OperationContext, parentExpr: any): Promise<CustomList>;
|
|
13
14
|
}
|
package/dist/expressions/list.js
CHANGED
|
@@ -67,18 +67,33 @@ var ExpressionSegment = /** @class */ (function () {
|
|
|
67
67
|
exports.ExpressionSegment = ExpressionSegment;
|
|
68
68
|
var ListExpression = /** @class */ (function (_super) {
|
|
69
69
|
__extends(ListExpression, _super);
|
|
70
|
-
function ListExpression(ast
|
|
70
|
+
function ListExpression(ast) {
|
|
71
71
|
var _this = _super.call(this) || this;
|
|
72
72
|
var me = _this;
|
|
73
|
-
var buildExpression = function (node) {
|
|
74
|
-
return new ExpressionSegment(node.fields.map(function (item) {
|
|
75
|
-
return visit(item.value);
|
|
76
|
-
}));
|
|
77
|
-
};
|
|
78
73
|
me.ast = ast;
|
|
79
|
-
me.expr =
|
|
74
|
+
me.expr = null;
|
|
80
75
|
return _this;
|
|
81
76
|
}
|
|
77
|
+
ListExpression.prototype.prepare = function (visit) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var me, node, _a, _b;
|
|
80
|
+
return __generator(this, function (_c) {
|
|
81
|
+
switch (_c.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
me = this;
|
|
84
|
+
node = me.ast;
|
|
85
|
+
_a = me;
|
|
86
|
+
_b = ExpressionSegment.bind;
|
|
87
|
+
return [4 /*yield*/, Promise.all(node.fields.map(function (item) {
|
|
88
|
+
return visit(item.value);
|
|
89
|
+
}))];
|
|
90
|
+
case 1:
|
|
91
|
+
_a.expr = new (_b.apply(ExpressionSegment, [void 0, _c.sent()]))();
|
|
92
|
+
return [2 /*return*/, me];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
82
97
|
ListExpression.prototype.get = function (operationContext, parentExpr) {
|
|
83
98
|
var me = this;
|
|
84
99
|
var evaluate = function (node) {
|
|
@@ -17,6 +17,7 @@ export declare class ExpressionSegment {
|
|
|
17
17
|
}
|
|
18
18
|
export default class LogicalAndBinaryExpression extends Expression {
|
|
19
19
|
expr: ExpressionSegment;
|
|
20
|
-
constructor(ast: ASTEvaluationExpression
|
|
20
|
+
constructor(ast: ASTEvaluationExpression);
|
|
21
|
+
prepare(visit: Function): Promise<LogicalAndBinaryExpression>;
|
|
21
22
|
get(operationContext: OperationContext): Promise<any>;
|
|
22
23
|
}
|
|
@@ -123,16 +123,36 @@ var ExpressionSegment = /** @class */ (function () {
|
|
|
123
123
|
exports.ExpressionSegment = ExpressionSegment;
|
|
124
124
|
var LogicalAndBinaryExpression = /** @class */ (function (_super) {
|
|
125
125
|
__extends(LogicalAndBinaryExpression, _super);
|
|
126
|
-
function LogicalAndBinaryExpression(ast
|
|
126
|
+
function LogicalAndBinaryExpression(ast) {
|
|
127
127
|
var _this = _super.call(this) || this;
|
|
128
128
|
var me = _this;
|
|
129
|
-
var buildExpression = function (node) {
|
|
130
|
-
return new ExpressionSegment(node.type, node.operator, visit(node.left), visit(node.right));
|
|
131
|
-
};
|
|
132
129
|
me.ast = ast;
|
|
133
|
-
me.expr =
|
|
130
|
+
me.expr = null;
|
|
134
131
|
return _this;
|
|
135
132
|
}
|
|
133
|
+
LogicalAndBinaryExpression.prototype.prepare = function (visit) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var me, node, _a, _b, _c;
|
|
136
|
+
return __generator(this, function (_d) {
|
|
137
|
+
switch (_d.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
me = this;
|
|
140
|
+
node = me.ast;
|
|
141
|
+
_a = me;
|
|
142
|
+
_b = ExpressionSegment.bind;
|
|
143
|
+
_c = [void 0, node.type,
|
|
144
|
+
node.operator];
|
|
145
|
+
return [4 /*yield*/, visit(node.left)];
|
|
146
|
+
case 1:
|
|
147
|
+
_c = _c.concat([_d.sent()]);
|
|
148
|
+
return [4 /*yield*/, visit(node.right)];
|
|
149
|
+
case 2:
|
|
150
|
+
_a.expr = new (_b.apply(ExpressionSegment, _c.concat([_d.sent()])))();
|
|
151
|
+
return [2 /*return*/, me];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
136
156
|
LogicalAndBinaryExpression.prototype.get = function (operationContext) {
|
|
137
157
|
var _this = this;
|
|
138
158
|
var me = this;
|
|
@@ -13,6 +13,7 @@ export declare class ExpressionSegment {
|
|
|
13
13
|
}
|
|
14
14
|
export default class MapExpression extends Expression {
|
|
15
15
|
expr: ExpressionSegment;
|
|
16
|
-
constructor(ast: ASTMapConstructorExpression
|
|
16
|
+
constructor(ast: ASTMapConstructorExpression);
|
|
17
|
+
prepare(visit: Function): Promise<MapExpression>;
|
|
17
18
|
get(operationContext: OperationContext, parentExpr: any): Promise<CustomMap>;
|
|
18
19
|
}
|
package/dist/expressions/map.js
CHANGED
|
@@ -87,21 +87,46 @@ var ExpressionSegment = /** @class */ (function () {
|
|
|
87
87
|
exports.ExpressionSegment = ExpressionSegment;
|
|
88
88
|
var MapExpression = /** @class */ (function (_super) {
|
|
89
89
|
__extends(MapExpression, _super);
|
|
90
|
-
function MapExpression(ast
|
|
90
|
+
function MapExpression(ast) {
|
|
91
91
|
var _this = _super.call(this) || this;
|
|
92
92
|
var me = _this;
|
|
93
|
-
var buildExpression = function (node) {
|
|
94
|
-
return new ExpressionSegment(node.fields.map(function (item) {
|
|
95
|
-
return {
|
|
96
|
-
key: visit(item.key),
|
|
97
|
-
value: visit(item.value)
|
|
98
|
-
};
|
|
99
|
-
}));
|
|
100
|
-
};
|
|
101
93
|
me.ast = ast;
|
|
102
|
-
me.expr =
|
|
94
|
+
me.expr = null;
|
|
103
95
|
return _this;
|
|
104
96
|
}
|
|
97
|
+
MapExpression.prototype.prepare = function (visit) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
+
var me, node, _a, _b;
|
|
100
|
+
var _this = this;
|
|
101
|
+
return __generator(this, function (_c) {
|
|
102
|
+
switch (_c.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
me = this;
|
|
105
|
+
node = me.ast;
|
|
106
|
+
_a = me;
|
|
107
|
+
_b = ExpressionSegment.bind;
|
|
108
|
+
return [4 /*yield*/, Promise.all(node.fields.map(function (item) { return __awaiter(_this, void 0, void 0, function () {
|
|
109
|
+
var _a;
|
|
110
|
+
return __generator(this, function (_b) {
|
|
111
|
+
switch (_b.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
_a = {};
|
|
114
|
+
return [4 /*yield*/, visit(item.key)];
|
|
115
|
+
case 1:
|
|
116
|
+
_a.key = _b.sent();
|
|
117
|
+
return [4 /*yield*/, visit(item.value)];
|
|
118
|
+
case 2: return [2 /*return*/, (_a.value = _b.sent(),
|
|
119
|
+
_a)];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}); }))];
|
|
123
|
+
case 1:
|
|
124
|
+
_a.expr = new (_b.apply(ExpressionSegment, [void 0, _c.sent()]))();
|
|
125
|
+
return [2 /*return*/, me];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
105
130
|
MapExpression.prototype.get = function (operationContext, parentExpr) {
|
|
106
131
|
var me = this;
|
|
107
132
|
var evaluate = function (values) {
|
|
@@ -25,6 +25,7 @@ export declare class ExpressionSegment {
|
|
|
25
25
|
}
|
|
26
26
|
export default class PathExpression extends Expression {
|
|
27
27
|
expr: ExpressionSegment;
|
|
28
|
-
constructor(ast: ASTBase
|
|
28
|
+
constructor(ast: ASTBase);
|
|
29
|
+
prepare(visit: Function): Promise<PathExpression>;
|
|
29
30
|
get(operationContext: OperationContext, parentExpr: any): Promise<any>;
|
|
30
31
|
}
|
package/dist/expressions/path.js
CHANGED
|
@@ -96,42 +96,95 @@ var ExpressionSegment = /** @class */ (function () {
|
|
|
96
96
|
exports.ExpressionSegment = ExpressionSegment;
|
|
97
97
|
var PathExpression = /** @class */ (function (_super) {
|
|
98
98
|
__extends(PathExpression, _super);
|
|
99
|
-
function PathExpression(ast
|
|
99
|
+
function PathExpression(ast) {
|
|
100
100
|
var _this = _super.call(this) || this;
|
|
101
101
|
var me = _this;
|
|
102
|
-
var buildExpression = function (node) {
|
|
103
|
-
var _a;
|
|
104
|
-
var expression = new ExpressionSegment();
|
|
105
|
-
switch (node.type) {
|
|
106
|
-
case greyscript_core_1.ASTType.MemberExpression:
|
|
107
|
-
var memberExpression = node;
|
|
108
|
-
expression.append(buildExpression(memberExpression.base));
|
|
109
|
-
expression.append(buildExpression(memberExpression.identifier));
|
|
110
|
-
break;
|
|
111
|
-
case greyscript_core_1.ASTType.IndexExpression:
|
|
112
|
-
var indexExpression = node;
|
|
113
|
-
expression.append(buildExpression(indexExpression.base));
|
|
114
|
-
if (((_a = indexExpression.index) === null || _a === void 0 ? void 0 : _a.type) === 'SliceExpression') {
|
|
115
|
-
var sliceExpression = indexExpression.index;
|
|
116
|
-
expression.append(new SliceSegment(visit(sliceExpression.left), visit(sliceExpression.right)));
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
expression.append(new IndexSegment(visit(indexExpression.index)));
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
case greyscript_core_1.ASTType.Identifier:
|
|
123
|
-
var identifier = node;
|
|
124
|
-
expression.append(new PathSegment(identifier.name));
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
expression.append(visit(node));
|
|
128
|
-
}
|
|
129
|
-
return expression;
|
|
130
|
-
};
|
|
131
102
|
me.ast = ast;
|
|
132
|
-
me.expr =
|
|
103
|
+
me.expr = null;
|
|
133
104
|
return _this;
|
|
134
105
|
}
|
|
106
|
+
PathExpression.prototype.prepare = function (visit) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
var me, buildExpression, _a;
|
|
109
|
+
return __generator(this, function (_b) {
|
|
110
|
+
switch (_b.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
me = this;
|
|
113
|
+
buildExpression = function (node) {
|
|
114
|
+
var _a;
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var expression, _b, memberExpression, _c, _d, _e, _f, indexExpression, _g, _h, sliceExpression, _j, _k, _l, _m, _o, _p, _q, identifier, _r, _s;
|
|
117
|
+
return __generator(this, function (_t) {
|
|
118
|
+
switch (_t.label) {
|
|
119
|
+
case 0:
|
|
120
|
+
expression = new ExpressionSegment();
|
|
121
|
+
_b = node.type;
|
|
122
|
+
switch (_b) {
|
|
123
|
+
case greyscript_core_1.ASTType.MemberExpression: return [3 /*break*/, 1];
|
|
124
|
+
case greyscript_core_1.ASTType.IndexExpression: return [3 /*break*/, 4];
|
|
125
|
+
case greyscript_core_1.ASTType.Identifier: return [3 /*break*/, 11];
|
|
126
|
+
}
|
|
127
|
+
return [3 /*break*/, 12];
|
|
128
|
+
case 1:
|
|
129
|
+
memberExpression = node;
|
|
130
|
+
_d = (_c = expression).append;
|
|
131
|
+
return [4 /*yield*/, buildExpression(memberExpression.base)];
|
|
132
|
+
case 2:
|
|
133
|
+
_d.apply(_c, [_t.sent()]);
|
|
134
|
+
_f = (_e = expression).append;
|
|
135
|
+
return [4 /*yield*/, buildExpression(memberExpression.identifier)];
|
|
136
|
+
case 3:
|
|
137
|
+
_f.apply(_e, [_t.sent()]);
|
|
138
|
+
return [3 /*break*/, 14];
|
|
139
|
+
case 4:
|
|
140
|
+
indexExpression = node;
|
|
141
|
+
_h = (_g = expression).append;
|
|
142
|
+
return [4 /*yield*/, buildExpression(indexExpression.base)];
|
|
143
|
+
case 5:
|
|
144
|
+
_h.apply(_g, [_t.sent()]);
|
|
145
|
+
if (!(((_a = indexExpression.index) === null || _a === void 0 ? void 0 : _a.type) === 'SliceExpression')) return [3 /*break*/, 8];
|
|
146
|
+
sliceExpression = indexExpression.index;
|
|
147
|
+
_k = (_j = expression).append;
|
|
148
|
+
_l = SliceSegment.bind;
|
|
149
|
+
return [4 /*yield*/, visit(sliceExpression.left)];
|
|
150
|
+
case 6:
|
|
151
|
+
_m = [void 0, _t.sent()];
|
|
152
|
+
return [4 /*yield*/, visit(sliceExpression.right)];
|
|
153
|
+
case 7:
|
|
154
|
+
_k.apply(_j, [new (_l.apply(SliceSegment, _m.concat([_t.sent()])))()]);
|
|
155
|
+
return [3 /*break*/, 10];
|
|
156
|
+
case 8:
|
|
157
|
+
_p = (_o = expression).append;
|
|
158
|
+
_q = IndexSegment.bind;
|
|
159
|
+
return [4 /*yield*/, visit(indexExpression.index)];
|
|
160
|
+
case 9:
|
|
161
|
+
_p.apply(_o, [new (_q.apply(IndexSegment, [void 0, _t.sent()]))()]);
|
|
162
|
+
_t.label = 10;
|
|
163
|
+
case 10: return [3 /*break*/, 14];
|
|
164
|
+
case 11:
|
|
165
|
+
identifier = node;
|
|
166
|
+
expression.append(new PathSegment(identifier.name));
|
|
167
|
+
return [3 /*break*/, 14];
|
|
168
|
+
case 12:
|
|
169
|
+
_s = (_r = expression).append;
|
|
170
|
+
return [4 /*yield*/, visit(node)];
|
|
171
|
+
case 13:
|
|
172
|
+
_s.apply(_r, [_t.sent()]);
|
|
173
|
+
_t.label = 14;
|
|
174
|
+
case 14: return [2 /*return*/, expression];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
_a = me;
|
|
180
|
+
return [4 /*yield*/, buildExpression(me.ast)];
|
|
181
|
+
case 1:
|
|
182
|
+
_a.expr = _b.sent();
|
|
183
|
+
return [2 /*return*/, me];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
135
188
|
PathExpression.prototype.get = function (operationContext, parentExpr) {
|
|
136
189
|
return __awaiter(this, void 0, void 0, function () {
|
|
137
190
|
var me, evaluate, resultExpr, context, value_1, _a, value, callable, _b;
|
package/dist/interpreter.d.ts
CHANGED
package/dist/interpreter.js
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
40
|
};
|
|
@@ -20,7 +56,7 @@ var Interpreter = /** @class */ (function () {
|
|
|
20
56
|
me.context = null;
|
|
21
57
|
if (options.target) {
|
|
22
58
|
me.target = options.target;
|
|
23
|
-
me.code =
|
|
59
|
+
me.code = null;
|
|
24
60
|
}
|
|
25
61
|
else {
|
|
26
62
|
me.target = 'unknown';
|
|
@@ -28,28 +64,49 @@ var Interpreter = /** @class */ (function () {
|
|
|
28
64
|
}
|
|
29
65
|
}
|
|
30
66
|
Interpreter.prototype.digest = function () {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var me, code, _a, parser, chunk, cps, mainContext, topOperation, _b, _c;
|
|
69
|
+
var _d;
|
|
70
|
+
return __generator(this, function (_e) {
|
|
71
|
+
switch (_e.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
me = this;
|
|
74
|
+
_a = me.code;
|
|
75
|
+
if (_a) return [3 /*break*/, 2];
|
|
76
|
+
return [4 /*yield*/, me.resourceHandler.get(me.target)];
|
|
77
|
+
case 1:
|
|
78
|
+
_a = (_e.sent());
|
|
79
|
+
_e.label = 2;
|
|
80
|
+
case 2:
|
|
81
|
+
code = _a;
|
|
82
|
+
parser = new greybel_core_1.Parser(code);
|
|
83
|
+
chunk = parser.parseChunk();
|
|
84
|
+
cps = new cps_1.default({
|
|
85
|
+
target: me.target,
|
|
86
|
+
resourceHandler: me.resourceHandler
|
|
87
|
+
});
|
|
88
|
+
mainContext = new context_1.OperationContext({
|
|
89
|
+
isProtected: true,
|
|
90
|
+
debugger: me.debugger,
|
|
91
|
+
cps: cps
|
|
92
|
+
});
|
|
93
|
+
_b = top_1.default.bind;
|
|
94
|
+
_c = [void 0, null];
|
|
95
|
+
_d = {};
|
|
96
|
+
return [4 /*yield*/, cps.visit(chunk)];
|
|
97
|
+
case 3:
|
|
98
|
+
topOperation = new (_b.apply(top_1.default, _c.concat([(_d.body = _e.sent(),
|
|
99
|
+
_d)])))();
|
|
100
|
+
mainContext.extend(me.api);
|
|
101
|
+
mainContext.scope.refs.set('params', (0, typer_1.cast)(me.params));
|
|
102
|
+
me.context = mainContext;
|
|
103
|
+
return [2 /*return*/, topOperation.run(mainContext)
|
|
104
|
+
.catch(function (err) {
|
|
105
|
+
console.error(err);
|
|
106
|
+
throw err;
|
|
107
|
+
})];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
53
110
|
});
|
|
54
111
|
};
|
|
55
112
|
Interpreter.prototype.exit = function () {
|
package/dist/resource.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export interface ResourceHandler {
|
|
2
|
-
getTargetRelativeTo(source: string, target: string): string
|
|
3
|
-
has(target: string): boolean
|
|
4
|
-
get(target: string): string
|
|
5
|
-
resolve(target: string): string
|
|
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
6
|
}
|
|
7
7
|
export declare class ResourceProvider {
|
|
8
8
|
getHandler(): ResourceHandler;
|
package/dist/resource.js
CHANGED
|
@@ -11,16 +11,16 @@ var ResourceProvider = /** @class */ (function () {
|
|
|
11
11
|
getTargetRelativeTo: function (source, target) {
|
|
12
12
|
var base = path.resolve(source, '..');
|
|
13
13
|
var result = path.resolve(base, target);
|
|
14
|
-
return fs.existsSync(result) ? result : result + '.src';
|
|
14
|
+
return Promise.resolve(fs.existsSync(result) ? result : result + '.src');
|
|
15
15
|
},
|
|
16
16
|
has: function (target) {
|
|
17
|
-
return fs.existsSync(target);
|
|
17
|
+
return Promise.resolve(fs.existsSync(target));
|
|
18
18
|
},
|
|
19
19
|
get: function (target) {
|
|
20
|
-
return fs.readFileSync(target, 'utf8');
|
|
20
|
+
return Promise.resolve(fs.readFileSync(target, 'utf8'));
|
|
21
21
|
},
|
|
22
22
|
resolve: function (target) {
|
|
23
|
-
return path.resolve(target);
|
|
23
|
+
return Promise.resolve(path.resolve(target));
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
};
|