greybel-interpreter 0.5.6 → 0.6.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.d.ts CHANGED
@@ -18,7 +18,6 @@ export declare enum ContextState {
18
18
  export declare class Scope extends CustomMap {
19
19
  context: OperationContext;
20
20
  constructor(context: OperationContext);
21
- set(path: string[], value: any): Promise<void>;
22
21
  get(path: string[]): Promise<any>;
23
22
  getCallable(path: string[]): Promise<Callable>;
24
23
  }
@@ -70,9 +69,9 @@ export declare class OperationContext {
70
69
  processState: OperationContextProcessState;
71
70
  isProtected: boolean;
72
71
  injected: boolean;
73
- api: Scope | null;
74
- locals: Scope | null;
75
- globals: Scope | null;
72
+ api: OperationContext | null;
73
+ locals: OperationContext | null;
74
+ globals: OperationContext | null;
76
75
  constructor(options: OperationContextOptions);
77
76
  step(item: ASTBase): Promise<void>;
78
77
  setLastActive(opc: OperationContext): OperationContext;
@@ -81,10 +80,12 @@ export declare class OperationContext {
81
80
  exit(): Promise<OperationContext>;
82
81
  isPending(): boolean;
83
82
  setPending(pending: boolean): OperationContext;
84
- lookupType(validate: (type: ContextType) => boolean): Scope;
85
- lookupAPI(): Scope;
86
- lookupGlobals(): Scope;
87
- lookupLocals(): Scope;
83
+ lookupAllOfType(validate: (type: ContextType) => boolean): OperationContext[];
84
+ lookupType(validate: (type: ContextType) => boolean): OperationContext;
85
+ lookupAllScopes(): OperationContext[];
86
+ lookupAPI(): OperationContext;
87
+ lookupGlobals(): OperationContext;
88
+ lookupLocals(): OperationContext;
88
89
  valueOf(): CustomMap;
89
90
  extend(map: Map<string, any>): OperationContext;
90
91
  set(path: any[], value: any): Promise<void>;
package/dist/context.js CHANGED
@@ -14,6 +14,42 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
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
+ };
17
53
  var __read = (this && this.__read) || function (o, n) {
18
54
  var m = typeof Symbol === "function" && o[Symbol.iterator];
19
55
  if (!m) return o;
@@ -67,87 +103,81 @@ var Scope = /** @class */ (function (_super) {
67
103
  _this.context = context;
68
104
  return _this;
69
105
  }
70
- Scope.prototype.set = function (path, value) {
71
- var me = this;
72
- var traversalPath = [].concat(path);
73
- var current = traversalPath.shift();
74
- if (current != null) {
75
- if (current === 'locals') {
76
- return me.context.locals.set(traversalPath, value);
77
- }
78
- else if (current === 'globals') {
79
- return me.context.globals.set(traversalPath, value);
80
- }
81
- else if (me.context.locals != null) {
82
- return map_1.default.prototype.set.call(me.context.locals, path, value);
83
- }
84
- else {
85
- throw new Error("Cannot set path ".concat(path.join('.')));
86
- }
87
- }
88
- };
89
106
  Scope.prototype.get = function (path) {
90
- var _a, _b, _c;
91
- var me = this;
92
- var traversalPath = [].concat(path);
93
- var current = traversalPath.shift();
94
- if (current != null) {
95
- if (current === 'locals') {
96
- return traversalPath.length === 0
97
- ? Promise.resolve(me.context.locals)
98
- : me.context.locals.get(traversalPath);
99
- }
100
- else if (current === 'globals') {
101
- return traversalPath.length === 0
102
- ? Promise.resolve(me.context.globals)
103
- : me.context.globals.get(traversalPath);
104
- }
105
- else if ((_a = me.context.locals) === null || _a === void 0 ? void 0 : _a.value.has(current)) {
106
- return map_1.default.prototype.get.call(me.context.locals, path);
107
- }
108
- else if ((_b = me.context.globals) === null || _b === void 0 ? void 0 : _b.value.has(current)) {
109
- return map_1.default.prototype.get.call(me.context.globals, path);
110
- }
111
- else if ((_c = me.context.api) === null || _c === void 0 ? void 0 : _c.value.has(current)) {
112
- return map_1.default.prototype.get.call(me.context.api, path);
113
- }
114
- else if (me.value.has(current)) {
115
- return _super.prototype.get.call(this, path);
116
- }
117
- else {
118
- throw new Error("Cannot get path ".concat(path.join('.')));
119
- }
120
- }
121
- return null;
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var me, traversalPath, current;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0:
112
+ me = this;
113
+ traversalPath = [].concat(path);
114
+ current = traversalPath.shift();
115
+ if (path.length === 0) {
116
+ return [2 /*return*/, Promise.resolve(me)];
117
+ }
118
+ if (!(current === 'locals' || current === 'globals')) return [3 /*break*/, 1];
119
+ return [2 /*return*/, me.context.get(path)];
120
+ case 1: return [4 /*yield*/, me.has(path)];
121
+ case 2:
122
+ if (!_a.sent()) return [3 /*break*/, 3];
123
+ return [2 /*return*/, _super.prototype.get.call(this, path)];
124
+ case 3: return [4 /*yield*/, me.context.api.scope.has(path)];
125
+ case 4:
126
+ if (_a.sent()) {
127
+ return [2 /*return*/, me.context.api.get(path)];
128
+ }
129
+ else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
130
+ return [2 /*return*/, Promise.resolve(map_1.default.intrinsics.get(current).bind(null, me))];
131
+ }
132
+ else if (me.context.previous) {
133
+ return [2 /*return*/, me.context.previous.get(path)];
134
+ }
135
+ else {
136
+ throw new Error("Cannot get path ".concat(path.join('.')));
137
+ }
138
+ _a.label = 5;
139
+ case 5: return [2 /*return*/];
140
+ }
141
+ });
142
+ });
122
143
  };
123
144
  Scope.prototype.getCallable = function (path) {
124
- var _a, _b, _c;
125
- var me = this;
126
- var traversalPath = [].concat(path);
127
- var current = traversalPath.shift();
128
- if (current != null) {
129
- if (current === 'locals') {
130
- return me.context.locals.getCallable(traversalPath);
131
- }
132
- else if (current === 'globals') {
133
- return me.context.globals.getCallable(traversalPath);
134
- }
135
- else if ((_a = me.context.locals) === null || _a === void 0 ? void 0 : _a.value.has(current)) {
136
- return map_1.default.prototype.getCallable.call(me.context.locals, path);
137
- }
138
- else if ((_b = me.context.globals) === null || _b === void 0 ? void 0 : _b.value.has(current)) {
139
- return map_1.default.prototype.getCallable.call(me.context.globals, path);
140
- }
141
- else if ((_c = me.context.api) === null || _c === void 0 ? void 0 : _c.value.has(current)) {
142
- return map_1.default.prototype.getCallable.call(me.context.api, path);
143
- }
144
- else {
145
- return _super.prototype.getCallable.call(this, path);
146
- }
147
- }
148
- return Promise.resolve({
149
- origin: me,
150
- context: null
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var me, traversalPath, current;
147
+ return __generator(this, function (_a) {
148
+ switch (_a.label) {
149
+ case 0:
150
+ me = this;
151
+ traversalPath = [].concat(path);
152
+ current = traversalPath.shift();
153
+ if (current === 'locals' || current === 'globals') {
154
+ return [2 /*return*/, me.context.getCallable(path)];
155
+ }
156
+ return [4 /*yield*/, me.has(path)];
157
+ case 1:
158
+ if (!_a.sent()) return [3 /*break*/, 2];
159
+ return [2 /*return*/, _super.prototype.getCallable.call(this, path)];
160
+ case 2: return [4 /*yield*/, me.context.api.scope.has(path)];
161
+ case 3:
162
+ if (_a.sent()) {
163
+ return [2 /*return*/, me.context.api.getCallable(path)];
164
+ }
165
+ else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
166
+ return [2 /*return*/, Promise.resolve({
167
+ origin: map_1.default.intrinsics.get(current).bind(null, me),
168
+ context: me
169
+ })];
170
+ }
171
+ else if (me.context.previous) {
172
+ return [2 /*return*/, me.context.previous.getCallable(path)];
173
+ }
174
+ else {
175
+ throw new Error("Cannot get callable path ".concat(path.join('.')));
176
+ }
177
+ _a.label = 4;
178
+ case 4: return [2 /*return*/];
179
+ }
180
+ });
151
181
  });
152
182
  };
153
183
  return Scope;
@@ -238,7 +268,7 @@ var OperationContext = /** @class */ (function () {
238
268
  };
239
269
  me.api = me.lookupAPI();
240
270
  me.globals = me.lookupGlobals();
241
- me.locals = me.lookupLocals();
271
+ me.locals = me.lookupLocals() || me;
242
272
  }
243
273
  OperationContext.prototype.step = function (item) {
244
274
  var me = this;
@@ -294,20 +324,38 @@ var OperationContext = /** @class */ (function () {
294
324
  me.processState.pending = pending;
295
325
  return me;
296
326
  };
327
+ OperationContext.prototype.lookupAllOfType = function (validate) {
328
+ var me = this;
329
+ var result = [];
330
+ if (validate(me.type)) {
331
+ result.push(me);
332
+ }
333
+ var current = me.previous;
334
+ while (current) {
335
+ if (validate(current.type)) {
336
+ result.push(current);
337
+ }
338
+ current = current.previous;
339
+ }
340
+ return result;
341
+ };
297
342
  OperationContext.prototype.lookupType = function (validate) {
298
343
  var me = this;
299
344
  if (validate(me.type)) {
300
- return me.scope;
345
+ return me;
301
346
  }
302
347
  var current = me.previous;
303
348
  while (current) {
304
349
  if (validate(current.type)) {
305
- return current.scope;
350
+ return current;
306
351
  }
307
352
  current = current.previous;
308
353
  }
309
354
  return null;
310
355
  };
356
+ OperationContext.prototype.lookupAllScopes = function () {
357
+ return this.lookupAllOfType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
358
+ };
311
359
  OperationContext.prototype.lookupAPI = function () {
312
360
  return this.lookupType(function (type) { return [ContextType.API].includes(type); });
313
361
  };
@@ -318,7 +366,7 @@ var OperationContext = /** @class */ (function () {
318
366
  return this.lookupType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
319
367
  };
320
368
  OperationContext.prototype.valueOf = function () {
321
- return this.scope.valueOf();
369
+ return this.scope;
322
370
  };
323
371
  OperationContext.prototype.extend = function (map) {
324
372
  var _a;
@@ -334,28 +382,46 @@ var OperationContext = /** @class */ (function () {
334
382
  OperationContext.prototype.set = function (path, value) {
335
383
  var _a;
336
384
  var me = this;
385
+ var traversalPath = [].concat(path);
386
+ var current = traversalPath.shift();
387
+ if (current === 'locals') {
388
+ return me.locals.set(traversalPath, value);
389
+ }
390
+ else if (current === 'globals') {
391
+ return me.globals.set(traversalPath, value);
392
+ }
337
393
  if (me.state === ContextState.TEMPORARY) {
338
394
  return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
339
395
  }
340
- else {
341
- return me.scope.set(path, value);
342
- }
396
+ return me.locals.scope.set(path, value);
343
397
  };
344
398
  OperationContext.prototype.get = function (path) {
345
399
  var _a;
346
400
  var me = this;
347
- if (me.state === ContextState.TEMPORARY) {
401
+ var traversalPath = [].concat(path);
402
+ var current = traversalPath.shift();
403
+ if (current === 'locals') {
404
+ return me.locals.get(traversalPath);
405
+ }
406
+ else if (current === 'globals') {
407
+ return me.globals.get(traversalPath);
408
+ }
409
+ else if (me.state === ContextState.TEMPORARY) {
348
410
  return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.get(path);
349
411
  }
350
- return me.scope.get(path);
412
+ return me.locals.scope.get(path);
351
413
  };
352
414
  OperationContext.prototype.getCallable = function (path) {
353
- var _a;
354
415
  var me = this;
355
- if (me.state === ContextState.TEMPORARY) {
356
- return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
416
+ var traversalPath = [].concat(path);
417
+ var current = traversalPath.shift();
418
+ if (current === 'locals') {
419
+ return me.locals.getCallable(traversalPath);
420
+ }
421
+ else if (current === 'globals') {
422
+ return me.globals.getCallable(traversalPath);
357
423
  }
358
- return me.scope.getCallable(path);
424
+ return me.locals.scope.getCallable(path);
359
425
  };
360
426
  OperationContext.prototype.setMemory = function (key, value) {
361
427
  var me = this;
@@ -5,7 +5,7 @@ export declare class CustomListIterator implements Iterator<any> {
5
5
  constructor(value: any);
6
6
  next(): IteratorResult<any>;
7
7
  }
8
- export declare function itemAtIndex(list: any[], n: number): number;
8
+ export declare function itemAtIndex(list: any[], n: number): number | null;
9
9
  export default class CustomList extends CustomObjectType {
10
10
  static intrinsics: Map<string, Function>;
11
11
  value: any[];
@@ -17,7 +17,6 @@ export default class CustomList extends CustomObjectType {
17
17
  set(path: any[], value: any): Promise<void>;
18
18
  get(path: any[]): Promise<any>;
19
19
  getCallable(path: any[]): Promise<Callable>;
20
- callMethod(method: string[], ...args: any[]): any;
21
20
  getType(): string;
22
21
  valueOf(): CustomList | null;
23
22
  toString(): string;
@@ -50,35 +50,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
50
50
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
51
  }
52
52
  };
53
- var __read = (this && this.__read) || function (o, n) {
54
- var m = typeof Symbol === "function" && o[Symbol.iterator];
55
- if (!m) return o;
56
- var i = m.call(o), r, ar = [], e;
57
- try {
58
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
- }
60
- catch (error) { e = { error: error }; }
61
- finally {
62
- try {
63
- if (r && !r.done && (m = i["return"])) m.call(i);
64
- }
65
- finally { if (e) throw e.error; }
66
- }
67
- return ar;
68
- };
69
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
70
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
71
- if (ar || !(i in from)) {
72
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
73
- ar[i] = from[i];
74
- }
75
- }
76
- return to.concat(ar || Array.prototype.slice.call(from));
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
77
55
  };
78
56
  Object.defineProperty(exports, "__esModule", { value: true });
79
57
  exports.itemAtIndex = exports.CustomListIterator = void 0;
80
58
  var operation_1 = require("../types/operation");
81
59
  var custom_type_1 = require("../types/custom-type");
60
+ var string_1 = __importDefault(require("./string"));
82
61
  var CustomListIterator = /** @class */ (function () {
83
62
  function CustomListIterator(value) {
84
63
  var me = this;
@@ -102,6 +81,8 @@ var CustomListIterator = /** @class */ (function () {
102
81
  }());
103
82
  exports.CustomListIterator = CustomListIterator;
104
83
  function itemAtIndex(list, n) {
84
+ if (Number.isNaN(n))
85
+ return null;
105
86
  n = Math.trunc(n) || 0;
106
87
  if (n < 0)
107
88
  n += list.length;
@@ -177,7 +158,8 @@ var CustomList = /** @class */ (function (_super) {
177
158
  currentIndex = itemAtIndex(refs, Number(current));
178
159
  if (refs.hasOwnProperty(currentIndex)) {
179
160
  sub = refs[currentIndex];
180
- if (traversalPath.length > 0 && sub instanceof custom_type_1.CustomObjectType) {
161
+ if (traversalPath.length > 0 &&
162
+ (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default)) {
181
163
  return [2 /*return*/, sub.get(traversalPath)];
182
164
  }
183
165
  if (traversalPath.length === 0) {
@@ -187,9 +169,6 @@ var CustomList = /** @class */ (function (_super) {
187
169
  else if (path.length === 1 && CustomList.intrinsics.has(current)) {
188
170
  return [2 /*return*/, CustomList.intrinsics.get(current).bind(null, me)];
189
171
  }
190
- else {
191
- throw new Error("Cannot get path ".concat(path.join('.')));
192
- }
193
172
  }
194
173
  return [2 /*return*/, null];
195
174
  });
@@ -207,7 +186,7 @@ var CustomList = /** @class */ (function (_super) {
207
186
  currentIndex = itemAtIndex(refs, Number(current));
208
187
  if (refs.hasOwnProperty(currentIndex)) {
209
188
  sub = refs[currentIndex];
210
- if (sub instanceof custom_type_1.CustomObjectType) {
189
+ if (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default) {
211
190
  return [2 /*return*/, sub.getCallable(traversalPath)];
212
191
  }
213
192
  if (traversalPath.length === 0) {
@@ -223,44 +202,14 @@ var CustomList = /** @class */ (function (_super) {
223
202
  context: me
224
203
  }];
225
204
  }
226
- else {
227
- throw new Error("Cannot get path ".concat(path.join('.')));
228
- }
229
205
  }
230
206
  return [2 /*return*/, {
231
- origin: refs,
207
+ origin: null,
232
208
  context: me
233
209
  }];
234
210
  });
235
211
  });
236
212
  };
237
- CustomList.prototype.callMethod = function (method) {
238
- var _a;
239
- var _b;
240
- var args = [];
241
- for (var _i = 1; _i < arguments.length; _i++) {
242
- args[_i - 1] = arguments[_i];
243
- }
244
- if (method.length === 0) {
245
- throw new Error('Unexpected method length');
246
- }
247
- var me = this;
248
- var member = (_b = method[0]) === null || _b === void 0 ? void 0 : _b.toString();
249
- if (CustomList.isNumber(member)) {
250
- var memberIndex = itemAtIndex(me.value, Number(member));
251
- if (!me.value.hasOwnProperty(memberIndex)) {
252
- return null;
253
- }
254
- if (method.length > 1) {
255
- return (_a = me.value[memberIndex]).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
256
- }
257
- return me.value[memberIndex];
258
- }
259
- if (!CustomList.intrinsics.has(member)) {
260
- throw new Error("Cannot access ".concat(member, " in list"));
261
- }
262
- return CustomList.intrinsics.get(member).apply(void 0, __spreadArray([me], __read(args), false));
263
- };
264
213
  CustomList.prototype.getType = function () {
265
214
  return 'list';
266
215
  };
@@ -16,10 +16,10 @@ export default class CustomMap extends CustomObjectType implements Iterable<Cust
16
16
  constructor(value?: Map<string, any>);
17
17
  [Symbol.iterator](): CustomMapIterator;
18
18
  extend(value: Map<string, any>): CustomMap;
19
+ has(path: string[]): Promise<boolean>;
19
20
  set(path: string[], value: any): Promise<void>;
20
21
  get(path: string[]): Promise<any>;
21
22
  getCallable(path: string[]): Promise<Callable>;
22
- callMethod(method: string[], ...args: any[]): any;
23
23
  createInstance(): CustomMap;
24
24
  getType(): string;
25
25
  valueOf(): CustomMap | null;
@@ -39,10 +39,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
39
  }
40
40
  return to.concat(ar || Array.prototype.slice.call(from));
41
41
  };
42
+ var __importDefault = (this && this.__importDefault) || function (mod) {
43
+ return (mod && mod.__esModule) ? mod : { "default": mod };
44
+ };
42
45
  Object.defineProperty(exports, "__esModule", { value: true });
43
46
  exports.CustomMapIterator = void 0;
44
47
  var custom_type_1 = require("../types/custom-type");
45
48
  var operation_1 = require("../types/operation");
49
+ var string_1 = __importDefault(require("./string"));
46
50
  var CustomMapIterator = /** @class */ (function () {
47
51
  function CustomMapIterator(value) {
48
52
  var me = this;
@@ -87,8 +91,33 @@ var CustomMap = /** @class */ (function (_super) {
87
91
  me.value = new Map(__spreadArray(__spreadArray([], __read(me.value.entries()), false), __read(value.entries()), false));
88
92
  return me;
89
93
  };
94
+ CustomMap.prototype.has = function (path) {
95
+ var me = this;
96
+ if (path.length === 0) {
97
+ return Promise.resolve(true);
98
+ }
99
+ var traversalPath = [].concat(path);
100
+ var refs = me.value;
101
+ var current = traversalPath.shift();
102
+ if (current != null) {
103
+ if (refs.has(current)) {
104
+ var sub = refs.get(current);
105
+ if (traversalPath.length > 0 && sub instanceof custom_type_1.CustomObjectType) {
106
+ return sub.has(traversalPath);
107
+ }
108
+ if (traversalPath.length === 0) {
109
+ return Promise.resolve(true);
110
+ }
111
+ }
112
+ }
113
+ return Promise.resolve(false);
114
+ };
90
115
  CustomMap.prototype.set = function (path, value) {
91
116
  var me = this;
117
+ if (!path) {
118
+ console.warn('Cannot set empty path for ', me);
119
+ return;
120
+ }
92
121
  var traversalPath = [].concat(path);
93
122
  var refs = me.value;
94
123
  var last = traversalPath.pop();
@@ -100,9 +129,8 @@ var CustomMap = /** @class */ (function (_super) {
100
129
  return sub.set(traversalPath.concat(last), value);
101
130
  }
102
131
  }
103
- else {
104
- throw new Error("Cannot set path ".concat(path.join('.')));
105
- }
132
+ console.warn("Cannot set path ".concat(path === null || path === void 0 ? void 0 : path.join('.')));
133
+ return;
106
134
  }
107
135
  if (value instanceof operation_1.FunctionOperationBase) {
108
136
  refs.set(last, value.fork(me));
@@ -122,7 +150,8 @@ var CustomMap = /** @class */ (function (_super) {
122
150
  if (current != null) {
123
151
  if (refs.has(current)) {
124
152
  var sub = refs.get(current);
125
- if (traversalPath.length > 0 && sub instanceof custom_type_1.CustomObjectType) {
153
+ if (traversalPath.length > 0 &&
154
+ (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default)) {
126
155
  return sub.get(traversalPath);
127
156
  }
128
157
  if (traversalPath.length === 0) {
@@ -140,19 +169,13 @@ var CustomMap = /** @class */ (function (_super) {
140
169
  };
141
170
  CustomMap.prototype.getCallable = function (path) {
142
171
  var me = this;
143
- if (path.length === 0) {
144
- return Promise.resolve({
145
- origin: me.value,
146
- context: me
147
- });
148
- }
149
172
  var traversalPath = [].concat(path);
150
173
  var refs = me.value;
151
174
  var current = traversalPath.shift();
152
175
  if (current != null) {
153
176
  if (refs.has(current)) {
154
177
  var sub = refs.get(current);
155
- if (sub instanceof custom_type_1.CustomObjectType) {
178
+ if (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default) {
156
179
  return sub.getCallable(traversalPath);
157
180
  }
158
181
  if (traversalPath.length === 0) {
@@ -169,33 +192,13 @@ var CustomMap = /** @class */ (function (_super) {
169
192
  });
170
193
  }
171
194
  else {
172
- throw new Error("Cannot get path ".concat(path.join('.')));
195
+ throw new Error("Cannot get callable path ".concat(path.join('.')));
173
196
  }
174
197
  }
175
- return Promise.resolve(null);
176
- };
177
- CustomMap.prototype.callMethod = function (method) {
178
- var _a;
179
- var _b;
180
- var args = [];
181
- for (var _i = 1; _i < arguments.length; _i++) {
182
- args[_i - 1] = arguments[_i];
183
- }
184
- if (method.length === 0) {
185
- throw new Error('Unexpected method length');
186
- }
187
- var me = this;
188
- var key = (_b = method[0]) === null || _b === void 0 ? void 0 : _b.toString();
189
- if (method.length > 1) {
190
- if (me.value.has(key)) {
191
- return (_a = me.value.get(key)).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
192
- }
193
- throw new Error("Unexpected method path");
194
- }
195
- if (!CustomMap.intrinsics.has(key)) {
196
- throw new Error("Cannot access ".concat(key, " in map"));
197
- }
198
- return CustomMap.intrinsics.get(key).apply(void 0, __spreadArray([me], __read(args), false));
198
+ return Promise.resolve({
199
+ origin: null,
200
+ context: me
201
+ });
199
202
  };
200
203
  CustomMap.prototype.createInstance = function () {
201
204
  var me = this;
@@ -1,3 +1,4 @@
1
+ import { Callable } from '../types/custom-type';
1
2
  import { CustomLiteralType } from '../types/custom-type';
2
3
  export declare class CustomStringIterator implements Iterator<string> {
3
4
  value: string;
@@ -5,6 +6,7 @@ export declare class CustomStringIterator implements Iterator<string> {
5
6
  constructor(value: string);
6
7
  next(): IteratorResult<string>;
7
8
  }
9
+ export declare function itemAtIndex(str: any, n: number): number | null;
8
10
  export default class CustomString extends CustomLiteralType {
9
11
  static intrinsics: Map<string, Function>;
10
12
  value: string;
@@ -12,8 +14,8 @@ export default class CustomString extends CustomLiteralType {
12
14
  constructor(value: string);
13
15
  slice(a: CustomLiteralType, b: CustomLiteralType): CustomString;
14
16
  [Symbol.iterator](): CustomStringIterator;
15
- toIndex(value: string): number;
16
- callMethod(method: string[], ...args: any[]): any;
17
+ get(path: any[]): Promise<any>;
18
+ getCallable(path: any[]): Promise<Callable>;
17
19
  getType(): string;
18
20
  valueOf(): string | null;
19
21
  toString(): string;