affinirum 1.3.0 → 1.4.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/README.md +156 -126
- package/dst/Affinirum.d.ts +1 -1
- package/dst/Affinirum.js +49 -53
- package/dst/Constants.js +10 -10
- package/dst/Functions.js +10 -10
- package/dst/ParserState.js +8 -8
- package/dst/atom/ArrayAtom.d.ts +3 -3
- package/dst/atom/ArrayAtom.js +14 -13
- package/dst/atom/FunctionAtom.d.ts +1 -1
- package/dst/atom/FunctionAtom.js +10 -8
- package/dst/atom/ObjectAtom.d.ts +3 -3
- package/dst/atom/ObjectAtom.js +14 -18
- package/dst/atom/PrimitiveAtom.js +3 -3
- package/dst/cjs/Affinirum.js +49 -53
- package/dst/cjs/Constants.js +10 -10
- package/dst/cjs/Functions.js +10 -10
- package/dst/cjs/ParserState.js +8 -8
- package/dst/cjs/atom/ArrayAtom.js +14 -13
- package/dst/cjs/atom/FunctionAtom.js +10 -8
- package/dst/cjs/atom/ObjectAtom.js +14 -18
- package/dst/cjs/atom/PrimitiveAtom.js +3 -3
- package/dst/cjs/node/ArrayNode.js +7 -3
- package/dst/cjs/node/{FunctionNode.js → CallNode.js} +5 -4
- package/dst/cjs/node/ObjectNode.js +4 -2
- package/dst/node/ArrayNode.d.ts +2 -1
- package/dst/node/ArrayNode.js +7 -3
- package/dst/node/{FunctionNode.d.ts → CallNode.d.ts} +1 -1
- package/dst/node/{FunctionNode.js → CallNode.js} +3 -2
- package/dst/node/ObjectNode.d.ts +1 -1
- package/dst/node/ObjectNode.js +4 -2
- package/package.json +1 -1
- /package/dst/cjs/{constant → native}/Aggregable.js +0 -0
- /package/dst/cjs/{constant → native}/Array.js +0 -0
- /package/dst/cjs/{constant → native}/Boolean.js +0 -0
- /package/dst/cjs/{constant → native}/Buffer.js +0 -0
- /package/dst/cjs/{constant → native}/Enumerable.js +0 -0
- /package/dst/cjs/{constant → native}/Float.js +0 -0
- /package/dst/cjs/{constant → native}/Integer.js +0 -0
- /package/dst/cjs/{constant → native}/Iterable.js +0 -0
- /package/dst/cjs/{constant → native}/Number.js +0 -0
- /package/dst/cjs/{constant → native}/Object.js +0 -0
- /package/dst/cjs/{constant → native}/String.js +0 -0
- /package/dst/cjs/{constant → native}/Timestamp.js +0 -0
- /package/dst/cjs/{constant → native}/Unknown.js +0 -0
- /package/dst/cjs/{constant → native}/notation/AN.js +0 -0
- /package/dst/cjs/{constant → native}/notation/JSON.js +0 -0
- /package/dst/{constant → native}/Aggregable.d.ts +0 -0
- /package/dst/{constant → native}/Aggregable.js +0 -0
- /package/dst/{constant → native}/Array.d.ts +0 -0
- /package/dst/{constant → native}/Array.js +0 -0
- /package/dst/{constant → native}/Boolean.d.ts +0 -0
- /package/dst/{constant → native}/Boolean.js +0 -0
- /package/dst/{constant → native}/Buffer.d.ts +0 -0
- /package/dst/{constant → native}/Buffer.js +0 -0
- /package/dst/{constant → native}/Enumerable.d.ts +0 -0
- /package/dst/{constant → native}/Enumerable.js +0 -0
- /package/dst/{constant → native}/Float.d.ts +0 -0
- /package/dst/{constant → native}/Float.js +0 -0
- /package/dst/{constant → native}/Integer.d.ts +0 -0
- /package/dst/{constant → native}/Integer.js +0 -0
- /package/dst/{constant → native}/Iterable.d.ts +0 -0
- /package/dst/{constant → native}/Iterable.js +0 -0
- /package/dst/{constant → native}/Number.d.ts +0 -0
- /package/dst/{constant → native}/Number.js +0 -0
- /package/dst/{constant → native}/Object.d.ts +0 -0
- /package/dst/{constant → native}/Object.js +0 -0
- /package/dst/{constant → native}/String.d.ts +0 -0
- /package/dst/{constant → native}/String.js +0 -0
- /package/dst/{constant → native}/Timestamp.d.ts +0 -0
- /package/dst/{constant → native}/Timestamp.js +0 -0
- /package/dst/{constant → native}/Unknown.d.ts +0 -0
- /package/dst/{constant → native}/Unknown.js +0 -0
- /package/dst/{constant → native}/notation/AN.d.ts +0 -0
- /package/dst/{constant → native}/notation/AN.js +0 -0
- /package/dst/{constant → native}/notation/JSON.d.ts +0 -0
- /package/dst/{constant → native}/notation/JSON.js +0 -0
package/dst/Affinirum.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { formatAN } from "./
|
|
2
|
-
import { funcOr, funcAnd, funcNot } from "./
|
|
3
|
-
import { funcAdd } from "./
|
|
4
|
-
import { funcAt, funcHas } from "./
|
|
5
|
-
import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower, funcNegate } from "./
|
|
6
|
-
import { funcCoalesce, funcEqual, funcNotEqual } from "./
|
|
1
|
+
import { formatAN } from "./native/notation/AN.js";
|
|
2
|
+
import { funcOr, funcAnd, funcNot } from "./native/Boolean.js";
|
|
3
|
+
import { funcAdd } from "./native/Aggregable.js";
|
|
4
|
+
import { funcAt, funcHas } from "./native/Iterable.js";
|
|
5
|
+
import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower, funcNegate } from "./native/Number.js";
|
|
6
|
+
import { funcCoalesce, funcEqual, funcNotEqual } from "./native/Unknown.js";
|
|
7
7
|
import { Constant } from "./Constant.js";
|
|
8
8
|
import { Variable } from "./Variable.js";
|
|
9
9
|
import { Type } from "./Type.js";
|
|
@@ -12,8 +12,8 @@ import { Constants } from "./Constants.js";
|
|
|
12
12
|
import { Functions } from "./Functions.js";
|
|
13
13
|
import { ArrayNode } from "./node/ArrayNode.js";
|
|
14
14
|
import { BlockNode } from "./node/BlockNode.js";
|
|
15
|
+
import { CallNode } from "./node/CallNode.js";
|
|
15
16
|
import { ConstantNode } from "./node/ConstantNode.js";
|
|
16
|
-
import { FunctionNode } from "./node/FunctionNode.js";
|
|
17
17
|
import { JumpNode } from "./node/JumpNode.js";
|
|
18
18
|
import { LoopNode } from "./node/LoopNode.js";
|
|
19
19
|
import { ObjectNode } from "./node/ObjectNode.js";
|
|
@@ -27,7 +27,7 @@ export class Affinirum {
|
|
|
27
27
|
_script;
|
|
28
28
|
_strict;
|
|
29
29
|
_root;
|
|
30
|
-
|
|
30
|
+
_varframes = new Map();
|
|
31
31
|
_variables = new Map();
|
|
32
32
|
_constants = new Map(Constants);
|
|
33
33
|
_functions = new Map(Functions);
|
|
@@ -94,12 +94,12 @@ export class Affinirum {
|
|
|
94
94
|
const variables = this._scope.variables();
|
|
95
95
|
for (const name in variables) {
|
|
96
96
|
if (!Object.prototype.hasOwnProperty.call(values, name)) {
|
|
97
|
-
this.
|
|
97
|
+
this._varframes.get(name)?.throwError(`undefined variable ${name}:\n`);
|
|
98
98
|
}
|
|
99
99
|
const variable = variables[name];
|
|
100
100
|
const value = values?.[name] ?? undefined;
|
|
101
101
|
if (!variable.type.match(Type.of(value))) {
|
|
102
|
-
this.
|
|
102
|
+
this._varframes.get(name)?.throwError(`unexpected type ${Type.of(value)} for variable ${name} of type ${variable.type}:\n`);
|
|
103
103
|
}
|
|
104
104
|
variable.value = value;
|
|
105
105
|
}
|
|
@@ -148,7 +148,7 @@ export class Affinirum {
|
|
|
148
148
|
let node = this._disjunction(state, scope);
|
|
149
149
|
while (state.operator === funcCoalesce) {
|
|
150
150
|
const fnode = new ConstantNode(state, state.operator);
|
|
151
|
-
node = new
|
|
151
|
+
node = new CallNode(state, fnode, [node, this._disjunction(state.next(), scope)]);
|
|
152
152
|
}
|
|
153
153
|
return node;
|
|
154
154
|
}
|
|
@@ -156,7 +156,7 @@ export class Affinirum {
|
|
|
156
156
|
let node = this._conjunction(state, scope);
|
|
157
157
|
while (state.operator === funcOr) {
|
|
158
158
|
const fnode = new ConstantNode(state, state.operator);
|
|
159
|
-
node = new
|
|
159
|
+
node = new CallNode(state, fnode, [node, this._conjunction(state.next(), scope)]);
|
|
160
160
|
}
|
|
161
161
|
return node;
|
|
162
162
|
}
|
|
@@ -164,7 +164,7 @@ export class Affinirum {
|
|
|
164
164
|
let node = this._negation(state, scope);
|
|
165
165
|
while (state.operator === funcAnd) {
|
|
166
166
|
const fnode = new ConstantNode(state, state.operator);
|
|
167
|
-
node = new
|
|
167
|
+
node = new CallNode(state, fnode, [node, this._negation(state.next(), scope)]);
|
|
168
168
|
}
|
|
169
169
|
return node;
|
|
170
170
|
}
|
|
@@ -179,7 +179,7 @@ export class Affinirum {
|
|
|
179
179
|
let node = this._comparison(state, scope);
|
|
180
180
|
if (negate) {
|
|
181
181
|
const fnode = new ConstantNode(frame, funcNot);
|
|
182
|
-
node = new
|
|
182
|
+
node = new CallNode(frame, fnode, [node]);
|
|
183
183
|
}
|
|
184
184
|
return node;
|
|
185
185
|
}
|
|
@@ -189,7 +189,7 @@ export class Affinirum {
|
|
|
189
189
|
|| state.operator === funcGreaterOrEqual || state.operator === funcLessOrEqual
|
|
190
190
|
|| state.operator === funcEqual || state.operator === funcNotEqual) {
|
|
191
191
|
const fnode = new ConstantNode(state, state.operator);
|
|
192
|
-
node = new
|
|
192
|
+
node = new CallNode(state, fnode, [node, this._aggregate(state.next(), scope)]);
|
|
193
193
|
}
|
|
194
194
|
return node;
|
|
195
195
|
}
|
|
@@ -197,7 +197,7 @@ export class Affinirum {
|
|
|
197
197
|
let node = this._product(state, scope);
|
|
198
198
|
while (state.operator === funcAdd || state.operator === funcSubtract) {
|
|
199
199
|
const fnode = new ConstantNode(state, state.operator);
|
|
200
|
-
node = new
|
|
200
|
+
node = new CallNode(state, fnode, [node, this._product(state.next(), scope)]);
|
|
201
201
|
}
|
|
202
202
|
return node;
|
|
203
203
|
}
|
|
@@ -205,7 +205,7 @@ export class Affinirum {
|
|
|
205
205
|
let node = this._signum(state, scope);
|
|
206
206
|
while (state.operator === funcMultiply || state.operator === funcDivide || state.operator === funcRemainder) {
|
|
207
207
|
const fnode = new ConstantNode(state, state.operator);
|
|
208
|
-
node = new
|
|
208
|
+
node = new CallNode(state, fnode, [node, this._signum(state.next(), scope)]);
|
|
209
209
|
}
|
|
210
210
|
return node;
|
|
211
211
|
}
|
|
@@ -222,7 +222,7 @@ export class Affinirum {
|
|
|
222
222
|
let node = this._factor(state, scope);
|
|
223
223
|
if (negate) {
|
|
224
224
|
const fnode = new ConstantNode(frame, funcNegate);
|
|
225
|
-
node = new
|
|
225
|
+
node = new CallNode(frame, fnode, [node]);
|
|
226
226
|
}
|
|
227
227
|
return node;
|
|
228
228
|
}
|
|
@@ -230,7 +230,7 @@ export class Affinirum {
|
|
|
230
230
|
let node = this._accessor(state, scope);
|
|
231
231
|
while (state.operator === funcPower) {
|
|
232
232
|
const fnode = new ConstantNode(state, state.operator);
|
|
233
|
-
node = new
|
|
233
|
+
node = new CallNode(state, fnode, [node, this._accessor(state.next(), scope)]);
|
|
234
234
|
}
|
|
235
235
|
return node;
|
|
236
236
|
}
|
|
@@ -238,11 +238,11 @@ export class Affinirum {
|
|
|
238
238
|
let node = this._term(state, scope);
|
|
239
239
|
while (state.isDot || state.isQuestion || state.isParenthesesOpen || state.isBracketsOpen) {
|
|
240
240
|
const frame = state.starts();
|
|
241
|
-
if (state.isDot || state.isQuestion) {
|
|
241
|
+
if (state.isDot || state.isQuestion) { // property access or property existance operator
|
|
242
242
|
const operator = state.isDot ? funcAt : funcHas;
|
|
243
243
|
if (state.next().isLiteral && (typeof state.literal.value === "string" || typeof state.literal.value === "bigint")) {
|
|
244
244
|
const fnode = new ConstantNode(frame.ends(state), operator);
|
|
245
|
-
node = new
|
|
245
|
+
node = new CallNode(frame, fnode, [node, new ConstantNode(state, new Constant(state.literal.value))]);
|
|
246
246
|
state.next();
|
|
247
247
|
}
|
|
248
248
|
else if (state.isToken) {
|
|
@@ -257,17 +257,17 @@ export class Affinirum {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
const fnode = new ConstantNode(frame.ends(state), func);
|
|
260
|
-
node = new
|
|
260
|
+
node = new CallNode(frame, fnode, subnodes);
|
|
261
261
|
state.closeParentheses().next();
|
|
262
262
|
}
|
|
263
263
|
else {
|
|
264
264
|
const fnode = new ConstantNode(frame.ends(state), func);
|
|
265
|
-
node = new
|
|
265
|
+
node = new CallNode(frame, fnode, [node]);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
else {
|
|
269
269
|
const fnode = new ConstantNode(frame.ends(), operator);
|
|
270
|
-
node = new
|
|
270
|
+
node = new CallNode(frame, fnode, [node, new ConstantNode(state, new Constant(state.token))]);
|
|
271
271
|
state.next();
|
|
272
272
|
}
|
|
273
273
|
}
|
|
@@ -275,7 +275,7 @@ export class Affinirum {
|
|
|
275
275
|
state.throwError("missing array index or object key");
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
else if (state.isParenthesesOpen) {
|
|
278
|
+
else if (state.isParenthesesOpen) { // function call
|
|
279
279
|
const subnodes = [];
|
|
280
280
|
while (!state.next().isParenthesesClose) {
|
|
281
281
|
subnodes.push(this._unit(state, scope));
|
|
@@ -283,25 +283,25 @@ export class Affinirum {
|
|
|
283
283
|
break;
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
node = new
|
|
286
|
+
node = new CallNode(frame.ends(state), node, subnodes);
|
|
287
287
|
state.closeParentheses().next();
|
|
288
288
|
}
|
|
289
|
-
else if (state.isBracketsOpen) {
|
|
289
|
+
else if (state.isBracketsOpen) { // index access operator
|
|
290
290
|
const fnode = new ConstantNode(frame, funcAt);
|
|
291
|
-
node = new
|
|
291
|
+
node = new CallNode(frame, fnode, [node, this._unit(state.next(), scope)]);
|
|
292
292
|
state.closeBrackets().next();
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
return node;
|
|
296
296
|
}
|
|
297
297
|
_term(state, scope) {
|
|
298
|
-
if (state.isLiteral) {
|
|
298
|
+
if (state.isLiteral) { // literal constant
|
|
299
299
|
const frame = state.starts();
|
|
300
300
|
const constant = new Constant(state.literal.value);
|
|
301
301
|
state.next();
|
|
302
302
|
return new ConstantNode(frame, constant);
|
|
303
303
|
}
|
|
304
|
-
else if (state.isToken) {
|
|
304
|
+
else if (state.isToken) { // variable
|
|
305
305
|
const frame = state.starts();
|
|
306
306
|
const constants = this._constants.get(state.token);
|
|
307
307
|
if (constants != null) {
|
|
@@ -331,8 +331,8 @@ export class Affinirum {
|
|
|
331
331
|
}
|
|
332
332
|
scope.global(state.token, variable);
|
|
333
333
|
}
|
|
334
|
-
if (!this.
|
|
335
|
-
this.
|
|
334
|
+
if (!this._varframes.has(state.token)) {
|
|
335
|
+
this._varframes.set(state.token, state.starts());
|
|
336
336
|
}
|
|
337
337
|
if (state.next().isAssignment) {
|
|
338
338
|
if (!variable.assignable) {
|
|
@@ -341,7 +341,7 @@ export class Affinirum {
|
|
|
341
341
|
if (state.assignment.operator) {
|
|
342
342
|
const operator = state.assignment.operator;
|
|
343
343
|
const fnode = new ConstantNode(frame, operator);
|
|
344
|
-
const subnode = new
|
|
344
|
+
const subnode = new CallNode(frame, fnode, [new VariableNode(frame, variable), this._unit(state.next(), scope)]);
|
|
345
345
|
return new VariableNode(frame, variable, subnode);
|
|
346
346
|
}
|
|
347
347
|
else {
|
|
@@ -351,7 +351,7 @@ export class Affinirum {
|
|
|
351
351
|
}
|
|
352
352
|
return new VariableNode(frame, variable);
|
|
353
353
|
}
|
|
354
|
-
else if (state.isBracesOpen) {
|
|
354
|
+
else if (state.isBracesOpen) { // code block
|
|
355
355
|
const frame = state.starts();
|
|
356
356
|
const subnodes = [];
|
|
357
357
|
while (!state.next().isBracesClose) {
|
|
@@ -367,7 +367,7 @@ export class Affinirum {
|
|
|
367
367
|
else if (state.isBracesClose) {
|
|
368
368
|
state.throwError("unexpected closing braces");
|
|
369
369
|
}
|
|
370
|
-
else if (state.isParenthesesOpen) {
|
|
370
|
+
else if (state.isParenthesesOpen) { // unit grouping
|
|
371
371
|
const node = this._unit(state.next(), scope);
|
|
372
372
|
state.closeParentheses().next();
|
|
373
373
|
return node;
|
|
@@ -375,7 +375,7 @@ export class Affinirum {
|
|
|
375
375
|
else if (state.isParenthesesClose) {
|
|
376
376
|
state.throwError("unexpected closing parentheses");
|
|
377
377
|
}
|
|
378
|
-
else if (state.isBracketsOpen) {
|
|
378
|
+
else if (state.isBracketsOpen) { // array or object
|
|
379
379
|
const frame = state.starts();
|
|
380
380
|
const subnodes = [];
|
|
381
381
|
let index = 0, colon = false;
|
|
@@ -407,7 +407,7 @@ export class Affinirum {
|
|
|
407
407
|
else if (state.isBracketsClose) {
|
|
408
408
|
state.throwError("unexpected closing brackets");
|
|
409
409
|
}
|
|
410
|
-
else if (state.isVar || state.isVal) {
|
|
410
|
+
else if (state.isVar || state.isVal) { // variable declaration
|
|
411
411
|
const assignable = state.isVar;
|
|
412
412
|
if (!state.next().isToken) {
|
|
413
413
|
state.throwError("missing variable name");
|
|
@@ -462,12 +462,8 @@ export class Affinirum {
|
|
|
462
462
|
state.throwError("unexpected expression token");
|
|
463
463
|
}
|
|
464
464
|
_function(state, scope) {
|
|
465
|
+
state.next().openParentheses();
|
|
465
466
|
const frame = state.starts();
|
|
466
|
-
let retType = Type.Unknown;
|
|
467
|
-
if (!state.next().isParenthesesOpen) {
|
|
468
|
-
retType = this._type(state, scope);
|
|
469
|
-
state.openParentheses();
|
|
470
|
-
}
|
|
471
467
|
let variadic = false;
|
|
472
468
|
const variables = new Map();
|
|
473
469
|
while (!state.next().isParenthesesClose) {
|
|
@@ -499,10 +495,11 @@ export class Affinirum {
|
|
|
499
495
|
break;
|
|
500
496
|
}
|
|
501
497
|
}
|
|
502
|
-
state.closeParentheses();
|
|
498
|
+
state.closeParentheses().next();
|
|
499
|
+
const retType = state.isColon ? this._type(state.next(), scope) : Type.Unknown;
|
|
503
500
|
frame.ends(state);
|
|
504
501
|
const args = Array.from(variables.values());
|
|
505
|
-
const subnode = this._unit(state
|
|
502
|
+
const subnode = this._unit(state, scope.subscope(variables));
|
|
506
503
|
const func = (...values) => {
|
|
507
504
|
args.forEach((arg, ix) => arg.value = values[ix]);
|
|
508
505
|
return subnode.evaluate();
|
|
@@ -527,7 +524,7 @@ export class Affinirum {
|
|
|
527
524
|
return new SwitchNode(frame, cnode, [cthen, celse]);
|
|
528
525
|
}
|
|
529
526
|
_type(state, scope) {
|
|
530
|
-
if (state.isType) {
|
|
527
|
+
if (state.isType) { // literal type
|
|
531
528
|
let type = state.type;
|
|
532
529
|
if (state.next().isQuestion) {
|
|
533
530
|
type = type.toOptional();
|
|
@@ -561,11 +558,7 @@ export class Affinirum {
|
|
|
561
558
|
: Type.arrayType(itemKeyTypes.map(([, v]) => v));
|
|
562
559
|
}
|
|
563
560
|
else if (state.isTilda) { // function type
|
|
564
|
-
|
|
565
|
-
if (!state.next().isParenthesesOpen) {
|
|
566
|
-
retType = this._type(state, scope);
|
|
567
|
-
state.openParentheses();
|
|
568
|
-
}
|
|
561
|
+
state.next().openParentheses();
|
|
569
562
|
let variadic = false;
|
|
570
563
|
const argTypes = [];
|
|
571
564
|
while (!state.next().isParenthesesClose) {
|
|
@@ -588,11 +581,14 @@ export class Affinirum {
|
|
|
588
581
|
}
|
|
589
582
|
}
|
|
590
583
|
state.closeParentheses().next();
|
|
591
|
-
|
|
592
|
-
retType = Type.Unknown;
|
|
593
|
-
}
|
|
584
|
+
const retType = state.isColon ? this._type(state.next(), scope) : Type.Unknown;
|
|
594
585
|
return Type.functionType(retType, argTypes, variadic);
|
|
595
586
|
}
|
|
587
|
+
else if (state.isParenthesesOpen) { // type grouping
|
|
588
|
+
const type = this._type(state.next(), scope);
|
|
589
|
+
state.closeParentheses().next();
|
|
590
|
+
return type;
|
|
591
|
+
}
|
|
596
592
|
else {
|
|
597
593
|
state.throwError("missing type name");
|
|
598
594
|
}
|
package/dst/Constants.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { constArray } from "./
|
|
2
|
-
import { constBoolean } from "./
|
|
3
|
-
import { constBuffer } from "./
|
|
4
|
-
import { constInteger } from "./
|
|
5
|
-
import { constFloat } from "./
|
|
6
|
-
import { constObject } from "./
|
|
7
|
-
import { constString } from "./
|
|
8
|
-
import { constTimestamp } from "./
|
|
9
|
-
import { constAN } from "./
|
|
10
|
-
import { constJSON } from "./
|
|
1
|
+
import { constArray } from "./native/Array.js";
|
|
2
|
+
import { constBoolean } from "./native/Boolean.js";
|
|
3
|
+
import { constBuffer } from "./native/Buffer.js";
|
|
4
|
+
import { constInteger } from "./native/Integer.js";
|
|
5
|
+
import { constFloat } from "./native/Float.js";
|
|
6
|
+
import { constObject } from "./native/Object.js";
|
|
7
|
+
import { constString } from "./native/String.js";
|
|
8
|
+
import { constTimestamp } from "./native/Timestamp.js";
|
|
9
|
+
import { constAN } from "./native/notation/AN.js";
|
|
10
|
+
import { constJSON } from "./native/notation/JSON.js";
|
|
11
11
|
export const Constants = [
|
|
12
12
|
["Array", constArray],
|
|
13
13
|
["Boolean", constBoolean],
|
package/dst/Functions.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { funcAdd } from "./
|
|
2
|
-
import { funcFirst, funcLast, funcFirstIndex, funcLastIndex, funcEvery, funcAny, funcFlatten, funcReverse, funcDerive, funcFilter, funcReduce, funcCompose, funcPrepend, funcAppend } from "./
|
|
3
|
-
import { funcByte } from "./
|
|
4
|
-
import { funcSlice, funcSplice, funcInject } from "./
|
|
5
|
-
import { funcLength, funcContains, funcAt, funcHas } from "./
|
|
6
|
-
import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcModulo, funcPower, funcRoot, funcNegate, funcCast, funcCastToFloat, funcCastToInteger } from "./
|
|
7
|
-
import { funcEntries, funcKeys, funcValues } from "./
|
|
8
|
-
import { funcLike, funcUnlike, funcStartsWith, funcEndsWith, funcChar, funcCharCode, funcTrim, funcTrimStart, funcTrimEnd, funcLowerCase, funcUpperCase, funcSplit, funcReplaceWith } from "./
|
|
9
|
-
import { funcYear, funcMonth, funcMonthIndex, funcWeekdayIndex, funcDay, funcHour, funcMinute, funcSecond, funcMillisecond, funcEpochTime, funcDaysSince, funcHoursSince, funcMinutesSince, funcSecondsSince } from "./
|
|
10
|
-
import { funcCoalesce, funcEqual, funcNotEqual, funcEncode, funcFormat } from "./
|
|
1
|
+
import { funcAdd } from "./native/Aggregable.js";
|
|
2
|
+
import { funcFirst, funcLast, funcFirstIndex, funcLastIndex, funcEvery, funcAny, funcFlatten, funcReverse, funcDerive, funcFilter, funcReduce, funcCompose, funcPrepend, funcAppend } from "./native/Array.js";
|
|
3
|
+
import { funcByte } from "./native/Buffer.js";
|
|
4
|
+
import { funcSlice, funcSplice, funcInject } from "./native/Enumerable.js";
|
|
5
|
+
import { funcLength, funcContains, funcAt, funcHas } from "./native/Iterable.js";
|
|
6
|
+
import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcModulo, funcPower, funcRoot, funcNegate, funcCast, funcCastToFloat, funcCastToInteger } from "./native/Number.js";
|
|
7
|
+
import { funcEntries, funcKeys, funcValues } from "./native/Object.js";
|
|
8
|
+
import { funcLike, funcUnlike, funcStartsWith, funcEndsWith, funcChar, funcCharCode, funcTrim, funcTrimStart, funcTrimEnd, funcLowerCase, funcUpperCase, funcSplit, funcReplaceWith } from "./native/String.js";
|
|
9
|
+
import { funcYear, funcMonth, funcMonthIndex, funcWeekdayIndex, funcDay, funcHour, funcMinute, funcSecond, funcMillisecond, funcEpochTime, funcDaysSince, funcHoursSince, funcMinutesSince, funcSecondsSince } from "./native/Timestamp.js";
|
|
10
|
+
import { funcCoalesce, funcEqual, funcNotEqual, funcEncode, funcFormat } from "./native/Unknown.js";
|
|
11
11
|
export const Functions = [
|
|
12
12
|
// Aggregable
|
|
13
13
|
["Add", funcAdd],
|
package/dst/ParserState.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { funcOr, funcAnd, funcNot } from "./
|
|
2
|
-
import { parseBuffer } from "./
|
|
3
|
-
import { funcAdd } from "./
|
|
4
|
-
import { isSignSymbol, isTokenStartSymbol, isNumericSymbol, isTokenSymbol, isDateSymbol, isTimeSymbol, isDateTimeSeparatorSymbol, replaceWith } from "./
|
|
1
|
+
import { funcOr, funcAnd, funcNot } from "./native/Boolean.js";
|
|
2
|
+
import { parseBuffer } from "./native/Buffer.js";
|
|
3
|
+
import { funcAdd } from "./native/Aggregable.js";
|
|
4
|
+
import { isSignSymbol, isTokenStartSymbol, isNumericSymbol, isTokenSymbol, isDateSymbol, isTimeSymbol, isDateTimeSeparatorSymbol, replaceWith } from "./native/String.js";
|
|
5
5
|
import { Constant } from "./Constant.js";
|
|
6
|
-
import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower } from "./
|
|
7
|
-
import { funcCoalesce, funcEqual, funcNotEqual } from "./
|
|
6
|
+
import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower } from "./native/Number.js";
|
|
7
|
+
import { funcCoalesce, funcEqual, funcNotEqual } from "./native/Unknown.js";
|
|
8
8
|
import { Type } from "./Type.js";
|
|
9
9
|
import { ParserFrame } from "./ParserFrame.js";
|
|
10
10
|
class Literal {
|
|
@@ -381,7 +381,7 @@ export class ParserState extends ParserFrame {
|
|
|
381
381
|
this._fragment = funcDivideAssignment;
|
|
382
382
|
break;
|
|
383
383
|
case "/":
|
|
384
|
-
if (this._expr.charAt(++this._end) ===
|
|
384
|
+
if (this._expr.charAt(++this._end) === "/") {
|
|
385
385
|
++this._end;
|
|
386
386
|
while (this._expr.charAt(this._end) !== ""
|
|
387
387
|
&& (this._expr.charAt(this._end) !== c
|
|
@@ -391,7 +391,7 @@ export class ParserState extends ParserFrame {
|
|
|
391
391
|
}
|
|
392
392
|
if (this._end >= this._expr.length) {
|
|
393
393
|
this._start = this._expr.length;
|
|
394
|
-
throw new Error(
|
|
394
|
+
throw new Error("missing closing comment mark");
|
|
395
395
|
}
|
|
396
396
|
++this._end;
|
|
397
397
|
}
|
package/dst/atom/ArrayAtom.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { IAtom } from "../Atom.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
export declare class ArrayAtom implements IAtom {
|
|
4
|
-
protected readonly
|
|
5
|
-
constructor(
|
|
4
|
+
protected readonly _valTypes: Type[];
|
|
5
|
+
constructor(_valTypes?: Type[]);
|
|
6
6
|
private get _undefined();
|
|
7
7
|
subtypes(): Type[];
|
|
8
|
-
|
|
8
|
+
valueType(index: number): Type | undefined;
|
|
9
9
|
match(atom: IAtom): boolean;
|
|
10
10
|
weight(): number;
|
|
11
11
|
toString(): string;
|
package/dst/atom/ArrayAtom.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
export class ArrayAtom {
|
|
2
|
-
|
|
3
|
-
constructor(
|
|
4
|
-
this.
|
|
2
|
+
_valTypes;
|
|
3
|
+
constructor(_valTypes = []) {
|
|
4
|
+
this._valTypes = _valTypes;
|
|
5
5
|
}
|
|
6
6
|
get _undefined() {
|
|
7
|
-
return this.
|
|
7
|
+
return this._valTypes.length === 0;
|
|
8
8
|
}
|
|
9
9
|
subtypes() {
|
|
10
|
-
return this.
|
|
10
|
+
return this._valTypes;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
return this.
|
|
12
|
+
valueType(index) {
|
|
13
|
+
return this._valTypes[index];
|
|
14
14
|
}
|
|
15
15
|
match(atom) {
|
|
16
16
|
if (atom instanceof ArrayAtom) {
|
|
17
17
|
if (this._undefined || atom._undefined) {
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < this._itemTypes.length; ++i) {
|
|
24
|
-
if (!this._itemTypes[i].match(atom._itemTypes[i])) {
|
|
20
|
+
for (let i = 0; i < this._valTypes.length; ++i) {
|
|
21
|
+
const vtype = atom.valueType(i);
|
|
22
|
+
if (!vtype || !this._valTypes[i].match(vtype)) {
|
|
25
23
|
return false;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
@@ -33,6 +31,9 @@ export class ArrayAtom {
|
|
|
33
31
|
return 0x10000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
|
|
34
32
|
}
|
|
35
33
|
toString() {
|
|
36
|
-
|
|
34
|
+
if (this._undefined) {
|
|
35
|
+
return "array";
|
|
36
|
+
}
|
|
37
|
+
return `[${this._valTypes.join(",")}]`;
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -12,7 +12,7 @@ export declare class FunctionAtom implements IAtom {
|
|
|
12
12
|
get maxArity(): number;
|
|
13
13
|
get isVariadic(): boolean;
|
|
14
14
|
get arity(): number;
|
|
15
|
-
argType(index: number): Type;
|
|
15
|
+
argType(index: number): Type | undefined;
|
|
16
16
|
match(atom: IAtom): boolean;
|
|
17
17
|
weight(): number;
|
|
18
18
|
toString(): string;
|
package/dst/atom/FunctionAtom.js
CHANGED
|
@@ -41,7 +41,7 @@ export class FunctionAtom {
|
|
|
41
41
|
return this._argTypes.length;
|
|
42
42
|
}
|
|
43
43
|
argType(index) {
|
|
44
|
-
return this._argTypes[index] ?? this._argTypes[this._argTypes.length - 1]
|
|
44
|
+
return this._argTypes[index] ?? (this._isVariadic ? this._argTypes[this._argTypes.length - 1] : undefined);
|
|
45
45
|
}
|
|
46
46
|
match(atom) {
|
|
47
47
|
if (atom instanceof FunctionAtom) {
|
|
@@ -51,8 +51,10 @@ export class FunctionAtom {
|
|
|
51
51
|
if (!this._retType.match(atom._retType) || this.minArity > atom.maxArity || this.maxArity < atom.minArity) {
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const argc = Math.max(this.minArity, atom.minArity);
|
|
55
|
+
for (let i = 0; i < argc; ++i) {
|
|
56
|
+
const atype = atom.argType(i);
|
|
57
|
+
if (!atype || !this.argType(i)?.match(atype)) {
|
|
56
58
|
return false;
|
|
57
59
|
}
|
|
58
60
|
}
|
|
@@ -64,10 +66,10 @@ export class FunctionAtom {
|
|
|
64
66
|
return 0x1000000000000 + (this._retType ? [this._retType, ...this._argTypes] : []).reduce((acc, i) => acc + i.weight(), 0);
|
|
65
67
|
}
|
|
66
68
|
toString() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}).join(",");
|
|
71
|
-
return
|
|
69
|
+
if (this._undefined) {
|
|
70
|
+
return "function";
|
|
71
|
+
}
|
|
72
|
+
const argTypes = this._argTypes.map((i, ix) => ix === this._argTypes.length - 1 && this.isVariadic ? `...${i.toString()}` : i.toString()).join(",");
|
|
73
|
+
return `~(${argTypes}):${this._retType.toString()}`;
|
|
72
74
|
}
|
|
73
75
|
}
|
package/dst/atom/ObjectAtom.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { IAtom } from "../Atom.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
export declare class ObjectAtom implements IAtom {
|
|
4
|
-
protected readonly
|
|
5
|
-
constructor(
|
|
4
|
+
protected readonly _valTypes: Record<string, Type>;
|
|
5
|
+
constructor(_valTypes?: Record<string, Type>);
|
|
6
6
|
private get _undefined();
|
|
7
7
|
subtypes(): Type[];
|
|
8
|
-
|
|
8
|
+
valueType(key: string): Type | undefined;
|
|
9
9
|
match(atom: IAtom): boolean;
|
|
10
10
|
weight(): number;
|
|
11
11
|
toString(): string;
|
package/dst/atom/ObjectAtom.js
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
export class ObjectAtom {
|
|
2
|
-
|
|
3
|
-
constructor(
|
|
4
|
-
this.
|
|
2
|
+
_valTypes;
|
|
3
|
+
constructor(_valTypes = {}) {
|
|
4
|
+
this._valTypes = _valTypes;
|
|
5
5
|
}
|
|
6
6
|
get _undefined() {
|
|
7
|
-
return Object.keys(this.
|
|
7
|
+
return Object.keys(this._valTypes).length === 0;
|
|
8
8
|
}
|
|
9
9
|
subtypes() {
|
|
10
|
-
return Object.values(this.
|
|
10
|
+
return Object.values(this._valTypes);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
return this.
|
|
12
|
+
valueType(key) {
|
|
13
|
+
return this._valTypes[key];
|
|
14
14
|
}
|
|
15
15
|
match(atom) {
|
|
16
16
|
if (atom instanceof ObjectAtom) {
|
|
17
17
|
if (this._undefined || atom._undefined) {
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
20
|
-
for (const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
if (!this._propTypes[prop].match(atom._propTypes[prop])) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
for (const prop in atom._propTypes) {
|
|
29
|
-
if (!this.propType(prop)) {
|
|
20
|
+
for (const key in this._valTypes) {
|
|
21
|
+
const vtype = atom.valueType(key);
|
|
22
|
+
if (!vtype || !this._valTypes[key].match(vtype)) {
|
|
30
23
|
return false;
|
|
31
24
|
}
|
|
32
25
|
}
|
|
@@ -38,6 +31,9 @@ export class ObjectAtom {
|
|
|
38
31
|
return 0x100000000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
|
|
39
32
|
}
|
|
40
33
|
toString() {
|
|
41
|
-
|
|
34
|
+
if (this._undefined) {
|
|
35
|
+
return "object";
|
|
36
|
+
}
|
|
37
|
+
return `[${Object.entries(this._valTypes).map(([k, v]) => `"${k}":${v}`).join(",")}]`;
|
|
42
38
|
}
|
|
43
39
|
}
|
|
@@ -14,13 +14,13 @@ export class PrimitiveAtom {
|
|
|
14
14
|
}
|
|
15
15
|
weight() {
|
|
16
16
|
switch (this._primitive) {
|
|
17
|
-
case "void": return
|
|
17
|
+
case "void": return 0x1;
|
|
18
18
|
case "boolean": return 0x2;
|
|
19
|
-
case "timestamp": return
|
|
19
|
+
case "timestamp": return 0x4;
|
|
20
20
|
case "float": return 0x8;
|
|
21
21
|
case "integer": return 0x10;
|
|
22
22
|
case "buffer": return 0x20;
|
|
23
|
-
case "string": return
|
|
23
|
+
case "string": return 0x40;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
toString() {
|