greybel-interpreter 2.2.10 → 2.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.js +3 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -6
- package/dist/operations/evaluate.d.ts +0 -2
- package/dist/operations/evaluate.js +1 -19
- package/dist/utils/object-value.d.ts +1 -0
- package/dist/utils/object-value.js +9 -0
- package/package.json +1 -1
- package/dist/types/interface.d.ts +0 -27
- package/dist/types/interface.js +0 -89
package/dist/context.js
CHANGED
|
@@ -51,6 +51,9 @@ class Scope extends map_1.CustomMap {
|
|
|
51
51
|
if (this.has(path)) {
|
|
52
52
|
return super.get(path);
|
|
53
53
|
}
|
|
54
|
+
else if (this.context.globals.scope.has(path)) {
|
|
55
|
+
return this.context.globals.scope.get(path);
|
|
56
|
+
}
|
|
54
57
|
else if (this.context.api.scope.has(path)) {
|
|
55
58
|
return this.context.api.scope.get(path);
|
|
56
59
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { Call } from './operations/call';
|
|
|
12
12
|
export { Chunk } from './operations/chunk';
|
|
13
13
|
export { Continue } from './operations/continue';
|
|
14
14
|
export { DebuggerStatement } from './operations/debugger-statement';
|
|
15
|
-
export { Evaluate, GenericProcessorHandler, handle,
|
|
15
|
+
export { Evaluate, GenericProcessorHandler, handle, handleList, handleMap, handleNumber, handleString, ListProcessorHandler, MapProcessorHandler, NumberProcessorHandler, ProcessorHandler, ProcessorHandlerFunction, StringProcessorHandler } from './operations/evaluate';
|
|
16
16
|
export { For } from './operations/for';
|
|
17
17
|
export { FunctionOperation } from './operations/function';
|
|
18
18
|
export { Clause, IfStatement } from './operations/if-statement';
|
|
@@ -34,7 +34,6 @@ export { CustomValue } from './types/base';
|
|
|
34
34
|
export { CustomBoolean } from './types/boolean';
|
|
35
35
|
export { DefaultType } from './types/default';
|
|
36
36
|
export { Argument, Callback, CustomFunction } from './types/function';
|
|
37
|
-
export { CustomInterface, CustomInterfaceIterator } from './types/interface';
|
|
38
37
|
export { CustomList, CustomListIterator } from './types/list';
|
|
39
38
|
export { CustomMap, CustomMapIterator } from './types/map';
|
|
40
39
|
export { CustomNil } from './types/nil';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Not = exports.Noop = exports.NewInstance = exports.NegatedBinary = exports.MapOperation = exports.Literal = exports.List = exports.Include = exports.Import = exports.IfStatement = exports.Clause = exports.FunctionOperation = exports.For = exports.StringProcessorHandler = exports.NumberProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.handleString = exports.handleNumber = exports.handleMap = exports.handleList = exports.
|
|
4
|
-
exports.Path = exports.ObjectValue = exports.RuntimeError = exports.PrepareError = exports.deepEqual = exports.CustomValueWithIntrinsics = exports.CustomObject = exports.CustomStringIterator = exports.CustomString = exports.CustomNumber = exports.CustomNil = exports.CustomMapIterator = exports.CustomMap = exports.CustomListIterator = exports.CustomList = exports.
|
|
3
|
+
exports.Operation = exports.Not = exports.Noop = exports.NewInstance = exports.NegatedBinary = exports.MapOperation = exports.Literal = exports.List = exports.Include = exports.Import = exports.IfStatement = exports.Clause = exports.FunctionOperation = exports.For = exports.StringProcessorHandler = exports.NumberProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.handleString = exports.handleNumber = exports.handleMap = exports.handleList = exports.handle = exports.GenericProcessorHandler = exports.Evaluate = exports.DebuggerStatement = exports.Continue = exports.Chunk = exports.Call = exports.Break = exports.Block = exports.Assign = exports.Interpreter = exports.HandlerContainer = exports.ResourceHandler = exports.DefaultResourceHandler = exports.OutputHandler = exports.DefaultOutputHandler = exports.ErrorHandler = exports.DefaultErrorHandler = exports.CPSContext = exports.CPS = exports.Scope = exports.ProcessState = exports.OperationContext = exports.LoopState = exports.FunctionState = exports.Debugger = exports.ContextType = exports.ContextState = void 0;
|
|
4
|
+
exports.Path = exports.ObjectValue = exports.RuntimeError = exports.PrepareError = exports.deepEqual = exports.CustomValueWithIntrinsics = exports.CustomObject = exports.CustomStringIterator = exports.CustomString = exports.CustomNumber = exports.CustomNil = exports.CustomMapIterator = exports.CustomMap = exports.CustomListIterator = exports.CustomList = exports.CustomFunction = exports.Argument = exports.DefaultType = exports.CustomBoolean = exports.CustomValue = exports.While = exports.Return = exports.ResolveResult = exports.Resolve = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.Reference = void 0;
|
|
5
5
|
var context_1 = require("./context");
|
|
6
6
|
Object.defineProperty(exports, "ContextState", { enumerable: true, get: function () { return context_1.ContextState; } });
|
|
7
7
|
Object.defineProperty(exports, "ContextType", { enumerable: true, get: function () { return context_1.ContextType; } });
|
|
@@ -45,7 +45,6 @@ var evaluate_1 = require("./operations/evaluate");
|
|
|
45
45
|
Object.defineProperty(exports, "Evaluate", { enumerable: true, get: function () { return evaluate_1.Evaluate; } });
|
|
46
46
|
Object.defineProperty(exports, "GenericProcessorHandler", { enumerable: true, get: function () { return evaluate_1.GenericProcessorHandler; } });
|
|
47
47
|
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return evaluate_1.handle; } });
|
|
48
|
-
Object.defineProperty(exports, "handleInterface", { enumerable: true, get: function () { return evaluate_1.handleInterface; } });
|
|
49
48
|
Object.defineProperty(exports, "handleList", { enumerable: true, get: function () { return evaluate_1.handleList; } });
|
|
50
49
|
Object.defineProperty(exports, "handleMap", { enumerable: true, get: function () { return evaluate_1.handleMap; } });
|
|
51
50
|
Object.defineProperty(exports, "handleNumber", { enumerable: true, get: function () { return evaluate_1.handleNumber; } });
|
|
@@ -102,9 +101,6 @@ Object.defineProperty(exports, "DefaultType", { enumerable: true, get: function
|
|
|
102
101
|
var function_2 = require("./types/function");
|
|
103
102
|
Object.defineProperty(exports, "Argument", { enumerable: true, get: function () { return function_2.Argument; } });
|
|
104
103
|
Object.defineProperty(exports, "CustomFunction", { enumerable: true, get: function () { return function_2.CustomFunction; } });
|
|
105
|
-
var interface_1 = require("./types/interface");
|
|
106
|
-
Object.defineProperty(exports, "CustomInterface", { enumerable: true, get: function () { return interface_1.CustomInterface; } });
|
|
107
|
-
Object.defineProperty(exports, "CustomInterfaceIterator", { enumerable: true, get: function () { return interface_1.CustomInterfaceIterator; } });
|
|
108
104
|
var list_2 = require("./types/list");
|
|
109
105
|
Object.defineProperty(exports, "CustomList", { enumerable: true, get: function () { return list_2.CustomList; } });
|
|
110
106
|
Object.defineProperty(exports, "CustomListIterator", { enumerable: true, get: function () { return list_2.CustomListIterator; } });
|
|
@@ -22,14 +22,12 @@ export declare const multiplyList: (a: CustomList, b: CustomNumber) => CustomVal
|
|
|
22
22
|
export declare const divideList: (a: CustomList, b: CustomNumber) => CustomValue;
|
|
23
23
|
export declare const ListProcessorHandler: ProcessorHandler;
|
|
24
24
|
export declare const MapProcessorHandler: ProcessorHandler;
|
|
25
|
-
export declare const InterfaceProcessorHandler: ProcessorHandler;
|
|
26
25
|
export declare const NilProcessorHandler: ProcessorHandler;
|
|
27
26
|
export declare const FunctionProcessorHandler: ProcessorHandler;
|
|
28
27
|
export declare const handleNumber: ProcessorHandlerFunction;
|
|
29
28
|
export declare const handleString: ProcessorHandlerFunction;
|
|
30
29
|
export declare const handleList: ProcessorHandlerFunction;
|
|
31
30
|
export declare const handleMap: ProcessorHandlerFunction;
|
|
32
|
-
export declare const handleInterface: ProcessorHandlerFunction;
|
|
33
31
|
export declare const handleNil: ProcessorHandlerFunction;
|
|
34
32
|
export declare const handleFunction: ProcessorHandlerFunction;
|
|
35
33
|
export declare const handle: (op: string, a: CustomValue, b: CustomValue) => CustomValue;
|
|
@@ -9,12 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Evaluate = exports.handle = exports.handleFunction = exports.handleNil = exports.
|
|
12
|
+
exports.Evaluate = exports.handle = exports.handleFunction = exports.handleNil = exports.handleMap = exports.handleList = exports.handleString = exports.handleNumber = exports.FunctionProcessorHandler = exports.NilProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.divideList = exports.multiplyList = exports.StringProcessorHandler = exports.divideString = exports.multiplyString = exports.minusString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
|
|
13
13
|
const greyscript_core_1 = require("greyscript-core");
|
|
14
14
|
const boolean_1 = require("../types/boolean");
|
|
15
15
|
const default_1 = require("../types/default");
|
|
16
16
|
const function_1 = require("../types/function");
|
|
17
|
-
const interface_1 = require("../types/interface");
|
|
18
17
|
const list_1 = require("../types/list");
|
|
19
18
|
const map_1 = require("../types/map");
|
|
20
19
|
const nil_1 = require("../types/nil");
|
|
@@ -170,10 +169,6 @@ exports.MapProcessorHandler = {
|
|
|
170
169
|
return default_1.DefaultType.Void;
|
|
171
170
|
}
|
|
172
171
|
};
|
|
173
|
-
exports.InterfaceProcessorHandler = {
|
|
174
|
-
[greyscript_core_1.Operator.Equal]: (left, right) => new boolean_1.CustomBoolean(left.value === right.value),
|
|
175
|
-
[greyscript_core_1.Operator.NotEqual]: (left, right) => new boolean_1.CustomBoolean(left.value !== right.value)
|
|
176
|
-
};
|
|
177
172
|
exports.NilProcessorHandler = {
|
|
178
173
|
[greyscript_core_1.Operator.Plus]: () => default_1.DefaultType.Void,
|
|
179
174
|
[greyscript_core_1.Operator.Minus]: () => default_1.DefaultType.Void,
|
|
@@ -234,16 +229,6 @@ const handleMap = (op, a, b) => {
|
|
|
234
229
|
return default_1.DefaultType.Void;
|
|
235
230
|
};
|
|
236
231
|
exports.handleMap = handleMap;
|
|
237
|
-
const handleInterface = (op, a, b) => {
|
|
238
|
-
if (op in exports.InterfaceProcessorHandler) {
|
|
239
|
-
return exports.InterfaceProcessorHandler[op](a, b);
|
|
240
|
-
}
|
|
241
|
-
else if (op in exports.GenericProcessorHandler) {
|
|
242
|
-
return exports.GenericProcessorHandler[op](a, b);
|
|
243
|
-
}
|
|
244
|
-
return default_1.DefaultType.Void;
|
|
245
|
-
};
|
|
246
|
-
exports.handleInterface = handleInterface;
|
|
247
232
|
const handleNil = (op, a, b) => {
|
|
248
233
|
if (op in exports.NilProcessorHandler) {
|
|
249
234
|
return exports.NilProcessorHandler[op](a, b);
|
|
@@ -294,9 +279,6 @@ const handle = (op, a, b) => {
|
|
|
294
279
|
else if (a instanceof map_1.CustomMap) {
|
|
295
280
|
return (0, exports.handleMap)(op, a, b);
|
|
296
281
|
}
|
|
297
|
-
else if (a instanceof interface_1.CustomInterface) {
|
|
298
|
-
return (0, exports.handleInterface)(op, a, b);
|
|
299
|
-
}
|
|
300
282
|
else if (a instanceof function_1.CustomFunction) {
|
|
301
283
|
return (0, exports.handleFunction)(op, a, b);
|
|
302
284
|
}
|
|
@@ -3,5 +3,6 @@ export declare class ObjectValue extends Map<CustomValue, CustomValue> {
|
|
|
3
3
|
get(mapKey: CustomValue): CustomValue;
|
|
4
4
|
has(mapKey: CustomValue): boolean;
|
|
5
5
|
set(mapKey: CustomValue, mapValue: CustomValue): this;
|
|
6
|
+
delete(mapKey: CustomValue): boolean;
|
|
6
7
|
extend(objVal: ObjectValue): this;
|
|
7
8
|
}
|
|
@@ -30,6 +30,15 @@ class ObjectValue extends Map {
|
|
|
30
30
|
super.set(mapKey, mapValue);
|
|
31
31
|
return this;
|
|
32
32
|
}
|
|
33
|
+
delete(mapKey) {
|
|
34
|
+
for (const key of this.keys()) {
|
|
35
|
+
if ((0, deep_equal_1.deepEqual)(key, mapKey)) {
|
|
36
|
+
super.delete(key);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
33
42
|
extend(objVal) {
|
|
34
43
|
for (const [key, value] of objVal) {
|
|
35
44
|
this.set(key, value);
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Path } from '../utils/path';
|
|
2
|
-
import { CustomValue } from './base';
|
|
3
|
-
import { CustomFunction } from './function';
|
|
4
|
-
import { CustomObject } from './with-intrinsics';
|
|
5
|
-
export declare class CustomInterfaceIterator implements Iterator<CustomValue> {
|
|
6
|
-
index: number;
|
|
7
|
-
next(): IteratorResult<CustomValue>;
|
|
8
|
-
}
|
|
9
|
-
export declare class CustomInterface extends CustomObject {
|
|
10
|
-
private readonly interfaceFns;
|
|
11
|
-
private readonly type;
|
|
12
|
-
readonly value: Object;
|
|
13
|
-
constructor(type: string);
|
|
14
|
-
getCustomType(): string;
|
|
15
|
-
toJSON(): string;
|
|
16
|
-
toString(): string;
|
|
17
|
-
fork(): CustomInterface;
|
|
18
|
-
toNumber(): number;
|
|
19
|
-
toInt(): number;
|
|
20
|
-
toTruthy(): boolean;
|
|
21
|
-
instanceOf(v: CustomValue): boolean;
|
|
22
|
-
[Symbol.iterator](): CustomInterfaceIterator;
|
|
23
|
-
has(path: Path<CustomValue> | CustomValue): boolean;
|
|
24
|
-
set(_path: Path<CustomValue> | CustomValue, _newValue: CustomValue): void;
|
|
25
|
-
get(path: Path<CustomValue> | CustomValue): CustomValue;
|
|
26
|
-
addFunction(name: string, fn: CustomFunction): CustomInterface;
|
|
27
|
-
}
|
package/dist/types/interface.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomInterface = exports.CustomInterfaceIterator = void 0;
|
|
4
|
-
const path_1 = require("../utils/path");
|
|
5
|
-
const base_1 = require("./base");
|
|
6
|
-
const default_1 = require("./default");
|
|
7
|
-
const with_intrinsics_1 = require("./with-intrinsics");
|
|
8
|
-
class CustomInterfaceIterator {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.index = 0;
|
|
11
|
-
}
|
|
12
|
-
next() {
|
|
13
|
-
return {
|
|
14
|
-
value: default_1.DefaultType.Void,
|
|
15
|
-
done: true
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.CustomInterfaceIterator = CustomInterfaceIterator;
|
|
20
|
-
class CustomInterface extends with_intrinsics_1.CustomObject {
|
|
21
|
-
constructor(type) {
|
|
22
|
-
super();
|
|
23
|
-
this.value = {};
|
|
24
|
-
this.type = type;
|
|
25
|
-
this.interfaceFns = new Map();
|
|
26
|
-
}
|
|
27
|
-
getCustomType() {
|
|
28
|
-
return this.type;
|
|
29
|
-
}
|
|
30
|
-
toJSON() {
|
|
31
|
-
return this.toString();
|
|
32
|
-
}
|
|
33
|
-
toString() {
|
|
34
|
-
return this.type;
|
|
35
|
-
}
|
|
36
|
-
fork() {
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
toNumber() {
|
|
40
|
-
return Number.NaN;
|
|
41
|
-
}
|
|
42
|
-
toInt() {
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
toTruthy() {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
instanceOf(v) {
|
|
49
|
-
return (v instanceof CustomInterface && v.getCustomType() === this.getCustomType());
|
|
50
|
-
}
|
|
51
|
-
[Symbol.iterator]() {
|
|
52
|
-
return new CustomInterfaceIterator();
|
|
53
|
-
}
|
|
54
|
-
has(path) {
|
|
55
|
-
if (path instanceof base_1.CustomValue) {
|
|
56
|
-
return this.has(new path_1.Path([path]));
|
|
57
|
-
}
|
|
58
|
-
const traversalPath = path.clone();
|
|
59
|
-
const current = traversalPath.next();
|
|
60
|
-
if (current !== null) {
|
|
61
|
-
return this.interfaceFns.has(current.toString());
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
set(_path, _newValue) {
|
|
66
|
-
throw new Error('Cannot set property on an interface.');
|
|
67
|
-
}
|
|
68
|
-
get(path) {
|
|
69
|
-
if (path instanceof base_1.CustomValue) {
|
|
70
|
-
return this.get(new path_1.Path([path]));
|
|
71
|
-
}
|
|
72
|
-
if (path.count() === 0) {
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
const traversalPath = path.clone();
|
|
76
|
-
const current = traversalPath.next();
|
|
77
|
-
if (current !== null) {
|
|
78
|
-
if (this.interfaceFns.has(current.toString())) {
|
|
79
|
-
return this.interfaceFns.get(current.toString());
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
throw new Error(`Unknown path in interface ${path.toString()}.`);
|
|
83
|
-
}
|
|
84
|
-
addFunction(name, fn) {
|
|
85
|
-
this.interfaceFns.set(name, fn);
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.CustomInterface = CustomInterface;
|