greybel-interpreter 0.5.8 → 0.6.2

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
@@ -86,7 +86,6 @@ export declare class OperationContext {
86
86
  lookupAPI(): OperationContext;
87
87
  lookupGlobals(): OperationContext;
88
88
  lookupLocals(): OperationContext;
89
- valueOf(): CustomMap;
90
89
  extend(map: Map<string, any>): OperationContext;
91
90
  set(path: any[], value: any): Promise<void>;
92
91
  get(path: any[]): Promise<any>;
package/dist/context.js CHANGED
@@ -365,9 +365,6 @@ var OperationContext = /** @class */ (function () {
365
365
  OperationContext.prototype.lookupLocals = function () {
366
366
  return this.lookupType(function (type) { return [ContextType.GLOBAL, ContextType.FUNCTION].includes(type); });
367
367
  };
368
- OperationContext.prototype.valueOf = function () {
369
- return this.scope;
370
- };
371
368
  OperationContext.prototype.extend = function (map) {
372
369
  var _a;
373
370
  var me = this;
@@ -4,7 +4,9 @@ export default class CustomBoolean extends CustomLiteralType {
4
4
  value: boolean;
5
5
  constructor(value: boolean);
6
6
  getType(): string;
7
- valueOf(): boolean;
8
7
  toString(): string;
9
8
  fork(): CustomBoolean;
9
+ toNumber(): number;
10
+ toTruthy(): boolean;
11
+ valueOf(): boolean;
10
12
  }
@@ -26,15 +26,21 @@ var CustomBoolean = /** @class */ (function (_super) {
26
26
  CustomBoolean.prototype.getType = function () {
27
27
  return 'boolean';
28
28
  };
29
- CustomBoolean.prototype.valueOf = function () {
30
- return this.value;
31
- };
32
29
  CustomBoolean.prototype.toString = function () {
33
30
  return this.value.toString();
34
31
  };
35
32
  CustomBoolean.prototype.fork = function () {
36
33
  return new CustomBoolean(this.value);
37
34
  };
35
+ CustomBoolean.prototype.toNumber = function () {
36
+ return Number(this.value);
37
+ };
38
+ CustomBoolean.prototype.toTruthy = function () {
39
+ return this.value;
40
+ };
41
+ CustomBoolean.prototype.valueOf = function () {
42
+ return this.value;
43
+ };
38
44
  CustomBoolean.intrinsics = new Map();
39
45
  return CustomBoolean;
40
46
  }(custom_type_1.CustomLiteralType));
@@ -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,9 +17,10 @@ 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
- valueOf(): CustomList | null;
23
21
  toString(): string;
22
+ toNumber(): number;
23
+ toTruthy(): boolean;
24
+ valueOf(): any[];
24
25
  fork(): CustomList;
25
26
  }
@@ -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;
@@ -115,7 +96,7 @@ var CustomList = /** @class */ (function (_super) {
115
96
  function CustomList(value) {
116
97
  var _this = _super.call(this) || this;
117
98
  _this.slice = function (a, b) {
118
- return new CustomList(this.value.slice(a === null || a === void 0 ? void 0 : a.valueOf(), b === null || b === void 0 ? void 0 : b.valueOf()));
99
+ return new CustomList(this.value.slice(a.toNumber(), b.toNumber()));
119
100
  };
120
101
  _this.value = value;
121
102
  return _this;
@@ -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) {
@@ -204,7 +186,7 @@ var CustomList = /** @class */ (function (_super) {
204
186
  currentIndex = itemAtIndex(refs, Number(current));
205
187
  if (refs.hasOwnProperty(currentIndex)) {
206
188
  sub = refs[currentIndex];
207
- if (sub instanceof custom_type_1.CustomObjectType) {
189
+ if (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default) {
208
190
  return [2 /*return*/, sub.getCallable(traversalPath)];
209
191
  }
210
192
  if (traversalPath.length === 0) {
@@ -228,46 +210,23 @@ var CustomList = /** @class */ (function (_super) {
228
210
  });
229
211
  });
230
212
  };
231
- CustomList.prototype.callMethod = function (method) {
232
- var _a;
233
- var _b;
234
- var args = [];
235
- for (var _i = 1; _i < arguments.length; _i++) {
236
- args[_i - 1] = arguments[_i];
237
- }
238
- if (method.length === 0) {
239
- throw new Error('Unexpected method length');
240
- }
241
- var me = this;
242
- var member = (_b = method[0]) === null || _b === void 0 ? void 0 : _b.toString();
243
- if (CustomList.isNumber(member)) {
244
- var memberIndex = itemAtIndex(me.value, Number(member));
245
- if (!me.value.hasOwnProperty(memberIndex)) {
246
- return null;
247
- }
248
- if (method.length > 1) {
249
- return (_a = me.value[memberIndex]).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
250
- }
251
- return me.value[memberIndex];
252
- }
253
- if (!CustomList.intrinsics.has(member)) {
254
- throw new Error("Cannot access ".concat(member, " in list"));
255
- }
256
- return CustomList.intrinsics.get(member).apply(void 0, __spreadArray([me], __read(args), false));
257
- };
258
213
  CustomList.prototype.getType = function () {
259
214
  return 'list';
260
215
  };
261
- CustomList.prototype.valueOf = function () {
262
- var me = this;
263
- var value = me.value;
264
- return value.length === 0 ? null : me;
265
- };
266
216
  CustomList.prototype.toString = function () {
267
217
  var me = this;
268
- var body = me.value.map(function (item) { var _a; return (_a = item === null || item === void 0 ? void 0 : item.valueOf()) === null || _a === void 0 ? void 0 : _a.toString(); });
218
+ var body = me.value.map(function (item) { return item === null || item === void 0 ? void 0 : item.toString(); });
269
219
  return "[".concat(body.join(','), "]");
270
220
  };
221
+ CustomList.prototype.toNumber = function () {
222
+ return 0;
223
+ };
224
+ CustomList.prototype.toTruthy = function () {
225
+ return this.value.length > 0;
226
+ };
227
+ CustomList.prototype.valueOf = function () {
228
+ return this.value;
229
+ };
271
230
  CustomList.prototype.fork = function () {
272
231
  return new CustomList(this.value);
273
232
  };
@@ -20,10 +20,11 @@ export default class CustomMap extends CustomObjectType implements Iterable<Cust
20
20
  set(path: string[], value: any): Promise<void>;
21
21
  get(path: string[]): Promise<any>;
22
22
  getCallable(path: string[]): Promise<Callable>;
23
- callMethod(method: string[], ...args: any[]): any;
24
23
  createInstance(): CustomMap;
25
24
  getType(): string;
26
- valueOf(): CustomMap | null;
25
+ toNumber(): number;
26
+ toTruthy(): boolean;
27
27
  toString(): string;
28
+ valueOf(): Map<string, any>;
28
29
  fork(): CustomMap;
29
30
  }
@@ -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;
@@ -146,7 +150,8 @@ var CustomMap = /** @class */ (function (_super) {
146
150
  if (current != null) {
147
151
  if (refs.has(current)) {
148
152
  var sub = refs.get(current);
149
- 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)) {
150
155
  return sub.get(traversalPath);
151
156
  }
152
157
  if (traversalPath.length === 0) {
@@ -170,7 +175,7 @@ var CustomMap = /** @class */ (function (_super) {
170
175
  if (current != null) {
171
176
  if (refs.has(current)) {
172
177
  var sub = refs.get(current);
173
- if (sub instanceof custom_type_1.CustomObjectType) {
178
+ if (sub instanceof custom_type_1.CustomObjectType || sub instanceof string_1.default) {
174
179
  return sub.getCallable(traversalPath);
175
180
  }
176
181
  if (traversalPath.length === 0) {
@@ -195,29 +200,6 @@ var CustomMap = /** @class */ (function (_super) {
195
200
  context: me
196
201
  });
197
202
  };
198
- CustomMap.prototype.callMethod = function (method) {
199
- var _a;
200
- var _b;
201
- var args = [];
202
- for (var _i = 1; _i < arguments.length; _i++) {
203
- args[_i - 1] = arguments[_i];
204
- }
205
- if (method.length === 0) {
206
- throw new Error('Unexpected method length');
207
- }
208
- var me = this;
209
- var key = (_b = method[0]) === null || _b === void 0 ? void 0 : _b.toString();
210
- if (method.length > 1) {
211
- if (me.value.has(key)) {
212
- return (_a = me.value.get(key)).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
213
- }
214
- throw new Error("Unexpected method path");
215
- }
216
- if (!CustomMap.intrinsics.has(key)) {
217
- throw new Error("Cannot access ".concat(key, " in map"));
218
- }
219
- return CustomMap.intrinsics.get(key).apply(void 0, __spreadArray([me], __read(args), false));
220
- };
221
203
  CustomMap.prototype.createInstance = function () {
222
204
  var me = this;
223
205
  var newInstance = new CustomMap();
@@ -234,10 +216,11 @@ var CustomMap = /** @class */ (function (_super) {
234
216
  var me = this;
235
217
  return ((_a = me.value.get('classID')) === null || _a === void 0 ? void 0 : _a.toString()) || 'map';
236
218
  };
237
- CustomMap.prototype.valueOf = function () {
238
- var me = this;
239
- var value = me.value;
240
- return value.size === 0 ? null : me;
219
+ CustomMap.prototype.toNumber = function () {
220
+ return Number.NaN;
221
+ };
222
+ CustomMap.prototype.toTruthy = function () {
223
+ return this.value.size > 0;
241
224
  };
242
225
  CustomMap.prototype.toString = function () {
243
226
  var me = this;
@@ -245,10 +228,13 @@ var CustomMap = /** @class */ (function (_super) {
245
228
  .entries(me.value)
246
229
  .map(function (_a) {
247
230
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
248
- return "\"".concat(key, "\": ").concat(value.valueOf().toString());
231
+ return "\"".concat(key, "\": ").concat(value === null || value === void 0 ? void 0 : value.toString());
249
232
  });
250
233
  return "{".concat(body.join(','), "}");
251
234
  };
235
+ CustomMap.prototype.valueOf = function () {
236
+ return this.value;
237
+ };
252
238
  CustomMap.prototype.fork = function () {
253
239
  return new CustomMap(this.value);
254
240
  };
@@ -3,6 +3,8 @@ export default class CustomNil extends CustomLiteralType {
3
3
  static intrinsics: Map<string, Function>;
4
4
  value: null;
5
5
  getType(): string;
6
- valueOf(): null;
6
+ toNumber(): number;
7
+ toTruthy(): boolean;
7
8
  toString(): string;
9
+ valueOf(): any[];
8
10
  }
@@ -26,12 +26,18 @@ var CustomNil = /** @class */ (function (_super) {
26
26
  CustomNil.prototype.getType = function () {
27
27
  return 'null';
28
28
  };
29
- CustomNil.prototype.valueOf = function () {
30
- return null;
29
+ CustomNil.prototype.toNumber = function () {
30
+ return Number.NaN;
31
+ };
32
+ CustomNil.prototype.toTruthy = function () {
33
+ return false;
31
34
  };
32
35
  CustomNil.prototype.toString = function () {
33
36
  return 'null';
34
37
  };
38
+ CustomNil.prototype.valueOf = function () {
39
+ return null;
40
+ };
35
41
  CustomNil.intrinsics = new Map();
36
42
  return CustomNil;
37
43
  }(custom_type_1.CustomLiteralType));
@@ -4,7 +4,9 @@ export default class CustomNumber extends CustomLiteralType {
4
4
  value: number;
5
5
  constructor(value: number);
6
6
  getType(): string;
7
- valueOf(): number;
8
7
  toString(): string;
8
+ toNumber(): number;
9
+ toTruthy(): boolean;
10
+ valueOf(): number;
9
11
  fork(): CustomNumber;
10
12
  }
@@ -26,12 +26,18 @@ var CustomNumber = /** @class */ (function (_super) {
26
26
  CustomNumber.prototype.getType = function () {
27
27
  return 'number';
28
28
  };
29
- CustomNumber.prototype.valueOf = function () {
30
- return this.value;
31
- };
32
29
  CustomNumber.prototype.toString = function () {
33
30
  return this.value.toString();
34
31
  };
32
+ CustomNumber.prototype.toNumber = function () {
33
+ return this.value;
34
+ };
35
+ CustomNumber.prototype.toTruthy = function () {
36
+ return Number.isNaN(this.value) ? false : !!this.value;
37
+ };
38
+ CustomNumber.prototype.valueOf = function () {
39
+ return this.value;
40
+ };
35
41
  CustomNumber.prototype.fork = function () {
36
42
  return new CustomNumber(this.value);
37
43
  };
@@ -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,10 +14,12 @@ 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
- valueOf(): string | null;
19
20
  toString(): string;
21
+ toNumber(): number;
22
+ toTruthy(): boolean;
23
+ valueOf(): string;
20
24
  fork(): CustomString;
21
25
  }
@@ -14,33 +14,44 @@ 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 __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;
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
+ });
32
25
  };
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
- }
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 };
39
51
  }
40
- return to.concat(ar || Array.prototype.slice.call(from));
41
52
  };
42
53
  Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.CustomStringIterator = void 0;
54
+ exports.itemAtIndex = exports.CustomStringIterator = void 0;
44
55
  var custom_type_1 = require("../types/custom-type");
45
56
  var CustomStringIterator = /** @class */ (function () {
46
57
  function CustomStringIterator(value) {
@@ -64,6 +75,17 @@ var CustomStringIterator = /** @class */ (function () {
64
75
  return CustomStringIterator;
65
76
  }());
66
77
  exports.CustomStringIterator = CustomStringIterator;
78
+ function itemAtIndex(str, n) {
79
+ if (Number.isNaN(n))
80
+ return null;
81
+ n = Math.trunc(n) || 0;
82
+ if (n < 0)
83
+ n += str.length;
84
+ if (n < 0 || n >= str.length)
85
+ return -1;
86
+ return n;
87
+ }
88
+ exports.itemAtIndex = itemAtIndex;
67
89
  var CustomString = /** @class */ (function (_super) {
68
90
  __extends(CustomString, _super);
69
91
  function CustomString(value) {
@@ -75,53 +97,72 @@ var CustomString = /** @class */ (function (_super) {
75
97
  return !Number.isNaN(Number(value));
76
98
  };
77
99
  CustomString.prototype.slice = function (a, b) {
78
- return new CustomString(this.value.slice(a === null || a === void 0 ? void 0 : a.valueOf(), b === null || b === void 0 ? void 0 : b.valueOf()));
100
+ return new CustomString(this.value.slice(a === null || a === void 0 ? void 0 : a.toNumber(), b === null || b === void 0 ? void 0 : b.toNumber()));
79
101
  };
80
102
  CustomString.prototype[Symbol.iterator] = function () {
81
103
  return new CustomStringIterator(this.value);
82
104
  };
83
- CustomString.prototype.toIndex = function (value) {
84
- var me = this;
85
- var casted = Number(value);
86
- return casted < 0 ? me.value.length + casted : casted;
105
+ CustomString.prototype.get = function (path) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ var me, traversalPath, str, current, currentIndex;
108
+ return __generator(this, function (_a) {
109
+ me = this;
110
+ if (path.length === 0) {
111
+ return [2 /*return*/, me];
112
+ }
113
+ traversalPath = [].concat(path);
114
+ str = me.value;
115
+ current = traversalPath.shift();
116
+ if (current != null) {
117
+ currentIndex = itemAtIndex(str, Number(current));
118
+ if (currentIndex != null && str.charAt(currentIndex) != null) {
119
+ return [2 /*return*/, new CustomString(str.charAt(currentIndex))];
120
+ }
121
+ else if (path.length === 1 && CustomString.intrinsics.has(current)) {
122
+ return [2 /*return*/, CustomString.intrinsics.get(current).bind(null, me)];
123
+ }
124
+ }
125
+ return [2 /*return*/, null];
126
+ });
127
+ });
87
128
  };
88
- CustomString.prototype.callMethod = function (method) {
89
- var args = [];
90
- for (var _i = 1; _i < arguments.length; _i++) {
91
- args[_i - 1] = arguments[_i];
92
- }
93
- if (method.length === 0) {
94
- throw new Error('Unexpected method length');
95
- }
96
- var me = this;
97
- var member = method[0].valueOf();
98
- if (CustomString.isNumber(member)) {
99
- var index = me.toIndex(member);
100
- if (!me.value[index]) {
101
- console.error(method, member, args);
102
- throw new Error("Unexpected index ".concat(index));
103
- }
104
- var value = new CustomString(me.value[index]);
105
- if (method.length > 1) {
106
- return value.callMethod.apply(value, __spreadArray([method.slice(1)], __read(args), false));
107
- }
108
- return value;
109
- }
110
- if (!CustomString.intrinsics.has(member)) {
111
- throw new Error("Cannot access ".concat(member, " in string"));
112
- }
113
- return CustomString.intrinsics.get(member).apply(void 0, __spreadArray([me], __read(args), false));
129
+ CustomString.prototype.getCallable = function (path) {
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ var me, traversalPath, current;
132
+ return __generator(this, function (_a) {
133
+ me = this;
134
+ traversalPath = [].concat(path);
135
+ current = traversalPath.shift();
136
+ if (current != null) {
137
+ if (path.length === 1 && CustomString.intrinsics.has(current)) {
138
+ return [2 /*return*/, {
139
+ origin: CustomString.intrinsics.get(current).bind(null, me),
140
+ context: me
141
+ }];
142
+ }
143
+ }
144
+ return [2 /*return*/, {
145
+ origin: null,
146
+ context: me
147
+ }];
148
+ });
149
+ });
114
150
  };
115
151
  CustomString.prototype.getType = function () {
116
152
  return 'string';
117
153
  };
118
- CustomString.prototype.valueOf = function () {
119
- var me = this;
120
- return me.value.length === 0 ? null : me.value;
121
- };
122
154
  CustomString.prototype.toString = function () {
123
155
  return this.value;
124
156
  };
157
+ CustomString.prototype.toNumber = function () {
158
+ return Number(this.value);
159
+ };
160
+ CustomString.prototype.toTruthy = function () {
161
+ return this.value.length > 0;
162
+ };
163
+ CustomString.prototype.valueOf = function () {
164
+ return this.value;
165
+ };
125
166
  CustomString.prototype.fork = function () {
126
167
  return new CustomString(this.value);
127
168
  };
@@ -2,7 +2,6 @@ import { ASTUnaryExpression } from 'greybel-core';
2
2
  import { Expression } from '../types/expression';
3
3
  import { OperationContext } from '../context';
4
4
  import { CustomType } from '../types/custom-type';
5
- export declare const toPrimitive: (v: CustomType | any) => any;
6
5
  export declare type OperationMap = {
7
6
  [key: string]: (a: CustomType) => any;
8
7
  };
@@ -52,17 +52,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
52
52
  };
53
53
  var _a;
54
54
  Object.defineProperty(exports, "__esModule", { value: true });
55
- exports.ExpressionSegment = exports.toPrimitive = void 0;
55
+ exports.ExpressionSegment = void 0;
56
56
  var greybel_core_1 = require("greybel-core");
57
57
  var expression_1 = require("../types/expression");
58
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
59
  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); },
60
+ _a[greybel_core_1.Operator.Plus] = function (a) { return a.toNumber(); },
61
+ _a[greybel_core_1.Operator.Minus] = function (a) { return -a.toNumber(); },
66
62
  _a);
67
63
  var ExpressionSegment = /** @class */ (function () {
68
64
  function ExpressionSegment(operator, arg) {