affinirum 1.5.2 → 1.5.3

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.
Files changed (67) hide show
  1. package/README.md +12 -2
  2. package/dst/Affinirum.d.ts +22 -22
  3. package/dst/Affinirum.js +82 -75
  4. package/dst/CallFrame.d.ts +11 -0
  5. package/dst/CallFrame.js +35 -0
  6. package/dst/LexicalScope.d.ts +13 -0
  7. package/dst/LexicalScope.js +27 -0
  8. package/dst/Node.d.ts +5 -4
  9. package/dst/Node.js +5 -5
  10. package/dst/ParserState.d.ts +3 -3
  11. package/dst/ParserState.js +40 -40
  12. package/dst/ScriptSpan.d.ts +10 -0
  13. package/dst/{ParserFrame.js → ScriptSpan.js} +20 -31
  14. package/dst/Type.d.ts +2 -0
  15. package/dst/Type.js +2 -0
  16. package/dst/Variable.d.ts +0 -4
  17. package/dst/Variable.js +0 -7
  18. package/dst/cjs/Affinirum.js +82 -75
  19. package/dst/cjs/CallFrame.js +39 -0
  20. package/dst/cjs/LexicalScope.js +31 -0
  21. package/dst/cjs/Node.js +5 -5
  22. package/dst/cjs/ParserState.js +40 -40
  23. package/dst/cjs/{ParserFrame.js → ScriptSpan.js} +22 -33
  24. package/dst/cjs/Type.js +2 -0
  25. package/dst/cjs/Variable.js +0 -7
  26. package/dst/cjs/native/Number.js +24 -11
  27. package/dst/cjs/native/notation/AN.js +2 -2
  28. package/dst/cjs/node/ArrayNode.js +4 -11
  29. package/dst/cjs/node/BlockNode.js +10 -6
  30. package/dst/cjs/node/CallNode.js +15 -28
  31. package/dst/cjs/node/CastNode.js +4 -4
  32. package/dst/cjs/node/ConstantNode.js +7 -5
  33. package/dst/cjs/node/JumpNode.js +4 -4
  34. package/dst/cjs/node/LoopNode.js +5 -5
  35. package/dst/cjs/node/ObjectNode.js +6 -12
  36. package/dst/cjs/node/SwitchNode.js +8 -7
  37. package/dst/cjs/node/VariableNode.js +5 -5
  38. package/dst/cjs/node/VariadicNode.js +10 -0
  39. package/dst/native/Number.js +24 -11
  40. package/dst/native/notation/AN.js +2 -2
  41. package/dst/node/ArrayNode.d.ts +4 -3
  42. package/dst/node/ArrayNode.js +4 -11
  43. package/dst/node/BlockNode.d.ts +6 -3
  44. package/dst/node/BlockNode.js +10 -6
  45. package/dst/node/CallNode.d.ts +4 -3
  46. package/dst/node/CallNode.js +15 -28
  47. package/dst/node/CastNode.d.ts +4 -3
  48. package/dst/node/CastNode.js +4 -4
  49. package/dst/node/ConstantNode.d.ts +5 -3
  50. package/dst/node/ConstantNode.js +7 -5
  51. package/dst/node/JumpNode.d.ts +4 -3
  52. package/dst/node/JumpNode.js +4 -4
  53. package/dst/node/LoopNode.d.ts +4 -3
  54. package/dst/node/LoopNode.js +5 -5
  55. package/dst/node/ObjectNode.d.ts +4 -3
  56. package/dst/node/ObjectNode.js +6 -12
  57. package/dst/node/SwitchNode.d.ts +4 -3
  58. package/dst/node/SwitchNode.js +8 -7
  59. package/dst/node/VariableNode.d.ts +4 -3
  60. package/dst/node/VariableNode.js +5 -5
  61. package/dst/node/VariadicNode.d.ts +4 -0
  62. package/dst/node/VariadicNode.js +6 -0
  63. package/package.json +10 -9
  64. package/dst/ParserFrame.d.ts +0 -13
  65. package/dst/Scope.d.ts +0 -16
  66. package/dst/Scope.js +0 -49
  67. package/dst/cjs/Scope.js +0 -53
@@ -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 { ParserFrame } from "./ParserFrame.js";
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 ParserFrame {
57
+ export class ParserState extends ScriptSpan {
58
58
  _fragment;
59
- constructor(expr) {
60
- super(expr);
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._expr);
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._expr.length && this._fragment == null) {
215
+ while (this._end < this._script.length && this._fragment == null) {
216
216
  this._start = this._end;
217
- const c = this._expr.charAt(this._end);
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
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._expr.charAt(++this._end) === "/") {
397
+ if (this._script.charAt(++this._end) === "/") {
398
398
  ++this._end;
399
- while (this._expr.charAt(this._end) !== ""
400
- && (this._expr.charAt(this._end) !== c
401
- || this._expr.charAt(this._end - 1) !== c
402
- || this._expr.charAt(this._end - 2) !== c)) {
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._expr.length) {
406
- this._start = this._expr.length;
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._expr.charAt(this._end) !== ""
413
- && this._expr.charAt(this._end) !== "\n") {
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._expr.charAt(this._end)) {
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._expr.charAt(this._end)) {
438
+ switch (this._script.charAt(this._end)) {
439
439
  case ".":
440
- if (this._expr.charAt(++this._end) === ".") {
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._expr, this._start);
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._expr, this._start);
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._expr, this._start);
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._expr.charAt(this._end))) {
474
+ while (isTokenSymbol(this._script.charAt(this._end))) {
475
475
  ++this._end;
476
476
  }
477
- const token = this._expr.substring(this._start, this._end);
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._expr, this._start);
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._expr.length) {
560
- this._start = this._end = this._expr.length;
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 ParserFrame {
2
- _expr;
3
- _start;
4
- _end;
5
- constructor(_expr, _start = 0, _end = 0) {
6
- this._expr = _expr;
7
- this._start = _start;
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
- return new ParserFrame(this._expr, this._start, this._end);
25
- }
26
- ends(frame) {
27
- if (frame) {
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
- return new ParserFrame(this._expr, this._start, this._end);
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._expr.length; ++i) {
38
- const c = this._expr[i];
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
  }