affinirum 1.5.2 → 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/README.md +12 -2
- package/dst/Affinirum.d.ts +22 -22
- package/dst/Affinirum.js +88 -80
- package/dst/CallFrame.d.ts +11 -0
- package/dst/CallFrame.js +35 -0
- package/dst/LexicalScope.d.ts +15 -0
- package/dst/LexicalScope.js +31 -0
- package/dst/Node.d.ts +5 -4
- package/dst/Node.js +5 -5
- package/dst/ParserState.d.ts +3 -3
- package/dst/ParserState.js +40 -40
- package/dst/ScriptSpan.d.ts +10 -0
- package/dst/{ParserFrame.js → ScriptSpan.js} +20 -31
- package/dst/Type.d.ts +2 -0
- package/dst/Type.js +2 -0
- package/dst/Variable.d.ts +0 -4
- package/dst/Variable.js +0 -7
- package/dst/cjs/Affinirum.d.ts +88 -0
- package/dst/cjs/Affinirum.js +88 -80
- package/dst/cjs/Atom.d.ts +7 -0
- package/dst/cjs/CallFrame.d.ts +11 -0
- package/dst/cjs/CallFrame.js +39 -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 +35 -0
- package/dst/cjs/Node.d.ts +14 -0
- package/dst/cjs/Node.js +5 -5
- package/dst/cjs/ParserState.d.ts +60 -0
- package/dst/cjs/ParserState.js +40 -40
- package/dst/cjs/ScriptSpan.d.ts +10 -0
- package/dst/cjs/{ParserFrame.js → ScriptSpan.js} +22 -33
- package/dst/cjs/Type.d.ts +71 -0
- package/dst/cjs/Type.js +2 -0
- package/dst/cjs/Value.d.ts +5 -0
- package/dst/cjs/Variable.d.ts +9 -0
- package/dst/cjs/Variable.js +0 -7
- 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 +25 -12
- 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/AN.js +2 -2
- 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/ArrayNode.js +4 -11
- package/dst/cjs/node/BlockNode.d.ts +15 -0
- package/dst/cjs/node/BlockNode.js +10 -6
- package/dst/cjs/node/CallNode.d.ts +15 -0
- package/dst/cjs/node/CallNode.js +15 -28
- package/dst/cjs/node/CastNode.d.ts +16 -0
- package/dst/cjs/node/CastNode.js +4 -4
- package/dst/cjs/node/ConstantNode.d.ts +17 -0
- package/dst/cjs/node/ConstantNode.js +7 -5
- package/dst/cjs/node/JumpNode.d.ts +16 -0
- package/dst/cjs/node/JumpNode.js +10 -6
- package/dst/cjs/node/LoopNode.d.ts +14 -0
- package/dst/cjs/node/LoopNode.js +5 -5
- package/dst/cjs/node/ObjectNode.d.ts +14 -0
- package/dst/cjs/node/ObjectNode.js +6 -12
- package/dst/cjs/node/SwitchNode.d.ts +15 -0
- package/dst/cjs/node/SwitchNode.js +8 -7
- package/dst/cjs/node/VariableNode.d.ts +15 -0
- package/dst/cjs/node/VariableNode.js +5 -5
- package/dst/cjs/node/VariadicNode.d.ts +4 -0
- package/dst/cjs/node/VariadicNode.js +10 -0
- package/dst/native/Buffer.js +1 -1
- package/dst/native/Number.js +25 -12
- package/dst/native/String.js +97 -48
- package/dst/native/Unknown.js +10 -1
- package/dst/native/notation/AN.js +2 -2
- package/dst/node/ArrayNode.d.ts +4 -3
- package/dst/node/ArrayNode.js +4 -11
- package/dst/node/BlockNode.d.ts +6 -3
- package/dst/node/BlockNode.js +10 -6
- package/dst/node/CallNode.d.ts +4 -3
- package/dst/node/CallNode.js +15 -28
- package/dst/node/CastNode.d.ts +4 -3
- package/dst/node/CastNode.js +4 -4
- package/dst/node/ConstantNode.d.ts +5 -3
- package/dst/node/ConstantNode.js +7 -5
- package/dst/node/JumpNode.d.ts +5 -3
- package/dst/node/JumpNode.js +10 -6
- package/dst/node/LoopNode.d.ts +4 -3
- package/dst/node/LoopNode.js +5 -5
- package/dst/node/ObjectNode.d.ts +4 -3
- package/dst/node/ObjectNode.js +6 -12
- package/dst/node/SwitchNode.d.ts +4 -3
- package/dst/node/SwitchNode.js +8 -7
- package/dst/node/VariableNode.d.ts +4 -3
- package/dst/node/VariableNode.js +5 -5
- package/dst/node/VariadicNode.d.ts +4 -0
- package/dst/node/VariadicNode.js +6 -0
- package/package.json +10 -9
- package/dst/ParserFrame.d.ts +0 -13
- package/dst/Scope.d.ts +0 -16
- package/dst/Scope.js +0 -49
- package/dst/cjs/Scope.js +0 -53
package/dst/Node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class Node extends
|
|
3
|
-
constructor(
|
|
4
|
-
super(
|
|
1
|
+
import { ScriptSpan } from "./ScriptSpan.js";
|
|
2
|
+
export class Node extends ScriptSpan {
|
|
3
|
+
constructor(span) {
|
|
4
|
+
super(span);
|
|
5
5
|
}
|
|
6
6
|
get constant() {
|
|
7
7
|
return false;
|
|
@@ -17,6 +17,6 @@ export class Node extends ParserFrame {
|
|
|
17
17
|
return this.throwError(`type ${this.type} mismatch with expected type ${type}`);
|
|
18
18
|
}
|
|
19
19
|
toString(ident = 0) {
|
|
20
|
-
return " ".repeat(ident) + `[${this._start}:${this.
|
|
20
|
+
return " ".repeat(ident) + `[${this._start}:${this._end}] <${this.type}>`;
|
|
21
21
|
}
|
|
22
22
|
}
|
package/dst/ParserState.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Constant } from "./Constant.js";
|
|
2
2
|
import { Value } from "./Value.js";
|
|
3
3
|
import { Type } from "./Type.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ScriptSpan } from "./ScriptSpan.js";
|
|
5
5
|
declare class Literal {
|
|
6
6
|
readonly value: Value;
|
|
7
7
|
constructor(value: Value);
|
|
@@ -10,9 +10,9 @@ declare class Assignment {
|
|
|
10
10
|
readonly operator?: Constant | undefined;
|
|
11
11
|
constructor(operator?: Constant | undefined);
|
|
12
12
|
}
|
|
13
|
-
export declare class ParserState extends
|
|
13
|
+
export declare class ParserState extends ScriptSpan {
|
|
14
14
|
protected _fragment: Literal | Assignment | Constant | Type | symbol | string | undefined;
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(script: string);
|
|
16
16
|
get literal(): Literal;
|
|
17
17
|
get assignment(): Assignment;
|
|
18
18
|
get operator(): Constant;
|
package/dst/ParserState.js
CHANGED
|
@@ -7,7 +7,7 @@ import { isTokenStartSymbol, isTokenSymbol, parseLiteralString } from "./native/
|
|
|
7
7
|
import { parseLiteralTimestamp } from "./native/Timestamp.js";
|
|
8
8
|
import { Constant } from "./Constant.js";
|
|
9
9
|
import { Type } from "./Type.js";
|
|
10
|
-
import {
|
|
10
|
+
import { ScriptSpan } from "./ScriptSpan.js";
|
|
11
11
|
class Literal {
|
|
12
12
|
value;
|
|
13
13
|
constructor(value) {
|
|
@@ -54,10 +54,10 @@ const idExit = Symbol();
|
|
|
54
54
|
const idReturn = Symbol();
|
|
55
55
|
const idStop = Symbol();
|
|
56
56
|
const idNext = Symbol();
|
|
57
|
-
export class ParserState extends
|
|
57
|
+
export class ParserState extends ScriptSpan {
|
|
58
58
|
_fragment;
|
|
59
|
-
constructor(
|
|
60
|
-
super(
|
|
59
|
+
constructor(script) {
|
|
60
|
+
super(script);
|
|
61
61
|
}
|
|
62
62
|
get literal() {
|
|
63
63
|
return this._fragment;
|
|
@@ -204,7 +204,7 @@ export class ParserState extends ParserFrame {
|
|
|
204
204
|
return this;
|
|
205
205
|
}
|
|
206
206
|
clone() {
|
|
207
|
-
const state = new ParserState(this.
|
|
207
|
+
const state = new ParserState(this._script);
|
|
208
208
|
state._start = this._start;
|
|
209
209
|
state._end = this._end;
|
|
210
210
|
state._fragment = this._fragment;
|
|
@@ -212,9 +212,9 @@ export class ParserState extends ParserFrame {
|
|
|
212
212
|
}
|
|
213
213
|
next() {
|
|
214
214
|
this._fragment = undefined;
|
|
215
|
-
while (this._end < this.
|
|
215
|
+
while (this._end < this._script.length && this._fragment == null) {
|
|
216
216
|
this._start = this._end;
|
|
217
|
-
const c = this.
|
|
217
|
+
const c = this._script.charAt(this._end);
|
|
218
218
|
++this._end;
|
|
219
219
|
switch (c) {
|
|
220
220
|
case " ":
|
|
@@ -245,7 +245,7 @@ export class ParserState extends ParserFrame {
|
|
|
245
245
|
this._fragment = idSemicolon;
|
|
246
246
|
break;
|
|
247
247
|
case ":":
|
|
248
|
-
switch (this.
|
|
248
|
+
switch (this._script.charAt(this._end)) {
|
|
249
249
|
case ":":
|
|
250
250
|
++this._end;
|
|
251
251
|
this._fragment = idCast;
|
|
@@ -259,7 +259,7 @@ export class ParserState extends ParserFrame {
|
|
|
259
259
|
this._fragment = idComma;
|
|
260
260
|
break;
|
|
261
261
|
case "~":
|
|
262
|
-
switch (this.
|
|
262
|
+
switch (this._script.charAt(this._end)) {
|
|
263
263
|
case ">":
|
|
264
264
|
++this._end;
|
|
265
265
|
this._fragment = idReturn;
|
|
@@ -270,7 +270,7 @@ export class ParserState extends ParserFrame {
|
|
|
270
270
|
}
|
|
271
271
|
break;
|
|
272
272
|
case "?":
|
|
273
|
-
switch (this.
|
|
273
|
+
switch (this._script.charAt(this._end)) {
|
|
274
274
|
case "?":
|
|
275
275
|
++this._end;
|
|
276
276
|
this._fragment = Type.Unknown;
|
|
@@ -285,7 +285,7 @@ export class ParserState extends ParserFrame {
|
|
|
285
285
|
}
|
|
286
286
|
break;
|
|
287
287
|
case "|":
|
|
288
|
-
switch (this.
|
|
288
|
+
switch (this._script.charAt(this._end)) {
|
|
289
289
|
case "=":
|
|
290
290
|
++this._end;
|
|
291
291
|
this._fragment = funcOrAssignment;
|
|
@@ -296,7 +296,7 @@ export class ParserState extends ParserFrame {
|
|
|
296
296
|
}
|
|
297
297
|
break;
|
|
298
298
|
case "&":
|
|
299
|
-
switch (this.
|
|
299
|
+
switch (this._script.charAt(this._end)) {
|
|
300
300
|
case "=":
|
|
301
301
|
++this._end;
|
|
302
302
|
this._fragment = funcAndAssignment;
|
|
@@ -307,7 +307,7 @@ export class ParserState extends ParserFrame {
|
|
|
307
307
|
}
|
|
308
308
|
break;
|
|
309
309
|
case ">":
|
|
310
|
-
switch (this.
|
|
310
|
+
switch (this._script.charAt(this._end)) {
|
|
311
311
|
case "=":
|
|
312
312
|
++this._end;
|
|
313
313
|
this._fragment = funcGreaterOrEqual;
|
|
@@ -318,7 +318,7 @@ export class ParserState extends ParserFrame {
|
|
|
318
318
|
}
|
|
319
319
|
break;
|
|
320
320
|
case "<":
|
|
321
|
-
switch (this.
|
|
321
|
+
switch (this._script.charAt(this._end)) {
|
|
322
322
|
case "=":
|
|
323
323
|
++this._end;
|
|
324
324
|
this._fragment = funcLessOrEqual;
|
|
@@ -329,7 +329,7 @@ export class ParserState extends ParserFrame {
|
|
|
329
329
|
}
|
|
330
330
|
break;
|
|
331
331
|
case "!":
|
|
332
|
-
switch (this.
|
|
332
|
+
switch (this._script.charAt(this._end)) {
|
|
333
333
|
case "=":
|
|
334
334
|
++this._end;
|
|
335
335
|
this._fragment = funcNotEqual;
|
|
@@ -340,7 +340,7 @@ export class ParserState extends ParserFrame {
|
|
|
340
340
|
}
|
|
341
341
|
break;
|
|
342
342
|
case "=":
|
|
343
|
-
switch (this.
|
|
343
|
+
switch (this._script.charAt(this._end)) {
|
|
344
344
|
case "=":
|
|
345
345
|
++this._end;
|
|
346
346
|
this._fragment = funcEqual;
|
|
@@ -355,7 +355,7 @@ export class ParserState extends ParserFrame {
|
|
|
355
355
|
}
|
|
356
356
|
break;
|
|
357
357
|
case "+":
|
|
358
|
-
switch (this.
|
|
358
|
+
switch (this._script.charAt(this._end)) {
|
|
359
359
|
case "=":
|
|
360
360
|
++this._end;
|
|
361
361
|
this._fragment = funcAddAssignment;
|
|
@@ -366,7 +366,7 @@ export class ParserState extends ParserFrame {
|
|
|
366
366
|
}
|
|
367
367
|
break;
|
|
368
368
|
case "-":
|
|
369
|
-
switch (this.
|
|
369
|
+
switch (this._script.charAt(this._end)) {
|
|
370
370
|
case "=":
|
|
371
371
|
++this._end;
|
|
372
372
|
this._fragment = funcSubtractAssignment;
|
|
@@ -377,7 +377,7 @@ export class ParserState extends ParserFrame {
|
|
|
377
377
|
}
|
|
378
378
|
break;
|
|
379
379
|
case "*":
|
|
380
|
-
switch (this.
|
|
380
|
+
switch (this._script.charAt(this._end)) {
|
|
381
381
|
case "=":
|
|
382
382
|
++this._end;
|
|
383
383
|
this._fragment = funcMultiplyAssignment;
|
|
@@ -388,29 +388,29 @@ export class ParserState extends ParserFrame {
|
|
|
388
388
|
}
|
|
389
389
|
break;
|
|
390
390
|
case "/":
|
|
391
|
-
switch (this.
|
|
391
|
+
switch (this._script.charAt(this._end)) {
|
|
392
392
|
case "=":
|
|
393
393
|
++this._end;
|
|
394
394
|
this._fragment = funcDivideAssignment;
|
|
395
395
|
break;
|
|
396
396
|
case "/":
|
|
397
|
-
if (this.
|
|
397
|
+
if (this._script.charAt(++this._end) === "/") {
|
|
398
398
|
++this._end;
|
|
399
|
-
while (this.
|
|
400
|
-
&& (this.
|
|
401
|
-
|| this.
|
|
402
|
-
|| this.
|
|
399
|
+
while (this._script.charAt(this._end) !== ""
|
|
400
|
+
&& (this._script.charAt(this._end) !== c
|
|
401
|
+
|| this._script.charAt(this._end - 1) !== c
|
|
402
|
+
|| this._script.charAt(this._end - 2) !== c)) {
|
|
403
403
|
++this._end;
|
|
404
404
|
}
|
|
405
|
-
if (this._end >= this.
|
|
406
|
-
this._start = this.
|
|
405
|
+
if (this._end >= this._script.length) {
|
|
406
|
+
this._start = this._script.length;
|
|
407
407
|
throw new Error("missing closing comment mark");
|
|
408
408
|
}
|
|
409
409
|
++this._end;
|
|
410
410
|
}
|
|
411
411
|
else {
|
|
412
|
-
while (this.
|
|
413
|
-
&& this.
|
|
412
|
+
while (this._script.charAt(this._end) !== ""
|
|
413
|
+
&& this._script.charAt(this._end) !== "\n") {
|
|
414
414
|
++this._end;
|
|
415
415
|
}
|
|
416
416
|
}
|
|
@@ -421,7 +421,7 @@ export class ParserState extends ParserFrame {
|
|
|
421
421
|
}
|
|
422
422
|
break;
|
|
423
423
|
case "%":
|
|
424
|
-
switch (this.
|
|
424
|
+
switch (this._script.charAt(this._end)) {
|
|
425
425
|
case "=":
|
|
426
426
|
++this._end;
|
|
427
427
|
this._fragment = funcRemainderAssignment;
|
|
@@ -435,9 +435,9 @@ export class ParserState extends ParserFrame {
|
|
|
435
435
|
this._fragment = funcPower;
|
|
436
436
|
break;
|
|
437
437
|
case ".":
|
|
438
|
-
switch (this.
|
|
438
|
+
switch (this._script.charAt(this._end)) {
|
|
439
439
|
case ".":
|
|
440
|
-
if (this.
|
|
440
|
+
if (this._script.charAt(++this._end) === ".") {
|
|
441
441
|
++this._end;
|
|
442
442
|
this._fragment = idEllipsis;
|
|
443
443
|
}
|
|
@@ -451,30 +451,30 @@ export class ParserState extends ParserFrame {
|
|
|
451
451
|
}
|
|
452
452
|
break;
|
|
453
453
|
case "@": {
|
|
454
|
-
const [ts, tsEnd] = parseLiteralTimestamp(this.
|
|
454
|
+
const [ts, tsEnd] = parseLiteralTimestamp(this._script, this._start);
|
|
455
455
|
this._fragment = new Literal(ts);
|
|
456
456
|
this._end = tsEnd;
|
|
457
457
|
break;
|
|
458
458
|
}
|
|
459
459
|
case "`": {
|
|
460
|
-
const [buf, bufEnd] = parseLiteralBuffer(this.
|
|
460
|
+
const [buf, bufEnd] = parseLiteralBuffer(this._script, this._start);
|
|
461
461
|
this._fragment = new Literal(buf);
|
|
462
462
|
this._end = bufEnd;
|
|
463
463
|
break;
|
|
464
464
|
}
|
|
465
465
|
case "\"":
|
|
466
466
|
case "'": {
|
|
467
|
-
const [str, strEnd] = parseLiteralString(this.
|
|
467
|
+
const [str, strEnd] = parseLiteralString(this._script, this._start);
|
|
468
468
|
this._fragment = new Literal(str);
|
|
469
469
|
this._end = strEnd;
|
|
470
470
|
break;
|
|
471
471
|
}
|
|
472
472
|
default:
|
|
473
473
|
if (isTokenStartSymbol(c)) {
|
|
474
|
-
while (isTokenSymbol(this.
|
|
474
|
+
while (isTokenSymbol(this._script.charAt(this._end))) {
|
|
475
475
|
++this._end;
|
|
476
476
|
}
|
|
477
|
-
const token = this.
|
|
477
|
+
const token = this._script.substring(this._start, this._end);
|
|
478
478
|
switch (token) {
|
|
479
479
|
case "true":
|
|
480
480
|
this._fragment = valueTrue;
|
|
@@ -546,7 +546,7 @@ export class ParserState extends ParserFrame {
|
|
|
546
546
|
}
|
|
547
547
|
}
|
|
548
548
|
else if (isNumericSymbol(c)) {
|
|
549
|
-
const [num, numEnd] = parseLiteralNumber(this.
|
|
549
|
+
const [num, numEnd] = parseLiteralNumber(this._script, this._start);
|
|
550
550
|
this._fragment = new Literal(num);
|
|
551
551
|
this._end = numEnd;
|
|
552
552
|
}
|
|
@@ -556,8 +556,8 @@ export class ParserState extends ParserFrame {
|
|
|
556
556
|
break;
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
|
-
if (this._end > this.
|
|
560
|
-
this._start = this._end = this.
|
|
559
|
+
if (this._end > this._script.length) {
|
|
560
|
+
this._start = this._end = this._script.length;
|
|
561
561
|
}
|
|
562
562
|
return this;
|
|
563
563
|
}
|
|
@@ -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
|
+
}
|
|
@@ -1,41 +1,30 @@
|
|
|
1
|
-
export class
|
|
2
|
-
|
|
3
|
-
_start;
|
|
4
|
-
_end;
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this._end = _end;
|
|
9
|
-
}
|
|
10
|
-
get expr() {
|
|
11
|
-
return this._expr;
|
|
12
|
-
}
|
|
13
|
-
get start() {
|
|
14
|
-
return this._start;
|
|
15
|
-
}
|
|
16
|
-
get end() {
|
|
17
|
-
return this._end;
|
|
18
|
-
}
|
|
19
|
-
starts(frame) {
|
|
20
|
-
if (frame) {
|
|
21
|
-
this._start = frame.start;
|
|
22
|
-
return this;
|
|
1
|
+
export class ScriptSpan {
|
|
2
|
+
_script;
|
|
3
|
+
_start = 0;
|
|
4
|
+
_end = 0;
|
|
5
|
+
constructor(span) {
|
|
6
|
+
if (typeof span === "string") {
|
|
7
|
+
this._script = span;
|
|
23
8
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this._end = frame.end;
|
|
29
|
-
return this;
|
|
9
|
+
else {
|
|
10
|
+
this._script = span._script;
|
|
11
|
+
this._start = span._start;
|
|
12
|
+
this._end = span._end;
|
|
30
13
|
}
|
|
31
|
-
|
|
14
|
+
}
|
|
15
|
+
start() {
|
|
16
|
+
return new ScriptSpan(this);
|
|
17
|
+
}
|
|
18
|
+
end(span) {
|
|
19
|
+
this._end = span._end;
|
|
20
|
+
return this;
|
|
32
21
|
}
|
|
33
22
|
throwError(message) {
|
|
34
23
|
const offset = this._start < 32 ? 0 : this._start - 32;
|
|
35
24
|
const length = this._end < this._start ? 0 : this._end - this._start - 1;
|
|
36
25
|
let expr = "";
|
|
37
|
-
for (let i = 0; i < this.
|
|
38
|
-
const c = this.
|
|
26
|
+
for (let i = 0; i < this._script.length; ++i) {
|
|
27
|
+
const c = this._script[i];
|
|
39
28
|
expr += SPACE_SYMBOLS.includes(c) ? " " : c;
|
|
40
29
|
}
|
|
41
30
|
throw new Error(`error: ${message} at position ${this._start}:\n${expr.substring(offset, offset + 60)}\n` +
|
package/dst/Type.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export declare class Type {
|
|
|
59
59
|
static readonly OptionalObject: Type;
|
|
60
60
|
static readonly Function: Type;
|
|
61
61
|
static readonly OptionalFunction: Type;
|
|
62
|
+
static readonly Reference: Type;
|
|
63
|
+
static readonly OptionalReference: Type;
|
|
62
64
|
static readonly Number: Type;
|
|
63
65
|
static readonly OptionalNumber: Type;
|
|
64
66
|
static readonly Enumerable: Type;
|
package/dst/Type.js
CHANGED
|
@@ -242,6 +242,8 @@ export class Type {
|
|
|
242
242
|
static OptionalObject = Type.union(Type.Void, Type.Object);
|
|
243
243
|
static Function = Type.functionType(undefined, undefined, true);
|
|
244
244
|
static OptionalFunction = Type.union(Type.Void, Type.Function);
|
|
245
|
+
static Reference = Type.union(Type.Array, Type.Object, Type.Function);
|
|
246
|
+
static OptionalReference = Type.union(Type.Void, Type.Array, Type.Object, Type.Function);
|
|
245
247
|
static Number = Type.union(Type.Float, Type.Integer);
|
|
246
248
|
static OptionalNumber = Type.union(Type.Void, Type.Float, Type.Integer);
|
|
247
249
|
static Enumerable = Type.union(Type.Buffer, Type.String, Type.Array);
|
package/dst/Variable.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Value } from "./Value.js";
|
|
2
1
|
import { Type } from "./Type.js";
|
|
3
2
|
export declare class Variable {
|
|
4
3
|
protected _type: Type;
|
|
5
4
|
protected readonly _assignable: boolean;
|
|
6
|
-
protected _value?: Value;
|
|
7
5
|
constructor(_type?: Type, _assignable?: boolean);
|
|
8
|
-
get value(): Value | undefined;
|
|
9
|
-
set value(value: Value | undefined);
|
|
10
6
|
get type(): Type;
|
|
11
7
|
set type(type: Type);
|
|
12
8
|
get assignable(): boolean;
|
package/dst/Variable.js
CHANGED
|
@@ -2,17 +2,10 @@ import { Type } from "./Type.js";
|
|
|
2
2
|
export class Variable {
|
|
3
3
|
_type;
|
|
4
4
|
_assignable;
|
|
5
|
-
_value;
|
|
6
5
|
constructor(_type = Type.Unknown, _assignable = true) {
|
|
7
6
|
this._type = _type;
|
|
8
7
|
this._assignable = _assignable;
|
|
9
8
|
}
|
|
10
|
-
get value() {
|
|
11
|
-
return this._value;
|
|
12
|
-
}
|
|
13
|
-
set value(value) {
|
|
14
|
-
this._value = value;
|
|
15
|
-
}
|
|
16
9
|
get type() {
|
|
17
10
|
return this._type;
|
|
18
11
|
}
|
|
@@ -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
|
+
}
|