greybel-interpreter 1.1.2 → 1.1.5
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.d.ts +4 -4
- package/dist/context.js +14 -10
- package/dist/interpreter.d.ts +2 -0
- package/dist/interpreter.js +28 -5
- package/dist/operations/for.d.ts +2 -3
- package/dist/operations/for.js +12 -12
- package/dist/operations/function.d.ts +2 -0
- package/dist/operations/function.js +5 -3
- package/dist/operations/import.d.ts +3 -0
- package/dist/operations/import.js +8 -4
- package/dist/operations/map.d.ts +1 -1
- package/dist/operations/map.js +17 -13
- package/dist/operations/resolve.d.ts +2 -2
- package/dist/operations/resolve.js +2 -2
- package/dist/types/function.d.ts +1 -1
- package/dist/types/function.js +3 -3
- package/dist/types/generics.d.ts +4 -3
- package/dist/types/interface.d.ts +4 -3
- package/dist/types/interface.js +6 -5
- package/dist/types/list.d.ts +3 -3
- package/dist/types/list.js +27 -45
- package/dist/types/map.d.ts +13 -8
- package/dist/types/map.js +87 -24
- package/dist/types/nil.d.ts +1 -0
- package/dist/types/nil.js +3 -1
- package/dist/types/string.d.ts +3 -3
- package/dist/types/string.js +15 -19
- package/package.json +5 -5
package/dist/context.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare enum ContextState {
|
|
|
22
22
|
export declare class Scope extends CustomMap {
|
|
23
23
|
private readonly context;
|
|
24
24
|
constructor(context: OperationContext);
|
|
25
|
-
get(path: Path<
|
|
25
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
26
26
|
}
|
|
27
27
|
export declare class Debugger {
|
|
28
28
|
private breakpoint;
|
|
@@ -102,8 +102,8 @@ export default class OperationContext {
|
|
|
102
102
|
lookupApi(): OperationContext;
|
|
103
103
|
lookupGlobals(): OperationContext;
|
|
104
104
|
lookupLocals(): OperationContext;
|
|
105
|
-
extend(map: Map<
|
|
106
|
-
set(path: Path<
|
|
107
|
-
get(path: Path<
|
|
105
|
+
extend(map: Map<CustomValue, CustomValue>): OperationContext;
|
|
106
|
+
set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
|
|
107
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
108
108
|
fork(options: ContextForkOptions): OperationContext;
|
|
109
109
|
}
|
package/dist/context.js
CHANGED
|
@@ -46,6 +46,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
46
46
|
exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
47
47
|
var handler_container_1 = __importDefault(require("./handler-container"));
|
|
48
48
|
var default_1 = __importDefault(require("./types/default"));
|
|
49
|
+
var generics_1 = require("./types/generics");
|
|
49
50
|
var map_1 = __importDefault(require("./types/map"));
|
|
50
51
|
var path_1 = __importDefault(require("./utils/path"));
|
|
51
52
|
var ContextType;
|
|
@@ -71,7 +72,7 @@ var Scope = /** @class */ (function (_super) {
|
|
|
71
72
|
return _this;
|
|
72
73
|
}
|
|
73
74
|
Scope.prototype.get = function (path) {
|
|
74
|
-
if (
|
|
75
|
+
if (path instanceof generics_1.CustomValue) {
|
|
75
76
|
return this.get(new path_1.default([path]));
|
|
76
77
|
}
|
|
77
78
|
if (path.count() === 0) {
|
|
@@ -79,7 +80,7 @@ var Scope = /** @class */ (function (_super) {
|
|
|
79
80
|
}
|
|
80
81
|
var traversalPath = path.clone();
|
|
81
82
|
var current = traversalPath.next();
|
|
82
|
-
if (current === 'locals' || current === 'globals') {
|
|
83
|
+
if (current.value === 'locals' || current.value === 'globals') {
|
|
83
84
|
return this.context.get(traversalPath);
|
|
84
85
|
}
|
|
85
86
|
else if (this.has(path)) {
|
|
@@ -88,8 +89,8 @@ var Scope = /** @class */ (function (_super) {
|
|
|
88
89
|
else if (this.context.api.scope.has(path)) {
|
|
89
90
|
return this.context.api.scope.get(path);
|
|
90
91
|
}
|
|
91
|
-
else if (path.count() === 1 && map_1.default.getIntrinsics().has(current)) {
|
|
92
|
-
return map_1.default.getIntrinsics().get(current);
|
|
92
|
+
else if (path.count() === 1 && map_1.default.getIntrinsics().has(current.toString())) {
|
|
93
|
+
return map_1.default.getIntrinsics().get(current.toString());
|
|
93
94
|
}
|
|
94
95
|
else if (this.context.previous !== null) {
|
|
95
96
|
return this.context.previous.get(path);
|
|
@@ -307,16 +308,16 @@ var OperationContext = /** @class */ (function () {
|
|
|
307
308
|
};
|
|
308
309
|
OperationContext.prototype.set = function (path, value) {
|
|
309
310
|
var _a;
|
|
310
|
-
if (
|
|
311
|
+
if (path instanceof generics_1.CustomValue) {
|
|
311
312
|
this.set(new path_1.default([path]), value);
|
|
312
313
|
return;
|
|
313
314
|
}
|
|
314
315
|
var traversalPath = path.clone();
|
|
315
316
|
var current = traversalPath.next();
|
|
316
|
-
if (current === 'locals') {
|
|
317
|
+
if (current.value === 'locals') {
|
|
317
318
|
this.locals.set(traversalPath, value);
|
|
318
319
|
}
|
|
319
|
-
else if (current === 'globals') {
|
|
320
|
+
else if (current.value === 'globals') {
|
|
320
321
|
this.globals.set(traversalPath, value);
|
|
321
322
|
}
|
|
322
323
|
else if (this.state === ContextState.Temporary) {
|
|
@@ -328,15 +329,18 @@ var OperationContext = /** @class */ (function () {
|
|
|
328
329
|
};
|
|
329
330
|
OperationContext.prototype.get = function (path) {
|
|
330
331
|
var _a;
|
|
331
|
-
if (
|
|
332
|
+
if (path instanceof generics_1.CustomValue) {
|
|
332
333
|
return this.get(new path_1.default([path]));
|
|
333
334
|
}
|
|
335
|
+
if (path.count() === 0) {
|
|
336
|
+
return this.scope;
|
|
337
|
+
}
|
|
334
338
|
var traversalPath = path.clone();
|
|
335
339
|
var current = traversalPath.next();
|
|
336
|
-
if (current === 'locals') {
|
|
340
|
+
if (current.value === 'locals') {
|
|
337
341
|
return this.locals.get(traversalPath);
|
|
338
342
|
}
|
|
339
|
-
else if (current === 'globals') {
|
|
343
|
+
else if (current.value === 'globals') {
|
|
340
344
|
return this.globals.get(traversalPath);
|
|
341
345
|
}
|
|
342
346
|
else if (this.state === ContextState.Temporary) {
|
package/dist/interpreter.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import CPS from './cps';
|
|
|
5
5
|
import HandlerContainer from './handler-container';
|
|
6
6
|
import Operation from './operations/operation';
|
|
7
7
|
import { CustomValue } from './types/generics';
|
|
8
|
+
import CustomString from './types/string';
|
|
9
|
+
export declare const PARAMS_PROPERTY: CustomString;
|
|
8
10
|
export interface InterpreterOptions {
|
|
9
11
|
target?: string;
|
|
10
12
|
api?: Map<string, CustomValue>;
|
package/dist/interpreter.js
CHANGED
|
@@ -73,10 +73,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
73
73
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
77
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
78
|
+
if (!m) return o;
|
|
79
|
+
var i = m.call(o), r, ar = [], e;
|
|
80
|
+
try {
|
|
81
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
82
|
+
}
|
|
83
|
+
catch (error) { e = { error: error }; }
|
|
84
|
+
finally {
|
|
85
|
+
try {
|
|
86
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
87
|
+
}
|
|
88
|
+
finally { if (e) throw e.error; }
|
|
89
|
+
}
|
|
90
|
+
return ar;
|
|
91
|
+
};
|
|
76
92
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
77
93
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
78
94
|
};
|
|
79
95
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
96
|
+
exports.PARAMS_PROPERTY = void 0;
|
|
80
97
|
var events_1 = __importDefault(require("events"));
|
|
81
98
|
var greybel_core_1 = require("greybel-core");
|
|
82
99
|
var context_1 = __importStar(require("./context"));
|
|
@@ -86,6 +103,7 @@ var noop_1 = __importDefault(require("./operations/noop"));
|
|
|
86
103
|
var default_1 = __importDefault(require("./types/default"));
|
|
87
104
|
var list_1 = __importDefault(require("./types/list"));
|
|
88
105
|
var string_1 = __importDefault(require("./types/string"));
|
|
106
|
+
exports.PARAMS_PROPERTY = new string_1.default('params');
|
|
89
107
|
var Interpreter = /** @class */ (function (_super) {
|
|
90
108
|
__extends(Interpreter, _super);
|
|
91
109
|
function Interpreter(options) {
|
|
@@ -222,16 +240,21 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
222
240
|
};
|
|
223
241
|
Interpreter.prototype.start = function (top) {
|
|
224
242
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
var newParams, process_1, err_2;
|
|
243
|
+
var api, newParams, process_1, err_2;
|
|
226
244
|
return __generator(this, function (_a) {
|
|
227
245
|
switch (_a.label) {
|
|
228
246
|
case 0:
|
|
229
247
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
230
248
|
throw new Error('Process already running.');
|
|
231
249
|
}
|
|
232
|
-
|
|
250
|
+
api = Array.from(this.api.entries()).reduce(function (result, _a) {
|
|
251
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
252
|
+
result.set(new string_1.default(key), value);
|
|
253
|
+
return result;
|
|
254
|
+
}, new Map());
|
|
255
|
+
this.apiContext.extend(api);
|
|
233
256
|
newParams = new list_1.default(this.params.map(function (item) { return new string_1.default(item); }));
|
|
234
|
-
this.globalContext.scope.set(
|
|
257
|
+
this.globalContext.scope.set(exports.PARAMS_PROPERTY, newParams);
|
|
235
258
|
_a.label = 1;
|
|
236
259
|
case 1:
|
|
237
260
|
_a.trys.push([1, 3, 4, 5]);
|
|
@@ -277,13 +300,13 @@ var Interpreter = /** @class */ (function (_super) {
|
|
|
277
300
|
};
|
|
278
301
|
Interpreter.prototype.setGlobalVariable = function (path, value) {
|
|
279
302
|
if (this.globalContext != null) {
|
|
280
|
-
this.globalContext.set(path, value);
|
|
303
|
+
this.globalContext.set(new string_1.default(path), value);
|
|
281
304
|
}
|
|
282
305
|
return this;
|
|
283
306
|
};
|
|
284
307
|
Interpreter.prototype.getGlobalVariable = function (path) {
|
|
285
308
|
if (this.globalContext != null) {
|
|
286
|
-
this.globalContext.get(path);
|
|
309
|
+
this.globalContext.get(new string_1.default(path));
|
|
287
310
|
}
|
|
288
311
|
return default_1.default.Void;
|
|
289
312
|
};
|
package/dist/operations/for.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { ASTForGenericStatement } from 'greyscript-core';
|
|
1
|
+
import { ASTForGenericStatement, ASTIdentifier } from 'greyscript-core';
|
|
2
2
|
import context from '../context';
|
|
3
3
|
import { CustomValue } from '../types/generics';
|
|
4
4
|
import Block from './block';
|
|
5
5
|
import Operation, { CPSVisit } from './operation';
|
|
6
|
-
import Resolve from './resolve';
|
|
7
6
|
export default class For extends Operation {
|
|
8
7
|
readonly item: ASTForGenericStatement;
|
|
9
8
|
block: Block;
|
|
10
|
-
variable:
|
|
9
|
+
variable: ASTIdentifier;
|
|
11
10
|
iterator: Operation;
|
|
12
11
|
constructor(item: ASTForGenericStatement, target?: string);
|
|
13
12
|
build(visit: CPSVisit): Promise<Operation>;
|
package/dist/operations/for.js
CHANGED
|
@@ -56,9 +56,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
57
|
var context_1 = require("../context");
|
|
58
58
|
var default_1 = __importDefault(require("../types/default"));
|
|
59
|
+
var number_1 = __importDefault(require("../types/number"));
|
|
60
|
+
var string_1 = __importDefault(require("../types/string"));
|
|
59
61
|
var block_1 = __importDefault(require("./block"));
|
|
60
62
|
var operation_1 = __importDefault(require("./operation"));
|
|
61
|
-
var resolve_1 = __importDefault(require("./resolve"));
|
|
62
63
|
var For = /** @class */ (function (_super) {
|
|
63
64
|
__extends(For, _super);
|
|
64
65
|
function For(item, target) {
|
|
@@ -75,13 +76,10 @@ var For = /** @class */ (function (_super) {
|
|
|
75
76
|
case 1:
|
|
76
77
|
stack = _b.sent();
|
|
77
78
|
this.block = new block_1.default(stack);
|
|
78
|
-
this.variable =
|
|
79
|
-
return [4 /*yield*/, this.variable.build(visit)];
|
|
80
|
-
case 2:
|
|
81
|
-
_b.sent();
|
|
79
|
+
this.variable = this.item.variable;
|
|
82
80
|
_a = this;
|
|
83
81
|
return [4 /*yield*/, visit(this.item.iterator)];
|
|
84
|
-
case
|
|
82
|
+
case 2:
|
|
85
83
|
_a.iterator = _b.sent();
|
|
86
84
|
return [2 /*return*/, this];
|
|
87
85
|
}
|
|
@@ -90,7 +88,7 @@ var For = /** @class */ (function (_super) {
|
|
|
90
88
|
};
|
|
91
89
|
For.prototype.handle = function (ctx) {
|
|
92
90
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
-
var forCtx,
|
|
91
|
+
var forCtx, identifier, iteratorValue, loopState, index;
|
|
94
92
|
var _this = this;
|
|
95
93
|
return __generator(this, function (_a) {
|
|
96
94
|
switch (_a.label) {
|
|
@@ -99,16 +97,17 @@ var For = /** @class */ (function (_super) {
|
|
|
99
97
|
type: context_1.ContextType.Loop,
|
|
100
98
|
state: context_1.ContextState.Temporary
|
|
101
99
|
});
|
|
102
|
-
|
|
103
|
-
case 1:
|
|
104
|
-
resolveResult = _a.sent();
|
|
100
|
+
identifier = this.variable.name;
|
|
105
101
|
return [4 /*yield*/, this.iterator.handle(ctx)];
|
|
106
|
-
case
|
|
102
|
+
case 1:
|
|
107
103
|
iteratorValue = (_a.sent());
|
|
108
104
|
loopState = new context_1.LoopState();
|
|
105
|
+
index = 0;
|
|
109
106
|
forCtx.loopState = loopState;
|
|
110
107
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
111
108
|
var iterator = iteratorValue[Symbol.iterator]();
|
|
109
|
+
var idxIdentifier = new string_1.default("__".concat(identifier, "_idx"));
|
|
110
|
+
var varIdentifier = new string_1.default(identifier);
|
|
112
111
|
var iteratorResult = iterator.next();
|
|
113
112
|
var iteration = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
114
113
|
var current, err_1;
|
|
@@ -122,7 +121,8 @@ var For = /** @class */ (function (_super) {
|
|
|
122
121
|
}
|
|
123
122
|
current = iteratorResult.value;
|
|
124
123
|
loopState.isContinue = false;
|
|
125
|
-
forCtx.set(
|
|
124
|
+
forCtx.set(idxIdentifier, new number_1.default(index++));
|
|
125
|
+
forCtx.set(varIdentifier, current);
|
|
126
126
|
return [4 /*yield*/, this.block.handle(forCtx)];
|
|
127
127
|
case 1:
|
|
128
128
|
_a.sent();
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ASTFunctionStatement } from 'greyscript-core';
|
|
2
2
|
import OperationContext from '../context';
|
|
3
3
|
import { CustomValue } from '../types/generics';
|
|
4
|
+
import CustomString from '../types/string';
|
|
4
5
|
import Operation, { CPSVisit } from './operation';
|
|
6
|
+
export declare const SELF_PROPERTY: CustomString;
|
|
5
7
|
export default class FunctionOperation extends Operation {
|
|
6
8
|
readonly item: ASTFunctionStatement;
|
|
7
9
|
block: Operation;
|
|
@@ -81,14 +81,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
81
81
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
82
82
|
};
|
|
83
83
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
84
|
+
exports.SELF_PROPERTY = void 0;
|
|
84
85
|
var greyscript_core_1 = require("greyscript-core");
|
|
85
86
|
var context_1 = require("../context");
|
|
86
87
|
var default_1 = __importDefault(require("../types/default"));
|
|
87
88
|
var function_1 = __importDefault(require("../types/function"));
|
|
88
|
-
var
|
|
89
|
+
var string_1 = __importDefault(require("../types/string"));
|
|
89
90
|
var block_1 = __importDefault(require("./block"));
|
|
90
91
|
var operation_1 = __importDefault(require("./operation"));
|
|
91
92
|
var reference_1 = __importDefault(require("./reference"));
|
|
93
|
+
exports.SELF_PROPERTY = new string_1.default('self');
|
|
92
94
|
var FunctionOperation = /** @class */ (function (_super) {
|
|
93
95
|
__extends(FunctionOperation, _super);
|
|
94
96
|
function FunctionOperation(item, target) {
|
|
@@ -157,11 +159,11 @@ var FunctionOperation = /** @class */ (function (_super) {
|
|
|
157
159
|
switch (_c.label) {
|
|
158
160
|
case 0:
|
|
159
161
|
fnCtx.functionState = new context_1.FunctionState();
|
|
160
|
-
fnCtx.set(
|
|
162
|
+
fnCtx.set(exports.SELF_PROPERTY, self);
|
|
161
163
|
try {
|
|
162
164
|
for (args_1 = __values(args), args_1_1 = args_1.next(); !args_1_1.done; args_1_1 = args_1.next()) {
|
|
163
165
|
_a = __read(args_1_1.value, 2), key = _a[0], value = _a[1];
|
|
164
|
-
fnCtx.set(new
|
|
166
|
+
fnCtx.set(new string_1.default(key), value);
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -2,7 +2,10 @@ import { ASTFeatureImportExpression } from 'greybel-core';
|
|
|
2
2
|
import { ASTBase } from 'greyscript-core';
|
|
3
3
|
import context from '../context';
|
|
4
4
|
import { CustomValue } from '../types/generics';
|
|
5
|
+
import CustomString from '../types/string';
|
|
5
6
|
import Operation, { CPSVisit } from './operation';
|
|
7
|
+
export declare const MODULE_PROPERTY: CustomString;
|
|
8
|
+
export declare const EXPORTS_PROPERTY: CustomString;
|
|
6
9
|
export default class Include extends Operation {
|
|
7
10
|
readonly item: ASTFeatureImportExpression;
|
|
8
11
|
code: string;
|
|
@@ -54,11 +54,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
54
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
55
|
};
|
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.EXPORTS_PROPERTY = exports.MODULE_PROPERTY = void 0;
|
|
57
58
|
var greybel_core_1 = require("greybel-core");
|
|
58
59
|
var context_1 = require("../context");
|
|
59
60
|
var default_1 = __importDefault(require("../types/default"));
|
|
60
61
|
var map_1 = __importDefault(require("../types/map"));
|
|
62
|
+
var string_1 = __importDefault(require("../types/string"));
|
|
61
63
|
var operation_1 = __importDefault(require("./operation"));
|
|
64
|
+
exports.MODULE_PROPERTY = new string_1.default('module');
|
|
65
|
+
exports.EXPORTS_PROPERTY = new string_1.default('exports');
|
|
62
66
|
var Include = /** @class */ (function (_super) {
|
|
63
67
|
__extends(Include, _super);
|
|
64
68
|
function Include(item, target, code) {
|
|
@@ -96,15 +100,15 @@ var Include = /** @class */ (function (_super) {
|
|
|
96
100
|
target: this.target
|
|
97
101
|
});
|
|
98
102
|
moduleMap = new map_1.default();
|
|
99
|
-
importCtx.set(
|
|
103
|
+
importCtx.set(exports.MODULE_PROPERTY, moduleMap);
|
|
100
104
|
return [4 /*yield*/, this.top.handle(importCtx)];
|
|
101
105
|
case 1:
|
|
102
106
|
_a.sent();
|
|
103
|
-
item = moduleMap.has(
|
|
104
|
-
? moduleMap.get(
|
|
107
|
+
item = moduleMap.has(exports.EXPORTS_PROPERTY)
|
|
108
|
+
? moduleMap.get(exports.EXPORTS_PROPERTY)
|
|
105
109
|
: default_1.default.Void;
|
|
106
110
|
identifier = this.item.name;
|
|
107
|
-
ctx.set(identifier.name, item);
|
|
111
|
+
ctx.set(new string_1.default(identifier.name), item);
|
|
108
112
|
return [2 /*return*/, default_1.default.Void];
|
|
109
113
|
}
|
|
110
114
|
});
|
package/dist/operations/map.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CustomValue } from '../types/generics';
|
|
|
4
4
|
import Operation, { CPSVisit } from './operation';
|
|
5
5
|
export default class MapOperation extends Operation {
|
|
6
6
|
readonly item: ASTMapConstructorExpression;
|
|
7
|
-
fields: Map<
|
|
7
|
+
fields: Map<Operation, Operation>;
|
|
8
8
|
constructor(item: ASTMapConstructorExpression, target?: string);
|
|
9
9
|
build(visit: CPSVisit): Promise<Operation>;
|
|
10
10
|
handle(ctx: context): Promise<CustomValue>;
|
package/dist/operations/map.js
CHANGED
|
@@ -105,9 +105,11 @@ var MapOperation = /** @class */ (function (_super) {
|
|
|
105
105
|
case 0:
|
|
106
106
|
mapKeyString = child;
|
|
107
107
|
_b = (_a = this.fields).set;
|
|
108
|
-
|
|
109
|
-
return [4 /*yield*/, visit(mapKeyString.value)];
|
|
108
|
+
return [4 /*yield*/, visit(mapKeyString.key)];
|
|
110
109
|
case 1:
|
|
110
|
+
_c = [_d.sent()];
|
|
111
|
+
return [4 /*yield*/, visit(mapKeyString.value)];
|
|
112
|
+
case 2:
|
|
111
113
|
_b.apply(_a, _c.concat([_d.sent()]));
|
|
112
114
|
return [2 /*return*/];
|
|
113
115
|
}
|
|
@@ -131,33 +133,35 @@ var MapOperation = /** @class */ (function (_super) {
|
|
|
131
133
|
newMap = new Map();
|
|
132
134
|
_h.label = 1;
|
|
133
135
|
case 1:
|
|
134
|
-
_h.trys.push([1,
|
|
136
|
+
_h.trys.push([1, 7, 8, 9]);
|
|
135
137
|
_a = __values(this.fields), _b = _a.next();
|
|
136
138
|
_h.label = 2;
|
|
137
139
|
case 2:
|
|
138
|
-
if (!!_b.done) return [3 /*break*/,
|
|
140
|
+
if (!!_b.done) return [3 /*break*/, 6];
|
|
139
141
|
_c = __read(_b.value, 2), key = _c[0], value = _c[1];
|
|
140
142
|
_e = (_d = newMap).set;
|
|
141
|
-
|
|
142
|
-
return [4 /*yield*/, value.handle(ctx)];
|
|
143
|
+
return [4 /*yield*/, key.handle(ctx)];
|
|
143
144
|
case 3:
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
_f = [_h.sent()];
|
|
146
|
+
return [4 /*yield*/, value.handle(ctx)];
|
|
146
147
|
case 4:
|
|
148
|
+
_e.apply(_d, _f.concat([_h.sent()]));
|
|
149
|
+
_h.label = 5;
|
|
150
|
+
case 5:
|
|
147
151
|
_b = _a.next();
|
|
148
152
|
return [3 /*break*/, 2];
|
|
149
|
-
case
|
|
150
|
-
case
|
|
153
|
+
case 6: return [3 /*break*/, 9];
|
|
154
|
+
case 7:
|
|
151
155
|
e_1_1 = _h.sent();
|
|
152
156
|
e_1 = { error: e_1_1 };
|
|
153
|
-
return [3 /*break*/,
|
|
154
|
-
case
|
|
157
|
+
return [3 /*break*/, 9];
|
|
158
|
+
case 8:
|
|
155
159
|
try {
|
|
156
160
|
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
|
|
157
161
|
}
|
|
158
162
|
finally { if (e_1) throw e_1.error; }
|
|
159
163
|
return [7 /*endfinally*/];
|
|
160
|
-
case
|
|
164
|
+
case 9: return [2 /*return*/, new map_1.default(newMap)];
|
|
161
165
|
}
|
|
162
166
|
});
|
|
163
167
|
});
|
|
@@ -22,9 +22,9 @@ export declare class OperationSegment {
|
|
|
22
22
|
}
|
|
23
23
|
export declare type Segment = SliceSegment | IdentifierSegment | IndexSegment | OperationSegment;
|
|
24
24
|
export declare class ResolveResult {
|
|
25
|
-
readonly path: Path<
|
|
25
|
+
readonly path: Path<CustomValue>;
|
|
26
26
|
readonly handle: CustomValue;
|
|
27
|
-
constructor(path: Path<
|
|
27
|
+
constructor(path: Path<CustomValue>, handle: CustomValue);
|
|
28
28
|
}
|
|
29
29
|
export default class Resolve extends Operation {
|
|
30
30
|
readonly item: ASTBase;
|
|
@@ -212,7 +212,7 @@ var Resolve = /** @class */ (function (_super) {
|
|
|
212
212
|
case 3:
|
|
213
213
|
if (!(current instanceof IdentifierSegment)) return [3 /*break*/, 6];
|
|
214
214
|
identifierSegment = current;
|
|
215
|
-
traversedPath.add(identifierSegment.value);
|
|
215
|
+
traversedPath.add(new string_1.default(identifierSegment.value));
|
|
216
216
|
if (index === lastIndex) {
|
|
217
217
|
return [3 /*break*/, 12];
|
|
218
218
|
}
|
|
@@ -243,7 +243,7 @@ var Resolve = /** @class */ (function (_super) {
|
|
|
243
243
|
return [4 /*yield*/, indexSegment.op.handle(ctx)];
|
|
244
244
|
case 7:
|
|
245
245
|
indexValue = _a.sent();
|
|
246
|
-
traversedPath.add(indexValue
|
|
246
|
+
traversedPath.add(indexValue);
|
|
247
247
|
if (index === lastIndex) {
|
|
248
248
|
return [3 /*break*/, 12];
|
|
249
249
|
}
|
package/dist/types/function.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Argument {
|
|
|
13
13
|
export default class CustomFunction extends CustomValue {
|
|
14
14
|
readonly scope?: OperationContext;
|
|
15
15
|
readonly name: string;
|
|
16
|
-
readonly
|
|
16
|
+
readonly value: Callback;
|
|
17
17
|
private injectSelf;
|
|
18
18
|
readonly argumentDefs: Array<Argument>;
|
|
19
19
|
static createExternalAnonymous(callback: Callback): CustomFunction;
|
package/dist/types/function.js
CHANGED
|
@@ -88,7 +88,7 @@ var CustomFunction = /** @class */ (function (_super) {
|
|
|
88
88
|
var _this = _super.call(this) || this;
|
|
89
89
|
_this.scope = scope;
|
|
90
90
|
_this.name = name;
|
|
91
|
-
_this.
|
|
91
|
+
_this.value = callback;
|
|
92
92
|
_this.injectSelf = injectSelf;
|
|
93
93
|
_this.argumentDefs = [];
|
|
94
94
|
return _this;
|
|
@@ -112,7 +112,7 @@ var CustomFunction = /** @class */ (function (_super) {
|
|
|
112
112
|
return this;
|
|
113
113
|
};
|
|
114
114
|
CustomFunction.prototype.fork = function () {
|
|
115
|
-
return new CustomFunction(this.scope, this.name, this.
|
|
115
|
+
return new CustomFunction(this.scope, this.name, this.value);
|
|
116
116
|
};
|
|
117
117
|
CustomFunction.prototype.getCustomType = function () {
|
|
118
118
|
return 'function';
|
|
@@ -164,7 +164,7 @@ var CustomFunction = /** @class */ (function (_super) {
|
|
|
164
164
|
case 4:
|
|
165
165
|
index++;
|
|
166
166
|
return [3 /*break*/, 1];
|
|
167
|
-
case 5: return [2 /*return*/, this.
|
|
167
|
+
case 5: return [2 /*return*/, this.value(fnCtx || callContext, self, argMap)];
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
});
|
package/dist/types/generics.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Path from '../utils/path';
|
|
2
2
|
export declare abstract class CustomValue {
|
|
3
|
+
abstract value: any;
|
|
3
4
|
abstract getCustomType(): string;
|
|
4
5
|
abstract toNumber(): number;
|
|
5
6
|
abstract toInt(): number;
|
|
@@ -8,9 +9,9 @@ export declare abstract class CustomValue {
|
|
|
8
9
|
abstract fork(): CustomValue;
|
|
9
10
|
}
|
|
10
11
|
export declare abstract class CustomValueWithIntrinsics extends CustomValue {
|
|
11
|
-
abstract has(path: Path<
|
|
12
|
-
abstract set(path: Path<
|
|
13
|
-
abstract get(path: Path<
|
|
12
|
+
abstract has(path: Path<CustomValue> | CustomValue): boolean;
|
|
13
|
+
abstract set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
|
|
14
|
+
abstract get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
14
15
|
abstract [Symbol.iterator](): Iterator<CustomValue>;
|
|
15
16
|
}
|
|
16
17
|
export declare abstract class CustomObject extends CustomValueWithIntrinsics {
|
|
@@ -7,6 +7,7 @@ export declare class CustomInterfaceIterator implements Iterator<CustomValue> {
|
|
|
7
7
|
export default class CustomInterface extends CustomObject {
|
|
8
8
|
private readonly interfaceFns;
|
|
9
9
|
private readonly type;
|
|
10
|
+
readonly value: Object;
|
|
10
11
|
constructor(type: string);
|
|
11
12
|
getCustomType(): string;
|
|
12
13
|
toString(): string;
|
|
@@ -15,8 +16,8 @@ export default class CustomInterface extends CustomObject {
|
|
|
15
16
|
toInt(): number;
|
|
16
17
|
toTruthy(): boolean;
|
|
17
18
|
[Symbol.iterator](): CustomInterfaceIterator;
|
|
18
|
-
has(path: Path<
|
|
19
|
-
set(_path: Path<
|
|
20
|
-
get(path: Path<
|
|
19
|
+
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
20
|
+
set(_path: Path<CustomValue> | CustomValue, _newValue: CustomValue): void;
|
|
21
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
21
22
|
addFunction(name: string, fn: CustomFunction): CustomInterface;
|
|
22
23
|
}
|
package/dist/types/interface.js
CHANGED
|
@@ -38,6 +38,7 @@ var CustomInterface = /** @class */ (function (_super) {
|
|
|
38
38
|
__extends(CustomInterface, _super);
|
|
39
39
|
function CustomInterface(type) {
|
|
40
40
|
var _this = _super.call(this) || this;
|
|
41
|
+
_this.value = {};
|
|
41
42
|
_this.type = type;
|
|
42
43
|
_this.interfaceFns = new Map();
|
|
43
44
|
return _this;
|
|
@@ -64,13 +65,13 @@ var CustomInterface = /** @class */ (function (_super) {
|
|
|
64
65
|
return new CustomInterfaceIterator();
|
|
65
66
|
};
|
|
66
67
|
CustomInterface.prototype.has = function (path) {
|
|
67
|
-
if (
|
|
68
|
+
if (path instanceof generics_1.CustomValue) {
|
|
68
69
|
return this.has(new path_1.default([path]));
|
|
69
70
|
}
|
|
70
71
|
var traversalPath = path.clone();
|
|
71
72
|
var current = traversalPath.next();
|
|
72
73
|
if (current !== null) {
|
|
73
|
-
return this.interfaceFns.has(current);
|
|
74
|
+
return this.interfaceFns.has(current.toString());
|
|
74
75
|
}
|
|
75
76
|
return false;
|
|
76
77
|
};
|
|
@@ -78,7 +79,7 @@ var CustomInterface = /** @class */ (function (_super) {
|
|
|
78
79
|
throw new Error('Cannot set property on an interface.');
|
|
79
80
|
};
|
|
80
81
|
CustomInterface.prototype.get = function (path) {
|
|
81
|
-
if (
|
|
82
|
+
if (path instanceof generics_1.CustomValue) {
|
|
82
83
|
return this.get(new path_1.default([path]));
|
|
83
84
|
}
|
|
84
85
|
if (path.count() === 0) {
|
|
@@ -87,8 +88,8 @@ var CustomInterface = /** @class */ (function (_super) {
|
|
|
87
88
|
var traversalPath = path.clone();
|
|
88
89
|
var current = traversalPath.next();
|
|
89
90
|
if (current !== null) {
|
|
90
|
-
if (this.interfaceFns.has(current)) {
|
|
91
|
-
return this.interfaceFns.get(current);
|
|
91
|
+
if (this.interfaceFns.has(current.toString())) {
|
|
92
|
+
return this.interfaceFns.get(current.toString());
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
throw new Error("Unknown path in interface ".concat(path.toString(), "."));
|
package/dist/types/list.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export default class CustomList extends CustomObject {
|
|
|
25
25
|
extend(list: CustomList | Array<CustomValue>): CustomList;
|
|
26
26
|
[Symbol.iterator](): CustomListIterator;
|
|
27
27
|
getItemIndex(index: number): number;
|
|
28
|
-
has(path: Path<
|
|
29
|
-
set(path: Path<
|
|
30
|
-
get(path: Path<
|
|
28
|
+
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
29
|
+
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
30
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
31
31
|
}
|
package/dist/types/list.js
CHANGED
|
@@ -47,6 +47,7 @@ exports.CustomListIterator = void 0;
|
|
|
47
47
|
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
48
48
|
var path_1 = __importDefault(require("../utils/path"));
|
|
49
49
|
var generics_1 = require("./generics");
|
|
50
|
+
var number_1 = __importDefault(require("./number"));
|
|
50
51
|
var CustomListIterator = /** @class */ (function () {
|
|
51
52
|
function CustomListIterator(value) {
|
|
52
53
|
var me = this;
|
|
@@ -128,19 +129,15 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
128
129
|
return CustomList.getItemIndex(this, index);
|
|
129
130
|
};
|
|
130
131
|
CustomList.prototype.has = function (path) {
|
|
131
|
-
if (
|
|
132
|
+
if (path instanceof generics_1.CustomValue) {
|
|
132
133
|
return this.has(new path_1.default([path]));
|
|
133
134
|
}
|
|
134
135
|
var traversalPath = path.clone();
|
|
135
136
|
var current = traversalPath.next();
|
|
136
|
-
if (current
|
|
137
|
-
var currentIndex =
|
|
138
|
-
var
|
|
139
|
-
if (
|
|
140
|
-
currentIndex = this.getItemIndex(currentIndex);
|
|
141
|
-
}
|
|
142
|
-
if (isCurrentNumber) {
|
|
143
|
-
var sub = this.value[currentIndex];
|
|
137
|
+
if (current instanceof number_1.default) {
|
|
138
|
+
var currentIndex = this.getItemIndex(current.toInt());
|
|
139
|
+
var sub = this.value[currentIndex];
|
|
140
|
+
if (sub) {
|
|
144
141
|
if (traversalPath.count() > 0 &&
|
|
145
142
|
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
146
143
|
return sub.has(traversalPath);
|
|
@@ -151,22 +148,16 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
151
148
|
return false;
|
|
152
149
|
};
|
|
153
150
|
CustomList.prototype.set = function (path, newValue) {
|
|
154
|
-
if (
|
|
151
|
+
if (path instanceof generics_1.CustomValue) {
|
|
155
152
|
return this.set(new path_1.default([path]), newValue);
|
|
156
153
|
}
|
|
157
154
|
var traversalPath = path.clone();
|
|
158
155
|
var last = traversalPath.last();
|
|
159
156
|
var current = traversalPath.next();
|
|
160
|
-
if (current
|
|
161
|
-
var currentIndex =
|
|
162
|
-
var
|
|
163
|
-
if (
|
|
164
|
-
currentIndex = this.getItemIndex(currentIndex);
|
|
165
|
-
}
|
|
166
|
-
if (isCurrentNumber &&
|
|
167
|
-
currentIndex >= 0 &&
|
|
168
|
-
currentIndex < this.value.length) {
|
|
169
|
-
var sub = this.value[currentIndex];
|
|
157
|
+
if (current instanceof number_1.default) {
|
|
158
|
+
var currentIndex = this.getItemIndex(current.toInt());
|
|
159
|
+
var sub = this.value[currentIndex];
|
|
160
|
+
if (sub) {
|
|
170
161
|
if (traversalPath.count() > 0 &&
|
|
171
162
|
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
172
163
|
sub.set(traversalPath, newValue);
|
|
@@ -175,31 +166,25 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
175
166
|
}
|
|
176
167
|
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
177
168
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return;
|
|
169
|
+
if (last instanceof number_1.default) {
|
|
170
|
+
var lastIndex = this.getItemIndex(last.toInt());
|
|
171
|
+
if (lastIndex >= 0 && lastIndex < this.value.length) {
|
|
172
|
+
this.value[lastIndex] = newValue;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
throw new Error("Index error (list index ".concat(lastIndex, " out of range)."));
|
|
186
176
|
}
|
|
187
|
-
throw new Error("Index
|
|
177
|
+
throw new Error("Index is not a number.");
|
|
188
178
|
};
|
|
189
179
|
CustomList.prototype.get = function (path) {
|
|
190
|
-
if (
|
|
180
|
+
if (path instanceof generics_1.CustomValue) {
|
|
191
181
|
return this.get(new path_1.default([path]));
|
|
192
182
|
}
|
|
193
183
|
var traversalPath = path.clone();
|
|
194
184
|
var current = traversalPath.next();
|
|
195
|
-
if (current
|
|
196
|
-
var currentIndex =
|
|
197
|
-
|
|
198
|
-
if (isCurrentNumber) {
|
|
199
|
-
currentIndex = this.getItemIndex(currentIndex);
|
|
200
|
-
}
|
|
201
|
-
if (isCurrentNumber &&
|
|
202
|
-
currentIndex >= 0 &&
|
|
185
|
+
if (current instanceof number_1.default) {
|
|
186
|
+
var currentIndex = this.getItemIndex(current.toInt());
|
|
187
|
+
if (currentIndex >= 0 &&
|
|
203
188
|
currentIndex < this.value.length) {
|
|
204
189
|
var sub = this.value[currentIndex];
|
|
205
190
|
if (traversalPath.count() > 0) {
|
|
@@ -211,13 +196,10 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
211
196
|
return sub;
|
|
212
197
|
}
|
|
213
198
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (isCurrentNumber) {
|
|
219
|
-
throw new Error("Index error (list index ".concat(currentIndex, " out of range)."));
|
|
220
|
-
}
|
|
199
|
+
throw new Error("Index error (list index ".concat(currentIndex, " out of range)."));
|
|
200
|
+
}
|
|
201
|
+
else if (path.count() === 1 && CustomList.getIntrinsics().has(current.toString())) {
|
|
202
|
+
return CustomList.getIntrinsics().get(current.toString());
|
|
221
203
|
}
|
|
222
204
|
throw new Error("Unknown path in list ".concat(path.toString(), "."));
|
|
223
205
|
};
|
package/dist/types/map.d.ts
CHANGED
|
@@ -2,19 +2,24 @@ import IntrinsicsContainer from '../intrinsics-container';
|
|
|
2
2
|
import Path from '../utils/path';
|
|
3
3
|
import CustomFunction from './function';
|
|
4
4
|
import { CustomObject, CustomValue } from './generics';
|
|
5
|
+
import CustomString from './string';
|
|
6
|
+
export declare const CLASS_ID_PROPERTY: CustomString;
|
|
7
|
+
export declare const getValue: (map: CustomMap, mapKey: CustomValue) => CustomValue;
|
|
8
|
+
export declare const hasValue: (map: CustomMap, mapKey: CustomValue) => boolean;
|
|
9
|
+
export declare const setValue: (map: CustomMap, mapKey: CustomValue, mapValue: CustomValue) => void;
|
|
5
10
|
export declare class CustomMapIterator implements Iterator<CustomValue> {
|
|
6
|
-
value: Map<
|
|
11
|
+
value: Map<CustomValue, CustomValue>;
|
|
7
12
|
index: number;
|
|
8
|
-
constructor(value: Map<
|
|
13
|
+
constructor(value: Map<CustomValue, CustomValue>);
|
|
9
14
|
next(): IteratorResult<CustomMap>;
|
|
10
15
|
}
|
|
11
16
|
export default class CustomMap extends CustomObject {
|
|
12
17
|
private static intrinsics;
|
|
13
18
|
static getIntrinsics(): IntrinsicsContainer;
|
|
14
19
|
static addIntrinsic(name: string, fn: CustomFunction): void;
|
|
15
|
-
readonly value: Map<
|
|
20
|
+
readonly value: Map<CustomValue, CustomValue>;
|
|
16
21
|
private isInstance;
|
|
17
|
-
constructor(value?: Map<
|
|
22
|
+
constructor(value?: Map<CustomValue, CustomValue>);
|
|
18
23
|
getCustomType(): string;
|
|
19
24
|
toString(): string;
|
|
20
25
|
fork(): CustomMap;
|
|
@@ -22,9 +27,9 @@ export default class CustomMap extends CustomObject {
|
|
|
22
27
|
toInt(): number;
|
|
23
28
|
toTruthy(): boolean;
|
|
24
29
|
[Symbol.iterator](): CustomMapIterator;
|
|
25
|
-
extend(map: CustomMap | Map<
|
|
26
|
-
has(path: Path<
|
|
27
|
-
set(path: Path<
|
|
28
|
-
get(path: Path<
|
|
30
|
+
extend(map: CustomMap | Map<CustomValue, CustomValue>): CustomMap;
|
|
31
|
+
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
32
|
+
set(path: Path<CustomValue> | CustomValue, newValue: CustomValue): void;
|
|
33
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
29
34
|
createInstance(): CustomMap;
|
|
30
35
|
}
|
package/dist/types/map.js
CHANGED
|
@@ -45,12 +45,75 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.CustomMapIterator = void 0;
|
|
48
|
+
exports.CustomMapIterator = exports.setValue = exports.hasValue = exports.getValue = exports.CLASS_ID_PROPERTY = void 0;
|
|
49
49
|
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
50
50
|
var path_1 = __importDefault(require("../utils/path"));
|
|
51
|
+
var default_1 = __importDefault(require("./default"));
|
|
51
52
|
var generics_1 = require("./generics");
|
|
52
53
|
var nil_1 = __importDefault(require("./nil"));
|
|
53
54
|
var string_1 = __importDefault(require("./string"));
|
|
55
|
+
exports.CLASS_ID_PROPERTY = new string_1.default('classID');
|
|
56
|
+
var getValue = function (map, mapKey) {
|
|
57
|
+
var e_1, _a;
|
|
58
|
+
try {
|
|
59
|
+
for (var _b = __values(map.value), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
60
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
61
|
+
if (key.value === mapKey.value) {
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
67
|
+
finally {
|
|
68
|
+
try {
|
|
69
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
70
|
+
}
|
|
71
|
+
finally { if (e_1) throw e_1.error; }
|
|
72
|
+
}
|
|
73
|
+
return default_1.default.Void;
|
|
74
|
+
};
|
|
75
|
+
exports.getValue = getValue;
|
|
76
|
+
var hasValue = function (map, mapKey) {
|
|
77
|
+
var e_2, _a;
|
|
78
|
+
try {
|
|
79
|
+
for (var _b = __values(map.value.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
80
|
+
var key = _c.value;
|
|
81
|
+
if (key.value === mapKey.value) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
87
|
+
finally {
|
|
88
|
+
try {
|
|
89
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
90
|
+
}
|
|
91
|
+
finally { if (e_2) throw e_2.error; }
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
};
|
|
95
|
+
exports.hasValue = hasValue;
|
|
96
|
+
var setValue = function (map, mapKey, mapValue) {
|
|
97
|
+
var e_3, _a;
|
|
98
|
+
try {
|
|
99
|
+
for (var _b = __values(map.value.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
100
|
+
var key = _c.value;
|
|
101
|
+
if (key.value === mapKey.value) {
|
|
102
|
+
map.value.set(key, mapValue);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
108
|
+
finally {
|
|
109
|
+
try {
|
|
110
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
111
|
+
}
|
|
112
|
+
finally { if (e_3) throw e_3.error; }
|
|
113
|
+
}
|
|
114
|
+
map.value.set(mapKey, mapValue);
|
|
115
|
+
};
|
|
116
|
+
exports.setValue = setValue;
|
|
54
117
|
var CustomMapIterator = /** @class */ (function () {
|
|
55
118
|
function CustomMapIterator(value) {
|
|
56
119
|
var me = this;
|
|
@@ -69,8 +132,8 @@ var CustomMapIterator = /** @class */ (function () {
|
|
|
69
132
|
var key = keys[me.index++];
|
|
70
133
|
return {
|
|
71
134
|
value: new CustomMap(new Map([
|
|
72
|
-
[
|
|
73
|
-
['value', me.value.get(key)]
|
|
135
|
+
[new string_1.default('key'), key],
|
|
136
|
+
[new string_1.default('value'), me.value.get(key)]
|
|
74
137
|
])),
|
|
75
138
|
done: false
|
|
76
139
|
};
|
|
@@ -94,13 +157,13 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
94
157
|
this.intrinsics.add(name, fn);
|
|
95
158
|
};
|
|
96
159
|
CustomMap.prototype.getCustomType = function () {
|
|
97
|
-
if (this.
|
|
98
|
-
return this.
|
|
160
|
+
if ((0, exports.hasValue)(this, exports.CLASS_ID_PROPERTY)) {
|
|
161
|
+
return (0, exports.getValue)(this, exports.CLASS_ID_PROPERTY).toString();
|
|
99
162
|
}
|
|
100
163
|
return 'map';
|
|
101
164
|
};
|
|
102
165
|
CustomMap.prototype.toString = function () {
|
|
103
|
-
var
|
|
166
|
+
var e_4, _a;
|
|
104
167
|
var values = [];
|
|
105
168
|
try {
|
|
106
169
|
for (var _b = __values(this.value), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -108,12 +171,12 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
108
171
|
values.push("".concat(key, ": ").concat(value.toString()));
|
|
109
172
|
}
|
|
110
173
|
}
|
|
111
|
-
catch (
|
|
174
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
112
175
|
finally {
|
|
113
176
|
try {
|
|
114
177
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
115
178
|
}
|
|
116
|
-
finally { if (
|
|
179
|
+
finally { if (e_4) throw e_4.error; }
|
|
117
180
|
}
|
|
118
181
|
return "{ ".concat(values.join(', '), " }");
|
|
119
182
|
};
|
|
@@ -133,34 +196,34 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
133
196
|
return new CustomMapIterator(this.value);
|
|
134
197
|
};
|
|
135
198
|
CustomMap.prototype.extend = function (map) {
|
|
136
|
-
var
|
|
199
|
+
var e_5, _a;
|
|
137
200
|
if (map instanceof CustomMap) {
|
|
138
201
|
map = map.value;
|
|
139
202
|
}
|
|
140
203
|
try {
|
|
141
204
|
for (var map_1 = __values(map), map_1_1 = map_1.next(); !map_1_1.done; map_1_1 = map_1.next()) {
|
|
142
205
|
var _b = __read(map_1_1.value, 2), key = _b[0], value = _b[1];
|
|
143
|
-
|
|
206
|
+
(0, exports.setValue)(this, key, value);
|
|
144
207
|
}
|
|
145
208
|
}
|
|
146
|
-
catch (
|
|
209
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
147
210
|
finally {
|
|
148
211
|
try {
|
|
149
212
|
if (map_1_1 && !map_1_1.done && (_a = map_1.return)) _a.call(map_1);
|
|
150
213
|
}
|
|
151
|
-
finally { if (
|
|
214
|
+
finally { if (e_5) throw e_5.error; }
|
|
152
215
|
}
|
|
153
216
|
return this;
|
|
154
217
|
};
|
|
155
218
|
CustomMap.prototype.has = function (path) {
|
|
156
|
-
if (
|
|
219
|
+
if (path instanceof generics_1.CustomValue) {
|
|
157
220
|
return this.has(new path_1.default([path]));
|
|
158
221
|
}
|
|
159
222
|
var traversalPath = path.clone();
|
|
160
223
|
var current = traversalPath.next();
|
|
161
224
|
if (current !== null) {
|
|
162
|
-
if (
|
|
163
|
-
var sub =
|
|
225
|
+
if ((0, exports.hasValue)(this, current)) {
|
|
226
|
+
var sub = (0, exports.getValue)(this, current);
|
|
164
227
|
if (traversalPath.count() > 0 &&
|
|
165
228
|
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
166
229
|
return sub.has(traversalPath);
|
|
@@ -171,15 +234,15 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
171
234
|
return false;
|
|
172
235
|
};
|
|
173
236
|
CustomMap.prototype.set = function (path, newValue) {
|
|
174
|
-
if (
|
|
237
|
+
if (path instanceof generics_1.CustomValue) {
|
|
175
238
|
return this.set(new path_1.default([path]), newValue);
|
|
176
239
|
}
|
|
177
240
|
var traversalPath = path.clone();
|
|
178
241
|
var last = traversalPath.last();
|
|
179
242
|
var current = traversalPath.next();
|
|
180
243
|
if (current !== null) {
|
|
181
|
-
if (
|
|
182
|
-
var sub =
|
|
244
|
+
if ((0, exports.hasValue)(this, current)) {
|
|
245
|
+
var sub = (0, exports.getValue)(this, current);
|
|
183
246
|
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
184
247
|
sub.set(traversalPath, newValue);
|
|
185
248
|
return;
|
|
@@ -187,17 +250,17 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
187
250
|
}
|
|
188
251
|
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
189
252
|
}
|
|
190
|
-
|
|
253
|
+
(0, exports.setValue)(this, last, newValue);
|
|
191
254
|
};
|
|
192
255
|
CustomMap.prototype.get = function (path) {
|
|
193
|
-
if (
|
|
256
|
+
if (path instanceof generics_1.CustomValue) {
|
|
194
257
|
return this.get(new path_1.default([path]));
|
|
195
258
|
}
|
|
196
259
|
var traversalPath = path.clone();
|
|
197
260
|
var current = traversalPath.next();
|
|
198
261
|
if (current !== null) {
|
|
199
|
-
if (
|
|
200
|
-
var sub =
|
|
262
|
+
if ((0, exports.hasValue)(this, current)) {
|
|
263
|
+
var sub = (0, exports.getValue)(this, current);
|
|
201
264
|
if (traversalPath.count() > 0) {
|
|
202
265
|
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
203
266
|
return sub.get(traversalPath);
|
|
@@ -207,8 +270,8 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
207
270
|
return sub;
|
|
208
271
|
}
|
|
209
272
|
}
|
|
210
|
-
else if (path.count() === 1 && CustomMap.getIntrinsics().has(current)) {
|
|
211
|
-
return CustomMap.getIntrinsics().get(current);
|
|
273
|
+
else if (path.count() === 1 && CustomMap.getIntrinsics().has(current.toString())) {
|
|
274
|
+
return CustomMap.getIntrinsics().get(current.toString());
|
|
212
275
|
}
|
|
213
276
|
}
|
|
214
277
|
throw new Error("Unknown path in map ".concat(path.toString(), "."));
|
package/dist/types/nil.d.ts
CHANGED
package/dist/types/nil.js
CHANGED
|
@@ -19,7 +19,9 @@ var generics_1 = require("./generics");
|
|
|
19
19
|
var CustomNil = /** @class */ (function (_super) {
|
|
20
20
|
__extends(CustomNil, _super);
|
|
21
21
|
function CustomNil() {
|
|
22
|
-
|
|
22
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
_this.value = null;
|
|
24
|
+
return _this;
|
|
23
25
|
}
|
|
24
26
|
CustomNil.prototype.getCustomType = function () {
|
|
25
27
|
return 'null';
|
package/dist/types/string.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export default class CustomString extends CustomValueWithIntrinsics {
|
|
|
27
27
|
slice(a: CustomValue, b: CustomValue): CustomString;
|
|
28
28
|
[Symbol.iterator](): CustomStringIterator;
|
|
29
29
|
getCharIndex(index: number): number;
|
|
30
|
-
has(path: Path<
|
|
31
|
-
set(_path: Path<
|
|
32
|
-
get(path: Path<
|
|
30
|
+
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
31
|
+
set(_path: Path<CustomValue> | CustomValue, _newValue: CustomValue): void;
|
|
32
|
+
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
33
33
|
}
|
package/dist/types/string.js
CHANGED
|
@@ -23,6 +23,7 @@ var intrinsics_container_1 = __importDefault(require("../intrinsics-container"))
|
|
|
23
23
|
var path_1 = __importDefault(require("../utils/path"));
|
|
24
24
|
var default_1 = __importDefault(require("./default"));
|
|
25
25
|
var generics_1 = require("./generics");
|
|
26
|
+
var number_1 = __importDefault(require("./number"));
|
|
26
27
|
var CustomStringIterator = /** @class */ (function () {
|
|
27
28
|
function CustomStringIterator(value) {
|
|
28
29
|
var me = this;
|
|
@@ -104,16 +105,13 @@ var CustomString = /** @class */ (function (_super) {
|
|
|
104
105
|
return CustomString.getCharIndex(this, index);
|
|
105
106
|
};
|
|
106
107
|
CustomString.prototype.has = function (path) {
|
|
107
|
-
if (
|
|
108
|
+
if (path instanceof generics_1.CustomValue) {
|
|
108
109
|
return this.has(new path_1.default([path]));
|
|
109
110
|
}
|
|
110
111
|
var traversalPath = path.clone();
|
|
111
112
|
var current = traversalPath.next();
|
|
112
|
-
if (current
|
|
113
|
-
var index =
|
|
114
|
-
if (Number.isNaN(index)) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
113
|
+
if (current instanceof number_1.default) {
|
|
114
|
+
var index = current.toInt();
|
|
117
115
|
return !!this.value[index];
|
|
118
116
|
}
|
|
119
117
|
return false;
|
|
@@ -122,24 +120,22 @@ var CustomString = /** @class */ (function (_super) {
|
|
|
122
120
|
throw new Error('Mutable operations are not allowed on a string.');
|
|
123
121
|
};
|
|
124
122
|
CustomString.prototype.get = function (path) {
|
|
125
|
-
if (
|
|
123
|
+
if (path instanceof generics_1.CustomValue) {
|
|
126
124
|
return this.get(new path_1.default([path]));
|
|
127
125
|
}
|
|
128
126
|
var traversalPath = path.clone();
|
|
129
127
|
var current = traversalPath.next();
|
|
130
|
-
if (current
|
|
131
|
-
var currentIndex =
|
|
132
|
-
var
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
if (isCurrentNumber) {
|
|
137
|
-
return new CustomString(this.value[currentIndex].toString());
|
|
138
|
-
}
|
|
139
|
-
else if (path.count() === 1 &&
|
|
140
|
-
CustomString.getIntrinsics().has(current)) {
|
|
141
|
-
return CustomString.intrinsics.get(current);
|
|
128
|
+
if (current instanceof number_1.default) {
|
|
129
|
+
var currentIndex = this.getCharIndex(current.toInt());
|
|
130
|
+
var segment = this.value[currentIndex];
|
|
131
|
+
if (segment) {
|
|
132
|
+
return new CustomString(segment);
|
|
142
133
|
}
|
|
134
|
+
throw new Error("Index error (string index ".concat(currentIndex, " out of range)."));
|
|
135
|
+
}
|
|
136
|
+
else if (path.count() === 1 &&
|
|
137
|
+
CustomString.getIntrinsics().has(current.toString())) {
|
|
138
|
+
return CustomString.intrinsics.get(current.toString());
|
|
143
139
|
}
|
|
144
140
|
return default_1.default.Void;
|
|
145
141
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greybel-interpreter",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Interpreter",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"watch": "tsc -w -p .",
|
|
11
11
|
"clean": "rm -rf dist",
|
|
12
12
|
"test": "jest ./tests",
|
|
13
|
-
"lint": "eslint
|
|
14
|
-
"lint:fix": "eslint --fix
|
|
13
|
+
"lint": "eslint ./src/**/*.ts",
|
|
14
|
+
"lint:fix": "eslint --fix ./src/**/*.ts"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typescript": "^4.5.4"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"greybel-core": "^0.
|
|
52
|
-
"greyscript-core": "^0.
|
|
51
|
+
"greybel-core": "^0.4.1",
|
|
52
|
+
"greyscript-core": "^0.3.4"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"greyscript",
|