affinirum 1.5.4 → 2.0.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/.cache/arrow-preview-vWvB5K/affinirum-arrow-functions.patch +155 -0
- package/.cache/function-syntax-tests.log +20 -0
- package/README.md +925 -355
- package/dst/Affinirum.d.ts +29 -19
- package/dst/Affinirum.js +399 -334
- package/dst/CallFrame.d.ts +12 -3
- package/dst/CallFrame.js +49 -10
- package/dst/Constant.d.ts +1 -3
- package/dst/Constant.js +3 -8
- package/dst/LexicalScope.d.ts +11 -9
- package/dst/LexicalScope.js +10 -6
- package/dst/ParserSpan.d.ts +11 -0
- package/dst/{ScriptSpan.js → ParserSpan.js} +8 -5
- package/dst/ParserState.d.ts +28 -49
- package/dst/ParserState.js +256 -489
- package/dst/Type.d.ts +34 -17
- package/dst/Type.js +211 -115
- package/dst/TypeParser.d.ts +9 -0
- package/dst/TypeParser.js +127 -0
- package/dst/Value.d.ts +1 -1
- package/dst/Value.js +21 -10
- package/dst/Variable.d.ts +16 -5
- package/dst/Variable.js +32 -7
- package/dst/atom/ArrayAtom.d.ts +10 -10
- package/dst/atom/ArrayAtom.js +62 -55
- package/dst/atom/Atom.d.ts +7 -0
- package/dst/atom/FunctionAtom.d.ts +13 -15
- package/dst/atom/FunctionAtom.js +53 -104
- package/dst/atom/FunctionSignature.d.ts +23 -0
- package/dst/atom/FunctionSignature.js +124 -0
- package/dst/atom/ObjectAtom.d.ts +11 -9
- package/dst/atom/ObjectAtom.js +73 -33
- package/dst/atom/PrimitiveAtom.d.ts +6 -7
- package/dst/atom/PrimitiveAtom.js +7 -10
- package/dst/cjs/Affinirum.d.ts +29 -19
- package/dst/cjs/Affinirum.js +398 -333
- package/dst/cjs/CallFrame.d.ts +12 -3
- package/dst/cjs/CallFrame.js +49 -10
- package/dst/cjs/Constant.d.ts +1 -3
- package/dst/cjs/Constant.js +3 -8
- package/dst/cjs/LexicalScope.d.ts +11 -9
- package/dst/cjs/LexicalScope.js +10 -6
- package/dst/cjs/ParserSpan.d.ts +11 -0
- package/dst/cjs/{ScriptSpan.js → ParserSpan.js} +10 -7
- package/dst/cjs/ParserState.d.ts +28 -49
- package/dst/cjs/ParserState.js +255 -488
- package/dst/cjs/Type.d.ts +34 -17
- package/dst/cjs/Type.js +211 -115
- package/dst/cjs/TypeParser.d.ts +9 -0
- package/dst/cjs/TypeParser.js +131 -0
- package/dst/cjs/Value.d.ts +1 -1
- package/dst/cjs/Value.js +21 -10
- package/dst/cjs/Variable.d.ts +16 -5
- package/dst/cjs/Variable.js +36 -9
- package/dst/cjs/atom/ArrayAtom.d.ts +10 -10
- package/dst/cjs/atom/ArrayAtom.js +62 -55
- package/dst/cjs/atom/Atom.d.ts +7 -0
- package/dst/cjs/atom/FunctionAtom.d.ts +13 -15
- package/dst/cjs/atom/FunctionAtom.js +54 -105
- package/dst/cjs/atom/FunctionSignature.d.ts +23 -0
- package/dst/cjs/atom/FunctionSignature.js +128 -0
- package/dst/cjs/atom/ObjectAtom.d.ts +11 -9
- package/dst/cjs/atom/ObjectAtom.js +73 -33
- package/dst/cjs/atom/PrimitiveAtom.d.ts +6 -7
- package/dst/cjs/atom/PrimitiveAtom.js +7 -10
- package/dst/cjs/dictionary/Constants.d.ts +2 -0
- package/dst/cjs/dictionary/Constants.js +27 -0
- package/dst/cjs/dictionary/Functions.d.ts +2 -0
- package/dst/cjs/{Functions.js → dictionary/Functions.js} +27 -25
- package/dst/cjs/native/Aggregable.js +10 -2
- package/dst/cjs/native/Array.d.ts +2 -3
- package/dst/cjs/native/Array.js +38 -39
- package/dst/cjs/native/Boolean.d.ts +1 -1
- package/dst/cjs/native/Boolean.js +13 -10
- package/dst/cjs/native/Buffer.d.ts +5 -5
- package/dst/cjs/native/Buffer.js +70 -46
- package/dst/cjs/native/Composite.d.ts +5 -0
- package/dst/cjs/native/Composite.js +35 -0
- package/dst/cjs/native/Enumerable.js +20 -8
- package/dst/cjs/native/Float.d.ts +3 -1
- package/dst/cjs/native/Float.js +51 -12
- package/dst/cjs/native/Integer.d.ts +4 -2
- package/dst/cjs/native/Integer.js +60 -25
- package/dst/cjs/native/Iterable.d.ts +0 -2
- package/dst/cjs/native/Iterable.js +9 -28
- package/dst/cjs/native/Number.d.ts +0 -2
- package/dst/cjs/native/Number.js +34 -48
- package/dst/cjs/native/Object.d.ts +1 -1
- package/dst/cjs/native/Object.js +5 -6
- package/dst/cjs/native/String.d.ts +7 -6
- package/dst/cjs/native/String.js +28 -27
- package/dst/cjs/native/Timestamp.d.ts +3 -3
- package/dst/cjs/native/Timestamp.js +34 -36
- package/dst/cjs/native/Unknown.d.ts +3 -3
- package/dst/cjs/native/Unknown.js +48 -17
- package/dst/cjs/native/notation/AN.d.ts +1 -1
- package/dst/cjs/native/notation/AN.js +37 -35
- package/dst/cjs/native/notation/IP.d.ts +1 -1
- package/dst/cjs/native/notation/IP.js +11 -12
- package/dst/cjs/native/notation/JSON.d.ts +1 -1
- package/dst/cjs/native/notation/JSON.js +7 -6
- package/dst/cjs/node/AccessNode.d.ts +24 -0
- package/dst/cjs/node/AccessNode.js +193 -0
- package/dst/cjs/node/ArrayNode.d.ts +7 -4
- package/dst/cjs/node/ArrayNode.js +26 -15
- package/dst/cjs/node/AssignableNode.d.ts +16 -0
- package/dst/cjs/node/AssignableNode.js +18 -0
- package/dst/cjs/node/AssignmentNode.d.ts +20 -0
- package/dst/cjs/node/AssignmentNode.js +66 -0
- package/dst/cjs/node/BlockNode.d.ts +5 -4
- package/dst/cjs/node/BlockNode.js +18 -11
- package/dst/cjs/node/CallNode.d.ts +7 -5
- package/dst/cjs/node/CallNode.js +40 -41
- package/dst/cjs/node/CastNode.d.ts +5 -6
- package/dst/cjs/node/CastNode.js +16 -17
- package/dst/cjs/node/ConstantNode.d.ts +4 -6
- package/dst/cjs/node/ConstantNode.js +9 -17
- package/dst/cjs/node/FinalNode.d.ts +19 -0
- package/dst/cjs/node/FinalNode.js +41 -0
- package/dst/cjs/node/FunctionNode.d.ts +17 -0
- package/dst/cjs/node/FunctionNode.js +51 -0
- package/dst/cjs/node/InvocationNode.d.ts +5 -0
- package/dst/cjs/node/InvocationNode.js +34 -0
- package/dst/cjs/node/JumpNode.d.ts +7 -9
- package/dst/cjs/node/JumpNode.js +12 -19
- package/dst/cjs/node/LoopNode.d.ts +7 -5
- package/dst/cjs/node/LoopNode.js +33 -22
- package/dst/cjs/node/MatchNode.d.ts +17 -0
- package/dst/cjs/node/MatchNode.js +65 -0
- package/dst/cjs/node/Node.d.ts +14 -0
- package/dst/cjs/{Node.js → node/Node.js} +17 -11
- package/dst/cjs/node/ObjectNode.d.ts +7 -4
- package/dst/cjs/node/ObjectNode.js +42 -11
- package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
- package/dst/cjs/node/TernaryNode.js +45 -0
- package/dst/cjs/node/VariableNode.d.ts +10 -6
- package/dst/cjs/node/VariableNode.js +50 -16
- package/dst/dictionary/Constants.d.ts +2 -0
- package/dst/dictionary/Constants.js +24 -0
- package/dst/dictionary/Functions.d.ts +2 -0
- package/dst/{Functions.js → dictionary/Functions.js} +26 -24
- package/dst/native/Aggregable.js +11 -3
- package/dst/native/Array.d.ts +2 -3
- package/dst/native/Array.js +37 -38
- package/dst/native/Boolean.d.ts +1 -1
- package/dst/native/Boolean.js +12 -9
- package/dst/native/Buffer.d.ts +5 -5
- package/dst/native/Buffer.js +66 -42
- package/dst/native/Composite.d.ts +5 -0
- package/dst/native/Composite.js +32 -0
- package/dst/native/Enumerable.js +20 -8
- package/dst/native/Float.d.ts +3 -1
- package/dst/native/Float.js +48 -11
- package/dst/native/Integer.d.ts +4 -2
- package/dst/native/Integer.js +56 -23
- package/dst/native/Iterable.d.ts +0 -2
- package/dst/native/Iterable.js +8 -27
- package/dst/native/Number.d.ts +0 -2
- package/dst/native/Number.js +34 -46
- package/dst/native/Object.d.ts +1 -1
- package/dst/native/Object.js +4 -5
- package/dst/native/String.d.ts +7 -6
- package/dst/native/String.js +24 -24
- package/dst/native/Timestamp.d.ts +3 -3
- package/dst/native/Timestamp.js +31 -33
- package/dst/native/Unknown.d.ts +3 -3
- package/dst/native/Unknown.js +49 -18
- package/dst/native/notation/AN.d.ts +1 -1
- package/dst/native/notation/AN.js +37 -35
- package/dst/native/notation/IP.d.ts +1 -1
- package/dst/native/notation/IP.js +10 -11
- package/dst/native/notation/JSON.d.ts +1 -1
- package/dst/native/notation/JSON.js +6 -5
- package/dst/node/AccessNode.d.ts +24 -0
- package/dst/node/AccessNode.js +189 -0
- package/dst/node/ArrayNode.d.ts +7 -4
- package/dst/node/ArrayNode.js +26 -15
- package/dst/node/AssignableNode.d.ts +16 -0
- package/dst/node/AssignableNode.js +14 -0
- package/dst/node/AssignmentNode.d.ts +20 -0
- package/dst/node/AssignmentNode.js +62 -0
- package/dst/node/BlockNode.d.ts +5 -4
- package/dst/node/BlockNode.js +18 -11
- package/dst/node/CallNode.d.ts +7 -5
- package/dst/node/CallNode.js +40 -41
- package/dst/node/CastNode.d.ts +5 -6
- package/dst/node/CastNode.js +16 -17
- package/dst/node/ConstantNode.d.ts +4 -6
- package/dst/node/ConstantNode.js +9 -17
- package/dst/node/FinalNode.d.ts +19 -0
- package/dst/node/FinalNode.js +37 -0
- package/dst/node/FunctionNode.d.ts +17 -0
- package/dst/node/FunctionNode.js +47 -0
- package/dst/node/InvocationNode.d.ts +5 -0
- package/dst/node/InvocationNode.js +30 -0
- package/dst/node/JumpNode.d.ts +7 -9
- package/dst/node/JumpNode.js +12 -19
- package/dst/node/LoopNode.d.ts +7 -5
- package/dst/node/LoopNode.js +33 -22
- package/dst/node/MatchNode.d.ts +17 -0
- package/dst/node/MatchNode.js +61 -0
- package/dst/node/Node.d.ts +14 -0
- package/dst/node/Node.js +28 -0
- package/dst/node/ObjectNode.d.ts +7 -4
- package/dst/node/ObjectNode.js +42 -11
- package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
- package/dst/node/TernaryNode.js +41 -0
- package/dst/node/VariableNode.d.ts +10 -6
- package/dst/node/VariableNode.js +50 -16
- package/package.json +4 -4
- package/dst/Atom.d.ts +0 -7
- package/dst/Constants.d.ts +0 -2
- package/dst/Constants.js +0 -24
- package/dst/Functions.d.ts +0 -2
- package/dst/Jump.d.ts +0 -1
- package/dst/Jump.js +0 -1
- package/dst/JumpException.d.ts +0 -9
- package/dst/JumpException.js +0 -14
- package/dst/Keywords.d.ts +0 -1
- package/dst/Keywords.js +0 -17
- package/dst/Node.d.ts +0 -14
- package/dst/Node.js +0 -22
- package/dst/ScriptSpan.d.ts +0 -10
- package/dst/cjs/Atom.d.ts +0 -7
- package/dst/cjs/Constants.d.ts +0 -2
- package/dst/cjs/Constants.js +0 -27
- package/dst/cjs/Functions.d.ts +0 -2
- package/dst/cjs/Jump.d.ts +0 -1
- package/dst/cjs/Jump.js +0 -2
- package/dst/cjs/JumpException.d.ts +0 -9
- package/dst/cjs/JumpException.js +0 -18
- package/dst/cjs/Keywords.d.ts +0 -1
- package/dst/cjs/Keywords.js +0 -20
- package/dst/cjs/Node.d.ts +0 -14
- package/dst/cjs/ScriptSpan.d.ts +0 -10
- package/dst/cjs/node/SwitchNode.js +0 -49
- package/dst/cjs/node/VariadicNode.d.ts +0 -4
- package/dst/cjs/node/VariadicNode.js +0 -10
- package/dst/node/SwitchNode.js +0 -45
- package/dst/node/VariadicNode.d.ts +0 -4
- package/dst/node/VariadicNode.js +0 -6
- /package/dst/{Atom.js → atom/Atom.js} +0 -0
- /package/dst/cjs/{Atom.js → atom/Atom.js} +0 -0
package/dst/CallFrame.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
1
2
|
import type { Value } from "./Value.js";
|
|
2
3
|
import type { Variable } from "./Variable.js";
|
|
3
4
|
export declare class CallFrame {
|
|
5
|
+
protected readonly _stop?: {
|
|
6
|
+
deadline?: Date;
|
|
7
|
+
};
|
|
4
8
|
protected readonly _superframe?: CallFrame;
|
|
5
9
|
protected readonly _values: Map<Variable, Value>;
|
|
6
|
-
|
|
10
|
+
protected readonly _types: WeakMap<object, Type[]>;
|
|
11
|
+
constructor(superframe?: CallFrame | Date, variables?: Iterable<Variable>);
|
|
12
|
+
timer(): void;
|
|
13
|
+
clearTimer(): void;
|
|
7
14
|
subframe(variables: Iterable<Variable>): CallFrame;
|
|
8
|
-
add(variable: Variable, value?: Value):
|
|
9
|
-
get(variable: Variable): Value;
|
|
15
|
+
add(variable: Variable, value?: Value): Value;
|
|
10
16
|
set(variable: Variable, value: Value): Value;
|
|
17
|
+
get(variable: Variable): Value;
|
|
18
|
+
define(value: Value, type: Type): Value;
|
|
19
|
+
definitions(value: object): readonly Type[];
|
|
11
20
|
}
|
package/dst/CallFrame.js
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
|
+
import { Type } from "./Type.js";
|
|
1
2
|
export class CallFrame {
|
|
3
|
+
_stop;
|
|
2
4
|
_superframe;
|
|
3
|
-
_values
|
|
5
|
+
_values;
|
|
6
|
+
_types;
|
|
4
7
|
constructor(superframe, variables = []) {
|
|
5
|
-
|
|
8
|
+
if (superframe instanceof CallFrame) {
|
|
9
|
+
this._superframe = superframe;
|
|
10
|
+
this._stop = superframe._stop;
|
|
11
|
+
}
|
|
12
|
+
else if (superframe instanceof Date) {
|
|
13
|
+
this._stop = { deadline: superframe };
|
|
14
|
+
}
|
|
15
|
+
this._values = new Map();
|
|
6
16
|
for (const variable of variables) {
|
|
7
|
-
this.
|
|
17
|
+
this._values.set(variable, undefined);
|
|
18
|
+
}
|
|
19
|
+
this._types = this._superframe?._types ?? new WeakMap();
|
|
20
|
+
}
|
|
21
|
+
timer() {
|
|
22
|
+
const deadline = this._stop?.deadline;
|
|
23
|
+
if (deadline && new Date() > deadline) {
|
|
24
|
+
throw new Error("execution timeout");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
clearTimer() {
|
|
28
|
+
if (this._stop) {
|
|
29
|
+
this._stop.deadline = undefined;
|
|
8
30
|
}
|
|
9
31
|
}
|
|
10
32
|
subframe(variables) {
|
|
@@ -12,24 +34,41 @@ export class CallFrame {
|
|
|
12
34
|
}
|
|
13
35
|
add(variable, value = undefined) {
|
|
14
36
|
this._values.set(variable, value);
|
|
37
|
+
this.define(value, variable.type);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
set(variable, value) {
|
|
41
|
+
if (this._values.has(variable)) {
|
|
42
|
+
return this.add(variable, value);
|
|
43
|
+
}
|
|
44
|
+
if (this._superframe instanceof CallFrame) {
|
|
45
|
+
return this._superframe.set(variable, value);
|
|
46
|
+
}
|
|
47
|
+
throw new Error("variable is not declared in call frame");
|
|
15
48
|
}
|
|
16
49
|
get(variable) {
|
|
17
50
|
if (this._values.has(variable)) {
|
|
18
51
|
return this._values.get(variable);
|
|
19
52
|
}
|
|
20
|
-
if (this._superframe) {
|
|
53
|
+
if (this._superframe instanceof CallFrame) {
|
|
21
54
|
return this._superframe.get(variable);
|
|
22
55
|
}
|
|
23
56
|
throw new Error("variable is not declared in call frame");
|
|
24
57
|
}
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
this._values.set(variable, value);
|
|
58
|
+
define(value, type) {
|
|
59
|
+
if (type.isAny || typeof value !== "object" || Type.isPrimitive(value) || Type.isFunction(value)) {
|
|
28
60
|
return value;
|
|
29
61
|
}
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
const types = this._types.get(value);
|
|
63
|
+
if (!types) {
|
|
64
|
+
this._types.set(value, [type]);
|
|
32
65
|
}
|
|
33
|
-
|
|
66
|
+
else if (!types.some((i) => i.equals(type))) {
|
|
67
|
+
types.push(type);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
definitions(value) {
|
|
72
|
+
return this._types.get(value) ?? [];
|
|
34
73
|
}
|
|
35
74
|
}
|
package/dst/Constant.d.ts
CHANGED
|
@@ -3,11 +3,9 @@ import { Type } from "./Type.js";
|
|
|
3
3
|
export declare class Constant {
|
|
4
4
|
protected readonly _value: Value;
|
|
5
5
|
protected _type: Type;
|
|
6
|
-
|
|
7
|
-
constructor(_value: Value, _type?: Type, _deterministic?: boolean);
|
|
6
|
+
constructor(value: Value, type?: Type);
|
|
8
7
|
get value(): Value;
|
|
9
8
|
get type(): Type;
|
|
10
9
|
set type(type: Type);
|
|
11
|
-
get deterministic(): boolean;
|
|
12
10
|
static Null: Constant;
|
|
13
11
|
}
|
package/dst/Constant.js
CHANGED
|
@@ -2,11 +2,9 @@ import { Type } from "./Type.js";
|
|
|
2
2
|
export class Constant {
|
|
3
3
|
_value;
|
|
4
4
|
_type;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
8
|
-
this._type = _type;
|
|
9
|
-
this._deterministic = _deterministic;
|
|
5
|
+
constructor(value, type = Type.of(value)) {
|
|
6
|
+
this._value = value;
|
|
7
|
+
this._type = type;
|
|
10
8
|
}
|
|
11
9
|
get value() {
|
|
12
10
|
return this._value;
|
|
@@ -17,8 +15,5 @@ export class Constant {
|
|
|
17
15
|
set type(type) {
|
|
18
16
|
this._type = type;
|
|
19
17
|
}
|
|
20
|
-
get deterministic() {
|
|
21
|
-
return this._deterministic;
|
|
22
|
-
}
|
|
23
18
|
static Null = new Constant(undefined);
|
|
24
19
|
}
|
package/dst/LexicalScope.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Type } from "./Type.js";
|
|
2
|
-
import {
|
|
2
|
+
import { LocalVariable } from "./Variable.js";
|
|
3
3
|
export declare class LexicalScope {
|
|
4
4
|
protected readonly _superscope?: LexicalScope;
|
|
5
5
|
protected readonly _subscopes: LexicalScope[];
|
|
6
|
-
protected readonly _variables: Map<string,
|
|
7
|
-
protected readonly _type: Type
|
|
8
|
-
|
|
6
|
+
protected readonly _variables: Map<string, LocalVariable>;
|
|
7
|
+
protected readonly _type: Type;
|
|
8
|
+
readonly inFunction: boolean;
|
|
9
|
+
inLoop: boolean;
|
|
10
|
+
constructor(superscope?: LexicalScope, variables?: Map<string, LocalVariable>, type?: Type, boundary?: boolean);
|
|
9
11
|
has(name: string): boolean;
|
|
10
|
-
get(name: string):
|
|
11
|
-
set(name: string, variable:
|
|
12
|
-
subscope(variables?: Map<string,
|
|
13
|
-
variables(): IterableIterator<
|
|
14
|
-
type(): Type;
|
|
12
|
+
get(name: string): LocalVariable | undefined;
|
|
13
|
+
set(name: string, variable: LocalVariable): void;
|
|
14
|
+
subscope(variables?: Map<string, LocalVariable>, type?: Type, boundary?: boolean): LexicalScope;
|
|
15
|
+
variables(): IterableIterator<LocalVariable>;
|
|
16
|
+
get type(): Type;
|
|
15
17
|
}
|
package/dst/LexicalScope.js
CHANGED
|
@@ -4,11 +4,15 @@ export class LexicalScope {
|
|
|
4
4
|
_subscopes = [];
|
|
5
5
|
_variables;
|
|
6
6
|
_type;
|
|
7
|
-
|
|
7
|
+
inFunction;
|
|
8
|
+
inLoop;
|
|
9
|
+
constructor(superscope, variables, type, boundary = false) {
|
|
8
10
|
superscope?._subscopes.push(this);
|
|
9
11
|
this._superscope = superscope;
|
|
10
12
|
this._variables = variables ?? new Map();
|
|
11
|
-
this._type = type;
|
|
13
|
+
this._type = type ?? superscope?.type ?? Type.Any;
|
|
14
|
+
this.inFunction = boundary || Boolean(superscope?.inFunction);
|
|
15
|
+
this.inLoop = !boundary && Boolean(superscope?.inLoop);
|
|
12
16
|
}
|
|
13
17
|
has(name) {
|
|
14
18
|
return this._variables.has(name) || Boolean(this._superscope?.has(name));
|
|
@@ -19,13 +23,13 @@ export class LexicalScope {
|
|
|
19
23
|
set(name, variable) {
|
|
20
24
|
this._variables.set(name, variable);
|
|
21
25
|
}
|
|
22
|
-
subscope(variables, type) {
|
|
23
|
-
return new LexicalScope(this, variables, type);
|
|
26
|
+
subscope(variables, type, boundary = false) {
|
|
27
|
+
return new LexicalScope(this, variables, type, boundary);
|
|
24
28
|
}
|
|
25
29
|
variables() {
|
|
26
30
|
return this._variables.values();
|
|
27
31
|
}
|
|
28
|
-
type() {
|
|
29
|
-
return this._type
|
|
32
|
+
get type() {
|
|
33
|
+
return this._type;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class ParserSpan {
|
|
2
|
+
protected readonly _script: string;
|
|
3
|
+
protected _start: number;
|
|
4
|
+
protected _end: number;
|
|
5
|
+
protected constructor(span: ParserSpan | string);
|
|
6
|
+
start(): ParserSpan;
|
|
7
|
+
end(span: ParserSpan): this;
|
|
8
|
+
text(): string;
|
|
9
|
+
throwError(message: string): never;
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class ParserSpan {
|
|
2
2
|
_script;
|
|
3
3
|
_start = 0;
|
|
4
4
|
_end = 0;
|
|
@@ -13,19 +13,22 @@ export class ScriptSpan {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
start() {
|
|
16
|
-
return new
|
|
16
|
+
return new ParserSpan(this);
|
|
17
17
|
}
|
|
18
18
|
end(span) {
|
|
19
19
|
this._end = span._end;
|
|
20
20
|
return this;
|
|
21
21
|
}
|
|
22
|
+
text() {
|
|
23
|
+
return this._script.substring(this._start, this._end);
|
|
24
|
+
}
|
|
22
25
|
throwError(message) {
|
|
23
26
|
const offset = this._start < 32 ? 0 : this._start - 32;
|
|
24
|
-
const length = this._end
|
|
27
|
+
const length = this._end <= this._start ? 0 : this._end - this._start - 1;
|
|
25
28
|
let expr = "";
|
|
26
29
|
for (let i = 0; i < this._script.length; ++i) {
|
|
27
30
|
const c = this._script[i];
|
|
28
|
-
expr +=
|
|
31
|
+
expr += spaceSymbols.includes(c) ? " " : c;
|
|
29
32
|
}
|
|
30
33
|
throw new Error(`error: ${message} at position ${this._start}:\n${expr.substring(offset, offset + 60)}\n` +
|
|
31
34
|
`${" ".repeat(expr.substring(offset, this._start).length)}^${"'".repeat(length)}`);
|
|
@@ -34,7 +37,7 @@ export class ScriptSpan {
|
|
|
34
37
|
return `[${this._start}:${this._end}]`;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
const
|
|
40
|
+
const spaceSymbols = [
|
|
38
41
|
// Whitespace and line-breaking characters
|
|
39
42
|
"\t", // tab
|
|
40
43
|
"\n", // newline
|
package/dst/ParserState.d.ts
CHANGED
|
@@ -1,60 +1,39 @@
|
|
|
1
|
-
import { Constant } from "./Constant.js";
|
|
2
|
-
import { Value } from "./Value.js";
|
|
3
1
|
import { Type } from "./Type.js";
|
|
4
|
-
import {
|
|
2
|
+
import { Value } from "./Value.js";
|
|
3
|
+
import { Constant } from "./Constant.js";
|
|
4
|
+
import { ParserSpan } from "./ParserSpan.js";
|
|
5
5
|
declare class Literal {
|
|
6
6
|
readonly value: Value;
|
|
7
7
|
constructor(value: Value);
|
|
8
8
|
}
|
|
9
|
-
declare class
|
|
10
|
-
readonly
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
protected
|
|
9
|
+
export declare class ParserState extends ParserSpan {
|
|
10
|
+
protected readonly _tokens: Map<string, false | Type | Constant | Literal>;
|
|
11
|
+
protected readonly _assignments: Set<string>;
|
|
12
|
+
protected readonly _punctuators: Set<string>;
|
|
13
|
+
protected readonly _operators: Set<string>;
|
|
14
|
+
protected _value: Type | Constant | Literal | string | false | undefined;
|
|
15
15
|
constructor(script: string);
|
|
16
|
-
|
|
17
|
-
get
|
|
18
|
-
get
|
|
19
|
-
get
|
|
20
|
-
get token(): string;
|
|
21
|
-
get isOperator(): boolean;
|
|
16
|
+
equals(...tokens: string[]): boolean;
|
|
17
|
+
get isEnded(): boolean;
|
|
18
|
+
get isType(): boolean;
|
|
19
|
+
get isConstant(): boolean;
|
|
22
20
|
get isLiteral(): boolean;
|
|
21
|
+
get isIdentifier(): boolean;
|
|
23
22
|
get isAssignment(): boolean;
|
|
24
|
-
get
|
|
25
|
-
get
|
|
26
|
-
get
|
|
27
|
-
get
|
|
28
|
-
get
|
|
29
|
-
get
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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;
|
|
23
|
+
get isPunctuator(): boolean;
|
|
24
|
+
get isOperator(): boolean;
|
|
25
|
+
get type(): Type;
|
|
26
|
+
get constant(): Constant;
|
|
27
|
+
get literal(): Literal;
|
|
28
|
+
get identifier(): string;
|
|
29
|
+
openParentheses(): void;
|
|
30
|
+
closeParentheses(): void;
|
|
31
|
+
openBrackets(): void;
|
|
32
|
+
closeBrackets(): void;
|
|
33
|
+
openBraces(): void;
|
|
34
|
+
closeBraces(): void;
|
|
35
|
+
assertColon(): void;
|
|
58
36
|
next(): ParserState;
|
|
59
37
|
}
|
|
38
|
+
export declare const keywords: Set<string>;
|
|
60
39
|
export {};
|