affinirum 1.5.3 → 1.5.4
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/dst/Affinirum.js +8 -7
- package/dst/LexicalScope.d.ts +5 -3
- package/dst/LexicalScope.js +9 -5
- package/dst/cjs/Affinirum.d.ts +88 -0
- package/dst/cjs/Affinirum.js +8 -7
- package/dst/cjs/Atom.d.ts +7 -0
- package/dst/cjs/CallFrame.d.ts +11 -0
- package/dst/cjs/Constant.d.ts +13 -0
- package/dst/cjs/Constants.d.ts +2 -0
- package/dst/cjs/Functions.d.ts +2 -0
- package/dst/cjs/Jump.d.ts +1 -0
- package/dst/cjs/JumpException.d.ts +9 -0
- package/dst/cjs/Keywords.d.ts +1 -0
- package/dst/cjs/LexicalScope.d.ts +15 -0
- package/dst/cjs/LexicalScope.js +9 -5
- package/dst/cjs/Node.d.ts +14 -0
- package/dst/cjs/ParserState.d.ts +60 -0
- package/dst/cjs/ScriptSpan.d.ts +10 -0
- package/dst/cjs/Type.d.ts +71 -0
- package/dst/cjs/Value.d.ts +5 -0
- package/dst/cjs/Variable.d.ts +9 -0
- package/dst/cjs/atom/ArrayAtom.d.ts +16 -0
- package/dst/cjs/atom/FunctionAtom.d.ts +22 -0
- package/dst/cjs/atom/ObjectAtom.d.ts +14 -0
- package/dst/cjs/atom/PrimitiveAtom.d.ts +12 -0
- package/dst/cjs/index.d.ts +3 -0
- package/dst/cjs/native/Aggregable.d.ts +4 -0
- package/dst/cjs/native/Array.d.ts +16 -0
- package/dst/cjs/native/Boolean.d.ts +6 -0
- package/dst/cjs/native/Buffer.d.ts +13 -0
- package/dst/cjs/native/Buffer.js +1 -1
- package/dst/cjs/native/Enumerable.d.ts +4 -0
- package/dst/cjs/native/Float.d.ts +5 -0
- package/dst/cjs/native/Integer.d.ts +7 -0
- package/dst/cjs/native/Iterable.d.ts +5 -0
- package/dst/cjs/native/Number.d.ts +26 -0
- package/dst/cjs/native/Number.js +1 -1
- package/dst/cjs/native/Object.d.ts +5 -0
- package/dst/cjs/native/String.d.ts +28 -0
- package/dst/cjs/native/String.js +97 -48
- package/dst/cjs/native/Timestamp.d.ts +22 -0
- package/dst/cjs/native/Unknown.d.ts +14 -0
- package/dst/cjs/native/Unknown.js +10 -1
- package/dst/cjs/native/notation/AN.d.ts +4 -0
- package/dst/cjs/native/notation/IP.d.ts +1 -0
- package/dst/cjs/native/notation/JSON.d.ts +3 -0
- package/dst/cjs/node/ArrayNode.d.ts +14 -0
- package/dst/cjs/node/BlockNode.d.ts +15 -0
- package/dst/cjs/node/CallNode.d.ts +15 -0
- package/dst/cjs/node/CastNode.d.ts +16 -0
- package/dst/cjs/node/ConstantNode.d.ts +17 -0
- package/dst/cjs/node/JumpNode.d.ts +16 -0
- package/dst/cjs/node/JumpNode.js +7 -3
- package/dst/cjs/node/LoopNode.d.ts +14 -0
- package/dst/cjs/node/ObjectNode.d.ts +14 -0
- package/dst/cjs/node/SwitchNode.d.ts +15 -0
- package/dst/cjs/node/VariableNode.d.ts +15 -0
- package/dst/cjs/node/VariadicNode.d.ts +4 -0
- package/dst/native/Buffer.js +1 -1
- package/dst/native/Number.js +1 -1
- package/dst/native/String.js +97 -48
- package/dst/native/Unknown.js +10 -1
- package/dst/node/JumpNode.d.ts +2 -1
- package/dst/node/JumpNode.js +7 -3
- package/package.json +1 -1
package/dst/Affinirum.js
CHANGED
|
@@ -35,7 +35,7 @@ export class Affinirum {
|
|
|
35
35
|
_variables = new Map();
|
|
36
36
|
_constants = new Map(Constants);
|
|
37
37
|
_functions = new Map(Functions);
|
|
38
|
-
_scope
|
|
38
|
+
_scope;
|
|
39
39
|
/**
|
|
40
40
|
Creates compiled expression. Any parsed token not recognized as a constant or a function will be compiled as a variable.
|
|
41
41
|
@param script Math expression to compile.
|
|
@@ -45,6 +45,7 @@ export class Affinirum {
|
|
|
45
45
|
*/
|
|
46
46
|
constructor(script, config) {
|
|
47
47
|
this._script = script;
|
|
48
|
+
this._scope = new LexicalScope(undefined, undefined, config?.type ?? Type.Unknown);
|
|
48
49
|
this._strict = config?.strict ?? false;
|
|
49
50
|
if (config?.variables) {
|
|
50
51
|
for (const [vname, vtype] of Object.entries(config.variables)) {
|
|
@@ -56,7 +57,7 @@ export class Affinirum {
|
|
|
56
57
|
if (!state.isEmpty) {
|
|
57
58
|
state.throwError("unexpected expression token or expression end");
|
|
58
59
|
}
|
|
59
|
-
this._root = this._root.compile(
|
|
60
|
+
this._root = this._root.compile(this._scope.type());
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
62
63
|
Returns original script text.
|
|
@@ -453,10 +454,10 @@ export class Affinirum {
|
|
|
453
454
|
return this._loop(state, scope);
|
|
454
455
|
}
|
|
455
456
|
else if (state.isExit) {
|
|
456
|
-
return new JumpNode(state, "exit", this._unit(state.next(), scope));
|
|
457
|
+
return new JumpNode(state, "exit", this._unit(state.next(), scope), this._scope.type());
|
|
457
458
|
}
|
|
458
459
|
else if (state.isReturn) {
|
|
459
|
-
return new JumpNode(state, "return", this._unit(state.next(), scope));
|
|
460
|
+
return new JumpNode(state, "return", this._unit(state.next(), scope), scope.type());
|
|
460
461
|
}
|
|
461
462
|
else if (state.isStop) {
|
|
462
463
|
const node = new JumpNode(state, "stop");
|
|
@@ -511,10 +512,10 @@ export class Affinirum {
|
|
|
511
512
|
}
|
|
512
513
|
}
|
|
513
514
|
state.closeParentheses().next();
|
|
514
|
-
const
|
|
515
|
+
const returnType = state.isColon ? this._type(state.next(), scope) : Type.Unknown;
|
|
515
516
|
span.end(state);
|
|
516
517
|
const args = Array.from(variables.values());
|
|
517
|
-
const subscope = scope.subscope(variables);
|
|
518
|
+
const subscope = scope.subscope(variables, returnType);
|
|
518
519
|
const subnode = this._unit(state, subscope);
|
|
519
520
|
const createFunction = (frame) => (...values) => {
|
|
520
521
|
const subframe = frame.subframe(subscope.variables());
|
|
@@ -534,7 +535,7 @@ export class Affinirum {
|
|
|
534
535
|
throw e;
|
|
535
536
|
}
|
|
536
537
|
};
|
|
537
|
-
const constant = new Constant(createFunction, Type.functionType(
|
|
538
|
+
const constant = new Constant(createFunction, Type.functionType(returnType, args.map((v) => v.type), variadic));
|
|
538
539
|
return new ConstantNode(span, constant, subnode, createFunction);
|
|
539
540
|
}
|
|
540
541
|
_loop(state, scope) {
|
package/dst/LexicalScope.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
1
2
|
import { Variable } from "./Variable.js";
|
|
2
3
|
export declare class LexicalScope {
|
|
3
4
|
protected readonly _superscope?: LexicalScope;
|
|
4
5
|
protected readonly _subscopes: LexicalScope[];
|
|
5
6
|
protected readonly _variables: Map<string, Variable>;
|
|
6
|
-
protected readonly
|
|
7
|
-
constructor(superscope?: LexicalScope, variables?: Map<string, Variable
|
|
7
|
+
protected readonly _type: Type | undefined;
|
|
8
|
+
constructor(superscope?: LexicalScope, variables?: Map<string, Variable>, type?: Type);
|
|
8
9
|
has(name: string): boolean;
|
|
9
10
|
get(name: string): Variable | undefined;
|
|
10
11
|
set(name: string, variable: Variable): void;
|
|
11
|
-
subscope(variables?: Map<string, Variable
|
|
12
|
+
subscope(variables?: Map<string, Variable>, type?: Type): LexicalScope;
|
|
12
13
|
variables(): IterableIterator<Variable>;
|
|
14
|
+
type(): Type;
|
|
13
15
|
}
|
package/dst/LexicalScope.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
1
2
|
export class LexicalScope {
|
|
2
3
|
_superscope;
|
|
3
4
|
_subscopes = [];
|
|
4
5
|
_variables;
|
|
5
|
-
|
|
6
|
-
constructor(superscope, variables) {
|
|
6
|
+
_type;
|
|
7
|
+
constructor(superscope, variables, type) {
|
|
7
8
|
superscope?._subscopes.push(this);
|
|
8
9
|
this._superscope = superscope;
|
|
9
10
|
this._variables = variables ?? new Map();
|
|
10
|
-
this.
|
|
11
|
+
this._type = type;
|
|
11
12
|
}
|
|
12
13
|
has(name) {
|
|
13
14
|
return this._variables.has(name) || Boolean(this._superscope?.has(name));
|
|
@@ -18,10 +19,13 @@ export class LexicalScope {
|
|
|
18
19
|
set(name, variable) {
|
|
19
20
|
this._variables.set(name, variable);
|
|
20
21
|
}
|
|
21
|
-
subscope(variables) {
|
|
22
|
-
return new LexicalScope(this, variables);
|
|
22
|
+
subscope(variables, type) {
|
|
23
|
+
return new LexicalScope(this, variables, type);
|
|
23
24
|
}
|
|
24
25
|
variables() {
|
|
25
26
|
return this._variables.values();
|
|
26
27
|
}
|
|
28
|
+
type() {
|
|
29
|
+
return this._type ?? this._superscope?.type() ?? Type.Unknown;
|
|
30
|
+
}
|
|
27
31
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Constant } from "./Constant.js";
|
|
2
|
+
import { Variable } from "./Variable.js";
|
|
3
|
+
import { Value } from "./Value.js";
|
|
4
|
+
import { Type } from "./Type.js";
|
|
5
|
+
import { Node } from "./Node.js";
|
|
6
|
+
import { LoopNode } from "./node/LoopNode.js";
|
|
7
|
+
import { SwitchNode } from "./node/SwitchNode.js";
|
|
8
|
+
import { ScriptSpan } from "./ScriptSpan.js";
|
|
9
|
+
import { ParserState } from "./ParserState.js";
|
|
10
|
+
import { LexicalScope } from "./LexicalScope.js";
|
|
11
|
+
export declare class Affinirum {
|
|
12
|
+
static readonly keywords: string[];
|
|
13
|
+
protected readonly _script: string;
|
|
14
|
+
protected readonly _strict: boolean;
|
|
15
|
+
protected readonly _root: Node;
|
|
16
|
+
protected readonly _vartypes: Map<string, Type>;
|
|
17
|
+
protected readonly _varspans: Map<string, ScriptSpan>;
|
|
18
|
+
protected readonly _variables: Map<string, Variable>;
|
|
19
|
+
protected readonly _constants: Map<string, Record<string, Constant>>;
|
|
20
|
+
protected readonly _functions: Map<string, Constant>;
|
|
21
|
+
protected readonly _scope: LexicalScope;
|
|
22
|
+
/**
|
|
23
|
+
Creates compiled expression. Any parsed token not recognized as a constant or a function will be compiled as a variable.
|
|
24
|
+
@param script Math expression to compile.
|
|
25
|
+
@param config Optional expected type, strict mode, variable types, constant values and functions to add for the compilation.
|
|
26
|
+
If expected type is provided then expression return type is matched against it.
|
|
27
|
+
If strict mode is set then undeclared variables will not be allowed in expression.
|
|
28
|
+
*/
|
|
29
|
+
constructor(script: string, config?: {
|
|
30
|
+
type?: Type;
|
|
31
|
+
strict?: boolean;
|
|
32
|
+
variables?: Record<string, Type>;
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
Returns original script text.
|
|
36
|
+
*/
|
|
37
|
+
get script(): String;
|
|
38
|
+
/**
|
|
39
|
+
Returns compiled expression return value type.
|
|
40
|
+
*/
|
|
41
|
+
get type(): Type;
|
|
42
|
+
/**
|
|
43
|
+
Returns string representing parsed node tree structure.
|
|
44
|
+
@returns Parsed expression string.
|
|
45
|
+
*/
|
|
46
|
+
toString(): string;
|
|
47
|
+
/**
|
|
48
|
+
Returns record with compiled variable names and expected types.
|
|
49
|
+
@returns Record with variable names and types.
|
|
50
|
+
*/
|
|
51
|
+
variables(): Record<string, Type>;
|
|
52
|
+
/**
|
|
53
|
+
Evaluates the compiled expression using the provided input values.
|
|
54
|
+
@param values Values for the expression's input variables. Omitted when there are no input variables.
|
|
55
|
+
@returns The evaluated result.
|
|
56
|
+
@throws If an input value is missing or evaluation fails.
|
|
57
|
+
*/
|
|
58
|
+
evaluate(values?: Record<string, Value>): Value;
|
|
59
|
+
/** Parses an Affinirum Notation string into a JavaScript value.
|
|
60
|
+
@param value Affinirum Notation string to parse.
|
|
61
|
+
@returns The parsed value.
|
|
62
|
+
@throws If string is not a valid Affinirum Notation string.
|
|
63
|
+
*/
|
|
64
|
+
static parse(value: string | undefined): Value;
|
|
65
|
+
/** Formats a JavaScript value as an Affinirum Notation string.
|
|
66
|
+
@param value Value to format. Null and undefined are formatted as the AN literal null.
|
|
67
|
+
@param whitespace Optional whitespace used for each indentation level.
|
|
68
|
+
@returns Affinirum Notation formatted string.
|
|
69
|
+
*/
|
|
70
|
+
static format(value: Value, whitespace?: string): string;
|
|
71
|
+
protected _list(state: ParserState, scope: LexicalScope): Node;
|
|
72
|
+
protected _unit(state: ParserState, scope: LexicalScope): Node;
|
|
73
|
+
protected _coalescence(state: ParserState, scope: LexicalScope): Node;
|
|
74
|
+
protected _disjunction(state: ParserState, scope: LexicalScope): Node;
|
|
75
|
+
protected _conjunction(state: ParserState, scope: LexicalScope): Node;
|
|
76
|
+
protected _negation(state: ParserState, scope: LexicalScope): Node;
|
|
77
|
+
protected _comparison(state: ParserState, scope: LexicalScope): Node;
|
|
78
|
+
protected _aggregate(state: ParserState, scope: LexicalScope): Node;
|
|
79
|
+
protected _product(state: ParserState, scope: LexicalScope): Node;
|
|
80
|
+
protected _signum(state: ParserState, scope: LexicalScope): Node;
|
|
81
|
+
protected _factor(state: ParserState, scope: LexicalScope): Node;
|
|
82
|
+
protected _accessor(state: ParserState, scope: LexicalScope): Node;
|
|
83
|
+
protected _term(state: ParserState, scope: LexicalScope): Node;
|
|
84
|
+
protected _function(state: ParserState, scope: LexicalScope): Node;
|
|
85
|
+
protected _loop(state: ParserState, scope: LexicalScope): LoopNode;
|
|
86
|
+
protected _switch(state: ParserState, scope: LexicalScope): SwitchNode;
|
|
87
|
+
protected _type(state: ParserState, scope: LexicalScope): Type;
|
|
88
|
+
}
|
package/dst/cjs/Affinirum.js
CHANGED
|
@@ -38,7 +38,7 @@ class Affinirum {
|
|
|
38
38
|
_variables = new Map();
|
|
39
39
|
_constants = new Map(Constants_js_1.Constants);
|
|
40
40
|
_functions = new Map(Functions_js_1.Functions);
|
|
41
|
-
_scope
|
|
41
|
+
_scope;
|
|
42
42
|
/**
|
|
43
43
|
Creates compiled expression. Any parsed token not recognized as a constant or a function will be compiled as a variable.
|
|
44
44
|
@param script Math expression to compile.
|
|
@@ -48,6 +48,7 @@ class Affinirum {
|
|
|
48
48
|
*/
|
|
49
49
|
constructor(script, config) {
|
|
50
50
|
this._script = script;
|
|
51
|
+
this._scope = new LexicalScope_js_1.LexicalScope(undefined, undefined, config?.type ?? Type_js_1.Type.Unknown);
|
|
51
52
|
this._strict = config?.strict ?? false;
|
|
52
53
|
if (config?.variables) {
|
|
53
54
|
for (const [vname, vtype] of Object.entries(config.variables)) {
|
|
@@ -59,7 +60,7 @@ class Affinirum {
|
|
|
59
60
|
if (!state.isEmpty) {
|
|
60
61
|
state.throwError("unexpected expression token or expression end");
|
|
61
62
|
}
|
|
62
|
-
this._root = this._root.compile(
|
|
63
|
+
this._root = this._root.compile(this._scope.type());
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
Returns original script text.
|
|
@@ -456,10 +457,10 @@ class Affinirum {
|
|
|
456
457
|
return this._loop(state, scope);
|
|
457
458
|
}
|
|
458
459
|
else if (state.isExit) {
|
|
459
|
-
return new JumpNode_js_1.JumpNode(state, "exit", this._unit(state.next(), scope));
|
|
460
|
+
return new JumpNode_js_1.JumpNode(state, "exit", this._unit(state.next(), scope), this._scope.type());
|
|
460
461
|
}
|
|
461
462
|
else if (state.isReturn) {
|
|
462
|
-
return new JumpNode_js_1.JumpNode(state, "return", this._unit(state.next(), scope));
|
|
463
|
+
return new JumpNode_js_1.JumpNode(state, "return", this._unit(state.next(), scope), scope.type());
|
|
463
464
|
}
|
|
464
465
|
else if (state.isStop) {
|
|
465
466
|
const node = new JumpNode_js_1.JumpNode(state, "stop");
|
|
@@ -514,10 +515,10 @@ class Affinirum {
|
|
|
514
515
|
}
|
|
515
516
|
}
|
|
516
517
|
state.closeParentheses().next();
|
|
517
|
-
const
|
|
518
|
+
const returnType = state.isColon ? this._type(state.next(), scope) : Type_js_1.Type.Unknown;
|
|
518
519
|
span.end(state);
|
|
519
520
|
const args = Array.from(variables.values());
|
|
520
|
-
const subscope = scope.subscope(variables);
|
|
521
|
+
const subscope = scope.subscope(variables, returnType);
|
|
521
522
|
const subnode = this._unit(state, subscope);
|
|
522
523
|
const createFunction = (frame) => (...values) => {
|
|
523
524
|
const subframe = frame.subframe(subscope.variables());
|
|
@@ -537,7 +538,7 @@ class Affinirum {
|
|
|
537
538
|
throw e;
|
|
538
539
|
}
|
|
539
540
|
};
|
|
540
|
-
const constant = new Constant_js_1.Constant(createFunction, Type_js_1.Type.functionType(
|
|
541
|
+
const constant = new Constant_js_1.Constant(createFunction, Type_js_1.Type.functionType(returnType, args.map((v) => v.type), variadic));
|
|
541
542
|
return new ConstantNode_js_1.ConstantNode(span, constant, subnode, createFunction);
|
|
542
543
|
}
|
|
543
544
|
_loop(state, scope) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Value } from "./Value.js";
|
|
2
|
+
import type { Variable } from "./Variable.js";
|
|
3
|
+
export declare class CallFrame {
|
|
4
|
+
protected readonly _superframe?: CallFrame;
|
|
5
|
+
protected readonly _values: Map<Variable, Value>;
|
|
6
|
+
constructor(superframe?: CallFrame, variables?: Iterable<Variable>);
|
|
7
|
+
subframe(variables: Iterable<Variable>): CallFrame;
|
|
8
|
+
add(variable: Variable, value?: Value): void;
|
|
9
|
+
get(variable: Variable): Value;
|
|
10
|
+
set(variable: Variable, value: Value): Value;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Value } from "./Value.js";
|
|
2
|
+
import { Type } from "./Type.js";
|
|
3
|
+
export declare class Constant {
|
|
4
|
+
protected readonly _value: Value;
|
|
5
|
+
protected _type: Type;
|
|
6
|
+
protected readonly _deterministic: boolean;
|
|
7
|
+
constructor(_value: Value, _type?: Type, _deterministic?: boolean);
|
|
8
|
+
get value(): Value;
|
|
9
|
+
get type(): Type;
|
|
10
|
+
set type(type: Type);
|
|
11
|
+
get deterministic(): boolean;
|
|
12
|
+
static Null: Constant;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Jump = "exit" | "return" | "stop" | "next";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Keywords: string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
2
|
+
import { Variable } from "./Variable.js";
|
|
3
|
+
export declare class LexicalScope {
|
|
4
|
+
protected readonly _superscope?: LexicalScope;
|
|
5
|
+
protected readonly _subscopes: LexicalScope[];
|
|
6
|
+
protected readonly _variables: Map<string, Variable>;
|
|
7
|
+
protected readonly _type: Type | undefined;
|
|
8
|
+
constructor(superscope?: LexicalScope, variables?: Map<string, Variable>, type?: Type);
|
|
9
|
+
has(name: string): boolean;
|
|
10
|
+
get(name: string): Variable | undefined;
|
|
11
|
+
set(name: string, variable: Variable): void;
|
|
12
|
+
subscope(variables?: Map<string, Variable>, type?: Type): LexicalScope;
|
|
13
|
+
variables(): IterableIterator<Variable>;
|
|
14
|
+
type(): Type;
|
|
15
|
+
}
|
package/dst/cjs/LexicalScope.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LexicalScope = void 0;
|
|
4
|
+
const Type_js_1 = require("./Type.js");
|
|
4
5
|
class LexicalScope {
|
|
5
6
|
_superscope;
|
|
6
7
|
_subscopes = [];
|
|
7
8
|
_variables;
|
|
8
|
-
|
|
9
|
-
constructor(superscope, variables) {
|
|
9
|
+
_type;
|
|
10
|
+
constructor(superscope, variables, type) {
|
|
10
11
|
superscope?._subscopes.push(this);
|
|
11
12
|
this._superscope = superscope;
|
|
12
13
|
this._variables = variables ?? new Map();
|
|
13
|
-
this.
|
|
14
|
+
this._type = type;
|
|
14
15
|
}
|
|
15
16
|
has(name) {
|
|
16
17
|
return this._variables.has(name) || Boolean(this._superscope?.has(name));
|
|
@@ -21,11 +22,14 @@ class LexicalScope {
|
|
|
21
22
|
set(name, variable) {
|
|
22
23
|
this._variables.set(name, variable);
|
|
23
24
|
}
|
|
24
|
-
subscope(variables) {
|
|
25
|
-
return new LexicalScope(this, variables);
|
|
25
|
+
subscope(variables, type) {
|
|
26
|
+
return new LexicalScope(this, variables, type);
|
|
26
27
|
}
|
|
27
28
|
variables() {
|
|
28
29
|
return this._variables.values();
|
|
29
30
|
}
|
|
31
|
+
type() {
|
|
32
|
+
return this._type ?? this._superscope?.type() ?? Type_js_1.Type.Unknown;
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
exports.LexicalScope = LexicalScope;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ScriptSpan } from "./ScriptSpan.js";
|
|
2
|
+
import { Type } from "./Type.js";
|
|
3
|
+
import { Value } from "./Value.js";
|
|
4
|
+
import { CallFrame } from "./CallFrame.js";
|
|
5
|
+
export declare abstract class Node extends ScriptSpan {
|
|
6
|
+
constructor(span: ScriptSpan);
|
|
7
|
+
abstract type: Type;
|
|
8
|
+
abstract compile(type: Type): Node;
|
|
9
|
+
abstract evaluate(frame: CallFrame): Value;
|
|
10
|
+
get constant(): boolean;
|
|
11
|
+
protected reduceType(type: Type): Type;
|
|
12
|
+
protected throwTypeError(type: Type): never;
|
|
13
|
+
toString(ident?: number): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Constant } from "./Constant.js";
|
|
2
|
+
import { Value } from "./Value.js";
|
|
3
|
+
import { Type } from "./Type.js";
|
|
4
|
+
import { ScriptSpan } from "./ScriptSpan.js";
|
|
5
|
+
declare class Literal {
|
|
6
|
+
readonly value: Value;
|
|
7
|
+
constructor(value: Value);
|
|
8
|
+
}
|
|
9
|
+
declare class Assignment {
|
|
10
|
+
readonly operator?: Constant | undefined;
|
|
11
|
+
constructor(operator?: Constant | undefined);
|
|
12
|
+
}
|
|
13
|
+
export declare class ParserState extends ScriptSpan {
|
|
14
|
+
protected _fragment: Literal | Assignment | Constant | Type | symbol | string | undefined;
|
|
15
|
+
constructor(script: string);
|
|
16
|
+
get literal(): Literal;
|
|
17
|
+
get assignment(): Assignment;
|
|
18
|
+
get operator(): Constant;
|
|
19
|
+
get type(): Type;
|
|
20
|
+
get token(): string;
|
|
21
|
+
get isOperator(): boolean;
|
|
22
|
+
get isLiteral(): boolean;
|
|
23
|
+
get isAssignment(): boolean;
|
|
24
|
+
get isType(): boolean;
|
|
25
|
+
get isToken(): boolean;
|
|
26
|
+
get isParenthesesOpen(): boolean;
|
|
27
|
+
get isParenthesesClose(): boolean;
|
|
28
|
+
get isBracketsOpen(): boolean;
|
|
29
|
+
get isBracketsClose(): boolean;
|
|
30
|
+
get isBracesOpen(): boolean;
|
|
31
|
+
get isBracesClose(): boolean;
|
|
32
|
+
get isSemicolon(): boolean;
|
|
33
|
+
get isColon(): boolean;
|
|
34
|
+
get isComma(): boolean;
|
|
35
|
+
get isTilda(): boolean;
|
|
36
|
+
get isDot(): boolean;
|
|
37
|
+
get isQuestion(): boolean;
|
|
38
|
+
get isEllipsis(): boolean;
|
|
39
|
+
get isCast(): boolean;
|
|
40
|
+
get isVar(): boolean;
|
|
41
|
+
get isVal(): boolean;
|
|
42
|
+
get isIf(): boolean;
|
|
43
|
+
get isElse(): boolean;
|
|
44
|
+
get isWhile(): boolean;
|
|
45
|
+
get isExit(): boolean;
|
|
46
|
+
get isReturn(): boolean;
|
|
47
|
+
get isStop(): boolean;
|
|
48
|
+
get isNext(): boolean;
|
|
49
|
+
get isEmpty(): boolean;
|
|
50
|
+
openParentheses(): this;
|
|
51
|
+
closeParentheses(): this;
|
|
52
|
+
openBrackets(): this;
|
|
53
|
+
closeBrackets(): this;
|
|
54
|
+
openBraces(): this;
|
|
55
|
+
closeBraces(): this;
|
|
56
|
+
separateByColon(): this;
|
|
57
|
+
clone(): ParserState;
|
|
58
|
+
next(): ParserState;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class ScriptSpan {
|
|
2
|
+
protected readonly _script: string;
|
|
3
|
+
protected _start: number;
|
|
4
|
+
protected _end: number;
|
|
5
|
+
protected constructor(span: ScriptSpan | string);
|
|
6
|
+
start(): ScriptSpan;
|
|
7
|
+
end(span: ScriptSpan): this;
|
|
8
|
+
throwError(message: string): never;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Value } from "./Value.js";
|
|
2
|
+
import { PrimitiveAtom, Primitive } from "./atom/PrimitiveAtom.js";
|
|
3
|
+
import { ArrayAtom } from "./atom/ArrayAtom.js";
|
|
4
|
+
import { ObjectAtom } from "./atom/ObjectAtom.js";
|
|
5
|
+
import { FunctionAtom } from "./atom/FunctionAtom.js";
|
|
6
|
+
type Atom = PrimitiveAtom | ArrayAtom | ObjectAtom | FunctionAtom;
|
|
7
|
+
export declare class Type {
|
|
8
|
+
protected readonly _atoms: Atom[];
|
|
9
|
+
private constructor();
|
|
10
|
+
get isUnknown(): boolean;
|
|
11
|
+
get isAtom(): boolean;
|
|
12
|
+
get isOptional(): boolean;
|
|
13
|
+
get isVoid(): boolean;
|
|
14
|
+
get isBoolean(): boolean;
|
|
15
|
+
get isTimestamp(): boolean;
|
|
16
|
+
get isFloat(): boolean;
|
|
17
|
+
get isInteger(): boolean;
|
|
18
|
+
get isBuffer(): boolean;
|
|
19
|
+
get isString(): boolean;
|
|
20
|
+
get isArray(): boolean;
|
|
21
|
+
get isObject(): boolean;
|
|
22
|
+
get isFunction(): boolean;
|
|
23
|
+
equate(type: Type | undefined): boolean;
|
|
24
|
+
accept(type: Type | Atom): boolean;
|
|
25
|
+
acceptValue(value: Value): boolean;
|
|
26
|
+
reduce(mask: Type): Type | undefined;
|
|
27
|
+
intersect(type: Type): boolean;
|
|
28
|
+
weight(): number;
|
|
29
|
+
arrayAtomValType(index: number): Type;
|
|
30
|
+
functionAtomRetType(type: Type): Type;
|
|
31
|
+
functionAtoms(type: Type, argc: number): FunctionAtom[];
|
|
32
|
+
toOptional(): Type;
|
|
33
|
+
toMandatory(): Type;
|
|
34
|
+
toString(): string;
|
|
35
|
+
static union(...types: Type[]): Type;
|
|
36
|
+
static of(value: Value): Type;
|
|
37
|
+
static isPrimitive(value: Value): value is string | number | bigint | boolean | Date | ArrayBuffer | null | undefined;
|
|
38
|
+
static primitiveType(primitive: Primitive): Type;
|
|
39
|
+
static arrayType(itemTypes?: Type[]): Type;
|
|
40
|
+
static objectType(propTypes?: [string, Type][]): Type;
|
|
41
|
+
static functionType(retType?: Type, argTypes?: Type[], isVariadic?: boolean): Type;
|
|
42
|
+
static readonly Unknown: Type;
|
|
43
|
+
static readonly Void: Type;
|
|
44
|
+
static readonly Boolean: Type;
|
|
45
|
+
static readonly OptionalBoolean: Type;
|
|
46
|
+
static readonly Timestamp: Type;
|
|
47
|
+
static readonly OptionalTimestamp: Type;
|
|
48
|
+
static readonly Float: Type;
|
|
49
|
+
static readonly OptionalFloat: Type;
|
|
50
|
+
static readonly Integer: Type;
|
|
51
|
+
static readonly OptionalInteger: Type;
|
|
52
|
+
static readonly Buffer: Type;
|
|
53
|
+
static readonly OptionalBuffer: Type;
|
|
54
|
+
static readonly String: Type;
|
|
55
|
+
static readonly OptionalString: Type;
|
|
56
|
+
static readonly Array: Type;
|
|
57
|
+
static readonly OptionalArray: Type;
|
|
58
|
+
static readonly Object: Type;
|
|
59
|
+
static readonly OptionalObject: Type;
|
|
60
|
+
static readonly Function: Type;
|
|
61
|
+
static readonly OptionalFunction: Type;
|
|
62
|
+
static readonly Reference: Type;
|
|
63
|
+
static readonly OptionalReference: Type;
|
|
64
|
+
static readonly Number: Type;
|
|
65
|
+
static readonly OptionalNumber: Type;
|
|
66
|
+
static readonly Enumerable: Type;
|
|
67
|
+
static readonly OptionalEnumerable: Type;
|
|
68
|
+
static readonly Iterable: Type;
|
|
69
|
+
static readonly OptionalIterable: Type;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type PrimitiveValue = undefined | null | number | boolean | Date | bigint | ArrayBuffer | string;
|
|
2
|
+
export type Value = PrimitiveValue | Value[] | {
|
|
3
|
+
[key: string]: Value;
|
|
4
|
+
} | ((...args: any[]) => Value);
|
|
5
|
+
export declare const normalize: (value: Value) => Value;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
2
|
+
export declare class Variable {
|
|
3
|
+
protected _type: Type;
|
|
4
|
+
protected readonly _assignable: boolean;
|
|
5
|
+
constructor(_type?: Type, _assignable?: boolean);
|
|
6
|
+
get type(): Type;
|
|
7
|
+
set type(type: Type);
|
|
8
|
+
get assignable(): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IAtom } from "../Atom.js";
|
|
2
|
+
import { Type } from "../Type.js";
|
|
3
|
+
export declare class ArrayAtom implements IAtom {
|
|
4
|
+
protected readonly _valTypes: Type[];
|
|
5
|
+
constructor(_valTypes?: Type[]);
|
|
6
|
+
private get _undefined();
|
|
7
|
+
private _intersectLength;
|
|
8
|
+
get isTuple(): boolean;
|
|
9
|
+
valTypes(): Type[];
|
|
10
|
+
valType(index: number): Type | undefined;
|
|
11
|
+
equate(atom: IAtom): boolean;
|
|
12
|
+
accept(atom: IAtom): boolean;
|
|
13
|
+
intersect(atom: IAtom): boolean;
|
|
14
|
+
weight(): number;
|
|
15
|
+
toString(): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IAtom } from "../Atom.js";
|
|
2
|
+
import { Type } from "../Type.js";
|
|
3
|
+
export declare class FunctionAtom implements IAtom {
|
|
4
|
+
protected readonly _retType: Type;
|
|
5
|
+
protected readonly _argTypes: Type[];
|
|
6
|
+
protected readonly _isVariadic: boolean;
|
|
7
|
+
protected readonly _minArity: number;
|
|
8
|
+
constructor(_retType?: Type, _argTypes?: Type[], _isVariadic?: boolean);
|
|
9
|
+
private get _undefined();
|
|
10
|
+
get retType(): Type;
|
|
11
|
+
get minArity(): number;
|
|
12
|
+
get maxArity(): number;
|
|
13
|
+
get isVariadic(): boolean;
|
|
14
|
+
get arity(): number;
|
|
15
|
+
argType(index: number): Type | undefined;
|
|
16
|
+
paramType(index: number): Type | undefined;
|
|
17
|
+
equate(atom: IAtom): boolean;
|
|
18
|
+
accept(atom: IAtom): boolean;
|
|
19
|
+
intersect(atom: IAtom): boolean;
|
|
20
|
+
weight(): number;
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IAtom } from "../Atom.js";
|
|
2
|
+
import { Type } from "../Type.js";
|
|
3
|
+
export declare class ObjectAtom implements IAtom {
|
|
4
|
+
protected readonly _valTypes: [string, Type][];
|
|
5
|
+
constructor(valTypes?: [string, Type][]);
|
|
6
|
+
private get _undefined();
|
|
7
|
+
valTypes(): [string, Type][];
|
|
8
|
+
valType(key: string): Type | undefined;
|
|
9
|
+
equate(atom: IAtom): boolean;
|
|
10
|
+
accept(atom: IAtom): boolean;
|
|
11
|
+
intersect(atom: IAtom): boolean;
|
|
12
|
+
weight(): number;
|
|
13
|
+
toString(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IAtom } from "../Atom.js";
|
|
2
|
+
export type Primitive = "void" | "boolean" | "timestamp" | "float" | "integer" | "buffer" | "string";
|
|
3
|
+
export declare class PrimitiveAtom implements IAtom {
|
|
4
|
+
protected readonly _primitive: Primitive;
|
|
5
|
+
constructor(_primitive?: Primitive);
|
|
6
|
+
get undef(): boolean;
|
|
7
|
+
equate(atom: IAtom): boolean;
|
|
8
|
+
accept(atom: IAtom): boolean;
|
|
9
|
+
intersect(atom: IAtom): boolean;
|
|
10
|
+
weight(): number;
|
|
11
|
+
toString(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
import { Value } from "../Value.js";
|
|
3
|
+
export declare const aggregate: (value1: ArrayBuffer | string | Value[] | null | undefined, value2: ArrayBuffer | string | Value[] | null | undefined) => string | ArrayBuffer | Value[] | undefined;
|
|
4
|
+
export declare const funcAdd: Constant;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
export declare const funcFirst: Constant;
|
|
3
|
+
export declare const funcLast: Constant;
|
|
4
|
+
export declare const funcFirstIndex: Constant;
|
|
5
|
+
export declare const funcLastIndex: Constant;
|
|
6
|
+
export declare const funcEvery: Constant;
|
|
7
|
+
export declare const funcAny: Constant;
|
|
8
|
+
export declare const funcFlatten: Constant;
|
|
9
|
+
export declare const funcReverse: Constant;
|
|
10
|
+
export declare const funcDerive: Constant;
|
|
11
|
+
export declare const funcFilter: Constant;
|
|
12
|
+
export declare const funcReduce: Constant;
|
|
13
|
+
export declare const funcCompose: Constant;
|
|
14
|
+
export declare const funcPrepend: Constant;
|
|
15
|
+
export declare const funcAppend: Constant;
|
|
16
|
+
export declare const constArray: any;
|