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
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
diff --git a/src/Affinirum.ts b/src/Affinirum.ts
|
|
2
|
+
--- a/src/Affinirum.ts
|
|
3
|
+
+++ b/src/Affinirum.ts
|
|
4
|
+
@@ -29,6 +29,12 @@ import { funcNot } from "./native/Boolean.js";
|
|
5
|
+
import { funcNegate } from "./native/Number.js";
|
|
6
|
+
import { parseAN, formatAN } from "./native/notation/AN.js"
|
|
7
|
+
|
|
8
|
+
+type FunctionHeader = {
|
|
9
|
+
+ params: { name: string; span: ParserSpan; type?: Type }[];
|
|
10
|
+
+ variadic: boolean;
|
|
11
|
+
+ returnType: Type;
|
|
12
|
+
+};
|
|
13
|
+
+
|
|
14
|
+
export class Affinirum {
|
|
15
|
+
|
|
16
|
+
static readonly keywords = [...keywords, ...constants.map((c) => c[0])];
|
|
17
|
+
@@ -428,6 +434,18 @@ export class Affinirum {
|
|
18
|
+
}
|
|
19
|
+
else if (state.equals("(")) { // grouping or type cast
|
|
20
|
+
const span = state.start();
|
|
21
|
+
+ const restore = state.checkpoint();
|
|
22
|
+
+ let header: FunctionHeader | undefined;
|
|
23
|
+
+ try {
|
|
24
|
+
+ header = this._readHeader(state, scope);
|
|
25
|
+
+ }
|
|
26
|
+
+ catch {
|
|
27
|
+
+ // A colon can belong to an enclosing cast or object entry.
|
|
28
|
+
+ }
|
|
29
|
+
+ if (header && state.equals("->")) {
|
|
30
|
+
+ return this._functionBody(state.next(), scope, span, header);
|
|
31
|
+
+ }
|
|
32
|
+
+ restore();
|
|
33
|
+
let node = this._unit(state.next(), scope);
|
|
34
|
+
if (state.equals(":")) {
|
|
35
|
+
const type = this._type.parse(state.next(), scope);
|
|
36
|
+
@@ -518,46 +536,62 @@ export class Affinirum {
|
|
37
|
+
return new VariableNode(span, variable);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
- protected _function(state: ParserState, scope: LexicalScope): Node {
|
|
41
|
+
- const span = state.start();
|
|
42
|
+
- state.next().openParentheses();
|
|
43
|
+
+ protected _readHeader(state: ParserState, scope: LexicalScope): FunctionHeader | undefined {
|
|
44
|
+
+ const params: FunctionHeader["params"] = [];
|
|
45
|
+
let variadic = false;
|
|
46
|
+
- const variables = new Map<string, LocalVariable>();
|
|
47
|
+
while (!state.next().equals(")")) {
|
|
48
|
+
if (!state.isIdentifier) {
|
|
49
|
+
- state.throwError("missing function argument name");
|
|
50
|
+
- }
|
|
51
|
+
- const identifier = state.identifier;
|
|
52
|
+
- if (variables.has(identifier)) {
|
|
53
|
+
- state.throwError(`duplicate function argument name ${identifier}`);
|
|
54
|
+
+ return undefined;
|
|
55
|
+
}
|
|
56
|
+
- if (scope.has(identifier)) {
|
|
57
|
+
- state.throwError(`variable ${identifier} redefinition`);
|
|
58
|
+
- }
|
|
59
|
+
- let argType: Type | undefined;
|
|
60
|
+
+ const name = state.identifier;
|
|
61
|
+
+ const span = state.start();
|
|
62
|
+
+ let type: Type | undefined;
|
|
63
|
+
if (state.next().equals(":")) {
|
|
64
|
+
variadic = state.next().equals("...");
|
|
65
|
+
if (variadic) {
|
|
66
|
+
state.next();
|
|
67
|
+
}
|
|
68
|
+
if (!variadic || !state.equals(")")) {
|
|
69
|
+
- argType = this._type.parse(state, scope);
|
|
70
|
+
+ type = this._type.parse(state, scope);
|
|
71
|
+
}
|
|
72
|
+
if (variadic) {
|
|
73
|
+
- argType = Type.arrayType(argType);
|
|
74
|
+
+ type = Type.arrayType(type);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
- const variable = new LocalVariable(argType, true);
|
|
78
|
+
- variables.set(identifier, variable);
|
|
79
|
+
- if (variadic) {
|
|
80
|
+
- break;
|
|
81
|
+
- }
|
|
82
|
+
- if (!state.equals(",")) {
|
|
83
|
+
+ params.push({ name, span, type });
|
|
84
|
+
+ if (variadic || !state.equals(",")) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
- state.closeParentheses();
|
|
89
|
+
+ if (!state.equals(")")) {
|
|
90
|
+
+ return undefined;
|
|
91
|
+
+ }
|
|
92
|
+
const returnType = state.next().equals(":") ? this._type.parse(state.next(), scope) : Type.Any;
|
|
93
|
+
+ return { params, variadic, returnType };
|
|
94
|
+
+ }
|
|
95
|
+
+
|
|
96
|
+
+ protected _function(state: ParserState, scope: LexicalScope): Node {
|
|
97
|
+
+ const span = state.start();
|
|
98
|
+
+ state.next().openParentheses();
|
|
99
|
+
+ const header = this._readHeader(state, scope);
|
|
100
|
+
+ if (!header) {
|
|
101
|
+
+ return state.throwError("invalid function parameter list");
|
|
102
|
+
+ }
|
|
103
|
+
+ return this._functionBody(state, scope, span, header);
|
|
104
|
+
+ }
|
|
105
|
+
+
|
|
106
|
+
+ protected _functionBody(state: ParserState, scope: LexicalScope, span: ParserSpan, header: FunctionHeader): Node {
|
|
107
|
+
+ const { params, variadic, returnType } = header;
|
|
108
|
+
+ const variables = new Map<string, LocalVariable>();
|
|
109
|
+
+ for (const param of params) {
|
|
110
|
+
+ if (variables.has(param.name)) {
|
|
111
|
+
+ param.span.throwError(`duplicate function argument name ${param.name}`);
|
|
112
|
+
+ }
|
|
113
|
+
+ if (scope.has(param.name)) {
|
|
114
|
+
+ param.span.throwError(`variable ${param.name} redefinition`);
|
|
115
|
+
+ }
|
|
116
|
+
+ variables.set(param.name, new LocalVariable(param.type, true));
|
|
117
|
+
+ }
|
|
118
|
+
state.openBraces();
|
|
119
|
+
state.next();
|
|
120
|
+
const args = Array.from(variables.values());
|
|
121
|
+
diff --git a/src/ParserState.ts b/src/ParserState.ts
|
|
122
|
+
--- a/src/ParserState.ts
|
|
123
|
+
+++ b/src/ParserState.ts
|
|
124
|
+
@@ -122,6 +122,15 @@ export class ParserState extends ParserSpan {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
+ checkpoint(): () => void {
|
|
129
|
+
+ const start = this._start, end = this._end, value = this._value;
|
|
130
|
+
+ return () => {
|
|
131
|
+
+ this._start = start;
|
|
132
|
+
+ this._end = end;
|
|
133
|
+
+ this._value = value;
|
|
134
|
+
+ };
|
|
135
|
+
+ }
|
|
136
|
+
+
|
|
137
|
+
next(): ParserState {
|
|
138
|
+
this._value = undefined;
|
|
139
|
+
while (this._end < this._script.length && this._value == null) {
|
|
140
|
+
@@ -261,6 +270,7 @@ const tokens: [string, Type | Constant | Literal | false][] = [
|
|
141
|
+
[";", false],
|
|
142
|
+
[":", false],
|
|
143
|
+
[",", false],
|
|
144
|
+
+ ["->", false],
|
|
145
|
+
["~", false],
|
|
146
|
+
["~>", false],
|
|
147
|
+
["?", false],
|
|
148
|
+
@@ -296,6 +306,7 @@ const punctuators: string[] = [
|
|
149
|
+
";",
|
|
150
|
+
":",
|
|
151
|
+
",",
|
|
152
|
+
+ "->",
|
|
153
|
+
"~",
|
|
154
|
+
"~>",
|
|
155
|
+
"?",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
> affinirum@2.0.0 pretest
|
|
3
|
+
> npm run clean && tsc --build tsconfig.test.json
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> affinirum@2.0.0 clean
|
|
7
|
+
> rimraf --glob dst/* && rimraf --glob *.tgz
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
> affinirum@2.0.0 test
|
|
11
|
+
> node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand
|
|
12
|
+
|
|
13
|
+
(node:19772) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
|
|
14
|
+
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
15
|
+
Seed: -1811215796
|
|
16
|
+
Test Suites: 43 passed, 43 total
|
|
17
|
+
Tests: 1092 passed, 1092 total
|
|
18
|
+
Snapshots: 0 total
|
|
19
|
+
Time: 7.071 s
|
|
20
|
+
Ran all test suites.
|