greybel-interpreter 0.1.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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/context.d.ts +68 -0
  4. package/dist/context.js +399 -0
  5. package/dist/cps.d.ts +15 -0
  6. package/dist/cps.js +438 -0
  7. package/dist/custom-types/boolean.d.ts +10 -0
  8. package/dist/custom-types/boolean.js +41 -0
  9. package/dist/custom-types/list.d.ts +25 -0
  10. package/dist/custom-types/list.js +281 -0
  11. package/dist/custom-types/map.d.ts +28 -0
  12. package/dist/custom-types/map.js +289 -0
  13. package/dist/custom-types/nil.d.ts +8 -0
  14. package/dist/custom-types/nil.js +38 -0
  15. package/dist/custom-types/number.d.ts +10 -0
  16. package/dist/custom-types/number.js +41 -0
  17. package/dist/custom-types/string.d.ts +21 -0
  18. package/dist/custom-types/string.js +132 -0
  19. package/dist/expressions/assign.d.ts +12 -0
  20. package/dist/expressions/assign.js +156 -0
  21. package/dist/expressions/binary-negated-expression.d.ts +18 -0
  22. package/dist/expressions/binary-negated-expression.js +115 -0
  23. package/dist/expressions/call.d.ts +13 -0
  24. package/dist/expressions/call.js +177 -0
  25. package/dist/expressions/list.d.ts +13 -0
  26. package/dist/expressions/list.js +119 -0
  27. package/dist/expressions/logical-and-binary.d.ts +22 -0
  28. package/dist/expressions/logical-and-binary.js +188 -0
  29. package/dist/expressions/map.d.ts +18 -0
  30. package/dist/expressions/map.js +171 -0
  31. package/dist/expressions/path.d.ts +30 -0
  32. package/dist/expressions/path.js +310 -0
  33. package/dist/index.d.ts +35 -0
  34. package/dist/index.js +82 -0
  35. package/dist/interpreter.d.ts +20 -0
  36. package/dist/interpreter.js +55 -0
  37. package/dist/operations/argument.d.ts +8 -0
  38. package/dist/operations/argument.js +129 -0
  39. package/dist/operations/body.d.ts +8 -0
  40. package/dist/operations/body.js +144 -0
  41. package/dist/operations/break.d.ts +7 -0
  42. package/dist/operations/break.js +34 -0
  43. package/dist/operations/continue.d.ts +7 -0
  44. package/dist/operations/continue.js +34 -0
  45. package/dist/operations/debugger.d.ts +7 -0
  46. package/dist/operations/debugger.js +32 -0
  47. package/dist/operations/else-if.d.ts +12 -0
  48. package/dist/operations/else-if.js +31 -0
  49. package/dist/operations/else.d.ts +10 -0
  50. package/dist/operations/else.js +30 -0
  51. package/dist/operations/for.d.ts +16 -0
  52. package/dist/operations/for.js +139 -0
  53. package/dist/operations/function.d.ts +21 -0
  54. package/dist/operations/function.js +125 -0
  55. package/dist/operations/if-statement.d.ts +8 -0
  56. package/dist/operations/if-statement.js +138 -0
  57. package/dist/operations/if.d.ts +12 -0
  58. package/dist/operations/if.js +31 -0
  59. package/dist/operations/new.d.ts +11 -0
  60. package/dist/operations/new.js +96 -0
  61. package/dist/operations/not.d.ts +11 -0
  62. package/dist/operations/not.js +95 -0
  63. package/dist/operations/reference.d.ts +11 -0
  64. package/dist/operations/reference.js +102 -0
  65. package/dist/operations/return.d.ts +11 -0
  66. package/dist/operations/return.js +102 -0
  67. package/dist/operations/top.d.ts +12 -0
  68. package/dist/operations/top.js +84 -0
  69. package/dist/operations/while.d.ts +14 -0
  70. package/dist/operations/while.js +123 -0
  71. package/dist/resource.d.ts +9 -0
  72. package/dist/resource.js +29 -0
  73. package/dist/typer.d.ts +6 -0
  74. package/dist/typer.js +99 -0
  75. package/dist/types/custom-type.d.ts +19 -0
  76. package/dist/types/custom-type.js +58 -0
  77. package/dist/types/expression.d.ts +6 -0
  78. package/dist/types/expression.js +9 -0
  79. package/dist/types/operation.d.ts +9 -0
  80. package/dist/types/operation.js +38 -0
  81. package/package.json +45 -0
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ var custom_type_1 = require("../types/custom-type");
19
+ var CustomNumber = /** @class */ (function (_super) {
20
+ __extends(CustomNumber, _super);
21
+ function CustomNumber(value) {
22
+ var _this = _super.call(this) || this;
23
+ _this.value = value;
24
+ return _this;
25
+ }
26
+ CustomNumber.prototype.getType = function () {
27
+ return 'number';
28
+ };
29
+ CustomNumber.prototype.valueOf = function () {
30
+ return this.value;
31
+ };
32
+ CustomNumber.prototype.toString = function () {
33
+ return this.value.toString();
34
+ };
35
+ CustomNumber.prototype.fork = function () {
36
+ return new CustomNumber(this.value);
37
+ };
38
+ CustomNumber.intrinsics = new Map();
39
+ return CustomNumber;
40
+ }(custom_type_1.CustomLiteralType));
41
+ exports.default = CustomNumber;
@@ -0,0 +1,21 @@
1
+ import { CustomLiteralType } from '../types/custom-type';
2
+ export declare class CustomStringIterator implements Iterator<string> {
3
+ value: string;
4
+ index: number;
5
+ constructor(value: string);
6
+ next(): IteratorResult<string>;
7
+ }
8
+ export default class CustomString extends CustomLiteralType {
9
+ static intrinsics: Map<string, Function>;
10
+ value: string;
11
+ static isNumber(value: string): boolean;
12
+ constructor(value: string);
13
+ slice(a: CustomLiteralType, b: CustomLiteralType): CustomString;
14
+ [Symbol.iterator](): CustomStringIterator;
15
+ toIndex(value: string): number;
16
+ callMethod(method: string[], ...args: any[]): any;
17
+ getType(): string;
18
+ valueOf(): string | null;
19
+ toString(): string;
20
+ fork(): CustomString;
21
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __read = (this && this.__read) || function (o, n) {
18
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
19
+ if (!m) return o;
20
+ var i = m.call(o), r, ar = [], e;
21
+ try {
22
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
+ }
24
+ catch (error) { e = { error: error }; }
25
+ finally {
26
+ try {
27
+ if (r && !r.done && (m = i["return"])) m.call(i);
28
+ }
29
+ finally { if (e) throw e.error; }
30
+ }
31
+ return ar;
32
+ };
33
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
35
+ if (ar || !(i in from)) {
36
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
37
+ ar[i] = from[i];
38
+ }
39
+ }
40
+ return to.concat(ar || Array.prototype.slice.call(from));
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.CustomStringIterator = void 0;
44
+ var custom_type_1 = require("../types/custom-type");
45
+ var CustomStringIterator = /** @class */ (function () {
46
+ function CustomStringIterator(value) {
47
+ var me = this;
48
+ me.value = value;
49
+ me.index = 0;
50
+ }
51
+ CustomStringIterator.prototype.next = function () {
52
+ var me = this;
53
+ if (me.index === me.value.length) {
54
+ return {
55
+ value: null,
56
+ done: true
57
+ };
58
+ }
59
+ return {
60
+ value: me.value[me.index++],
61
+ done: false
62
+ };
63
+ };
64
+ return CustomStringIterator;
65
+ }());
66
+ exports.CustomStringIterator = CustomStringIterator;
67
+ var CustomString = /** @class */ (function (_super) {
68
+ __extends(CustomString, _super);
69
+ function CustomString(value) {
70
+ var _this = _super.call(this) || this;
71
+ _this.value = value;
72
+ return _this;
73
+ }
74
+ CustomString.isNumber = function (value) {
75
+ return !Number.isNaN(Number(value));
76
+ };
77
+ CustomString.prototype.slice = function (a, b) {
78
+ return new CustomString(this.value.slice(a.valueOf(), b.valueOf()));
79
+ };
80
+ CustomString.prototype[Symbol.iterator] = function () {
81
+ return new CustomStringIterator(this.value);
82
+ };
83
+ CustomString.prototype.toIndex = function (value) {
84
+ var me = this;
85
+ var casted = Number(value);
86
+ return casted < 0 ? me.value.length + casted : casted;
87
+ };
88
+ CustomString.prototype.callMethod = function (method) {
89
+ var _a;
90
+ var args = [];
91
+ for (var _i = 1; _i < arguments.length; _i++) {
92
+ args[_i - 1] = arguments[_i];
93
+ }
94
+ if (method.length === 0) {
95
+ throw new Error('Unexpected method length');
96
+ }
97
+ var me = this;
98
+ var member = method[0].valueOf();
99
+ if (CustomString.isNumber(member)) {
100
+ var index = me.toIndex(member);
101
+ if (!me.value[index]) {
102
+ console.error(method, member, args);
103
+ throw new Error("Unexpected index ".concat(index));
104
+ }
105
+ var value = new CustomString(me.value[index]);
106
+ if (method.length > 1) {
107
+ return value.callMethod.apply(value, __spreadArray([method.slice(1)], __read(args), false));
108
+ }
109
+ return value;
110
+ }
111
+ if (!CustomString.intrinsics.has(member)) {
112
+ throw new Error("Cannot access ".concat(member, " in string"));
113
+ }
114
+ return (_a = CustomString.intrinsics.get(member)).call.apply(_a, __spreadArray([me], __read(args), false));
115
+ };
116
+ CustomString.prototype.getType = function () {
117
+ return 'string';
118
+ };
119
+ CustomString.prototype.valueOf = function () {
120
+ var me = this;
121
+ return me.value.length === 0 ? null : me.value;
122
+ };
123
+ CustomString.prototype.toString = function () {
124
+ return "\"".concat(this.value.toString(), "\"");
125
+ };
126
+ CustomString.prototype.fork = function () {
127
+ return new CustomString(this.value);
128
+ };
129
+ CustomString.intrinsics = new Map();
130
+ return CustomString;
131
+ }(custom_type_1.CustomLiteralType));
132
+ exports.default = CustomString;
@@ -0,0 +1,12 @@
1
+ import { ASTAssignmentStatement } from 'greybel-core';
2
+ import { Expression } from '../types/expression';
3
+ import { OperationContext } from '../context';
4
+ export declare class ExpressionSegment {
5
+ left: any;
6
+ right: any;
7
+ constructor(left: any, right: any);
8
+ }
9
+ export default class AssignExpression extends Expression {
10
+ constructor(ast: ASTAssignmentStatement, visit: Function);
11
+ get(operationContext: OperationContext, parentExpr: any): Promise<any>;
12
+ }
@@ -0,0 +1,156 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.ExpressionSegment = void 0;
55
+ var operation_1 = require("../types/operation");
56
+ var expression_1 = require("../types/expression");
57
+ var custom_type_1 = require("../types/custom-type");
58
+ var typer_1 = require("../typer");
59
+ var ExpressionSegment = /** @class */ (function () {
60
+ function ExpressionSegment(left, right) {
61
+ var me = this;
62
+ me.left = left;
63
+ me.right = right;
64
+ }
65
+ return ExpressionSegment;
66
+ }());
67
+ exports.ExpressionSegment = ExpressionSegment;
68
+ var AssignExpression = /** @class */ (function (_super) {
69
+ __extends(AssignExpression, _super);
70
+ function AssignExpression(ast, visit) {
71
+ var _this = _super.call(this) || this;
72
+ var me = _this;
73
+ var buildExpression = function (node) {
74
+ return new ExpressionSegment(visit(node.variable), visit(node.init));
75
+ };
76
+ me.ast = ast;
77
+ me.expr = buildExpression(ast);
78
+ return _this;
79
+ }
80
+ AssignExpression.prototype.get = function (operationContext, parentExpr) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ var me, evaluate;
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ me = this;
87
+ evaluate = function (node) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var left, right, pathLength, origin, handlePath, context;
90
+ return __generator(this, function (_a) {
91
+ switch (_a.label) {
92
+ case 0:
93
+ if (!(node.left instanceof expression_1.Expression)) {
94
+ operationContext.debugger.raise('Unexpected left assignment', me, node.left);
95
+ }
96
+ return [4 /*yield*/, node.left.get(operationContext, me.expr)];
97
+ case 1:
98
+ left = _a.sent();
99
+ right = node.right;
100
+ if (!(0, typer_1.isCustomValue)(right)) return [3 /*break*/, 2];
101
+ right = right;
102
+ return [3 /*break*/, 9];
103
+ case 2:
104
+ if (!(node.right instanceof expression_1.Expression)) return [3 /*break*/, 4];
105
+ return [4 /*yield*/, right.get(operationContext)];
106
+ case 3:
107
+ right = _a.sent();
108
+ return [3 /*break*/, 9];
109
+ case 4:
110
+ if (!(node.right instanceof operation_1.Operation)) return [3 /*break*/, 8];
111
+ return [4 /*yield*/, right.get(operationContext)];
112
+ case 5:
113
+ right = _a.sent();
114
+ pathLength = left.path.length;
115
+ if (!(right instanceof operation_1.FunctionOperationBase && pathLength > 1)) return [3 /*break*/, 7];
116
+ return [4 /*yield*/, operationContext.get(left.path.slice(0, pathLength - 1))];
117
+ case 6:
118
+ origin = _a.sent();
119
+ if ((0, typer_1.isCustomMap)(origin)) {
120
+ right = right.fork(origin);
121
+ }
122
+ _a.label = 7;
123
+ case 7: return [3 /*break*/, 9];
124
+ case 8:
125
+ operationContext.debugger.raise('Unexpected right assignment', me, right);
126
+ _a.label = 9;
127
+ case 9:
128
+ if (!left.handle) return [3 /*break*/, 12];
129
+ if (!(left.handle instanceof custom_type_1.CustomObjectType)) return [3 /*break*/, 11];
130
+ handlePath = left.path;
131
+ context = left.handle;
132
+ return [4 /*yield*/, context.set(handlePath, right)];
133
+ case 10:
134
+ _a.sent();
135
+ return [2 /*return*/, true];
136
+ case 11:
137
+ operationContext.debugger.raise('Unexpected left assignment', me, left);
138
+ _a.label = 12;
139
+ case 12: return [4 /*yield*/, operationContext.set(left.path, right)];
140
+ case 13:
141
+ _a.sent();
142
+ return [2 /*return*/, true];
143
+ }
144
+ });
145
+ });
146
+ };
147
+ operationContext.debugger.debug('AssignExpression', 'get', 'expr', me.expr);
148
+ return [4 /*yield*/, evaluate(me.expr)];
149
+ case 1: return [2 /*return*/, _a.sent()];
150
+ }
151
+ });
152
+ });
153
+ };
154
+ return AssignExpression;
155
+ }(expression_1.Expression));
156
+ exports.default = AssignExpression;
@@ -0,0 +1,18 @@
1
+ import { ASTUnaryExpression } from 'greybel-core';
2
+ import { Expression } from '../types/expression';
3
+ import { OperationContext } from '../context';
4
+ import { CustomType } from '../types/custom-type';
5
+ export declare const toPrimitive: (v: CustomType | any) => any;
6
+ export declare type OperationMap = {
7
+ [key: string]: (a: CustomType) => any;
8
+ };
9
+ export declare class ExpressionSegment {
10
+ operator: string;
11
+ arg: any;
12
+ constructor(operator: string, arg: any);
13
+ }
14
+ export default class BinaryNegatedExpression extends Expression {
15
+ expr: ExpressionSegment;
16
+ constructor(ast: ASTUnaryExpression, visit: Function);
17
+ get(operationContext: OperationContext): any;
18
+ }
@@ -0,0 +1,115 @@
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 _a;
54
+ Object.defineProperty(exports, "__esModule", { value: true });
55
+ exports.ExpressionSegment = exports.toPrimitive = void 0;
56
+ var greybel_core_1 = require("greybel-core");
57
+ var expression_1 = require("../types/expression");
58
+ var typer_1 = require("../typer");
59
+ var toPrimitive = function (v) {
60
+ return (0, typer_1.isCustomValue)(v) ? v.valueOf() : v;
61
+ };
62
+ exports.toPrimitive = toPrimitive;
63
+ var OPERATIONS = (_a = {},
64
+ _a[greybel_core_1.Operator.Plus] = function (a) { return (0, exports.toPrimitive)(a); },
65
+ _a[greybel_core_1.Operator.Minus] = function (a) { return -(0, exports.toPrimitive)(a); },
66
+ _a);
67
+ var ExpressionSegment = /** @class */ (function () {
68
+ function ExpressionSegment(operator, arg) {
69
+ var me = this;
70
+ me.operator = operator;
71
+ me.arg = arg;
72
+ }
73
+ return ExpressionSegment;
74
+ }());
75
+ exports.ExpressionSegment = ExpressionSegment;
76
+ var BinaryNegatedExpression = /** @class */ (function (_super) {
77
+ __extends(BinaryNegatedExpression, _super);
78
+ function BinaryNegatedExpression(ast, visit) {
79
+ var _this = _super.call(this) || this;
80
+ var me = _this;
81
+ var buildExpression = function (node) {
82
+ return new ExpressionSegment(node.operator, visit(node.argument));
83
+ };
84
+ me.ast = ast;
85
+ me.expr = buildExpression(ast);
86
+ return _this;
87
+ }
88
+ BinaryNegatedExpression.prototype.get = function (operationContext) {
89
+ var me = this;
90
+ var evaluate = function (node) {
91
+ return __awaiter(this, void 0, void 0, function () {
92
+ var arg, _a;
93
+ return __generator(this, function (_b) {
94
+ switch (_b.label) {
95
+ case 0:
96
+ if (!(0, typer_1.isCustomValue)(node.arg)) return [3 /*break*/, 1];
97
+ _a = node.arg;
98
+ return [3 /*break*/, 3];
99
+ case 1: return [4 /*yield*/, node.arg.get(operationContext)];
100
+ case 2:
101
+ _a = _b.sent();
102
+ _b.label = 3;
103
+ case 3:
104
+ arg = _a;
105
+ return [2 /*return*/, (0, typer_1.cast)(OPERATIONS[node.operator](arg))];
106
+ }
107
+ });
108
+ });
109
+ };
110
+ operationContext.debugger.debug('BinaryNegatedExpression', 'get', 'expr', me.expr);
111
+ return evaluate(me.expr);
112
+ };
113
+ return BinaryNegatedExpression;
114
+ }(expression_1.Expression));
115
+ exports.default = BinaryNegatedExpression;
@@ -0,0 +1,13 @@
1
+ import { Expression } from '../types/expression';
2
+ import { OperationContext } from '../context';
3
+ export declare class ExpressionSegment {
4
+ path: any;
5
+ args: any[];
6
+ constructor(path: any, args: any[]);
7
+ resolveArgs(operationContext: OperationContext): Promise<any>;
8
+ }
9
+ export default class CallExpression extends Expression {
10
+ expr: ExpressionSegment;
11
+ constructor(ast: any, visit: Function);
12
+ get(operationContext: OperationContext, parentExpr: any): Promise<any>;
13
+ }