affinirum 1.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.
Files changed (121) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +301 -0
  3. package/dst/Affinirum.d.ts +73 -0
  4. package/dst/Affinirum.js +536 -0
  5. package/dst/Constant.d.ts +15 -0
  6. package/dst/Constant.js +26 -0
  7. package/dst/Constants.d.ts +2 -0
  8. package/dst/Constants.js +22 -0
  9. package/dst/Functions.d.ts +2 -0
  10. package/dst/Functions.js +85 -0
  11. package/dst/Keywords.d.ts +1 -0
  12. package/dst/Keywords.js +17 -0
  13. package/dst/Node.d.ts +13 -0
  14. package/dst/Node.js +22 -0
  15. package/dst/ParserFrame.d.ts +13 -0
  16. package/dst/ParserFrame.js +80 -0
  17. package/dst/ParserState.d.ts +54 -0
  18. package/dst/ParserState.js +562 -0
  19. package/dst/StaticScope.d.ts +13 -0
  20. package/dst/StaticScope.js +44 -0
  21. package/dst/Type.d.ts +72 -0
  22. package/dst/Type.js +196 -0
  23. package/dst/Value.d.ts +3 -0
  24. package/dst/Value.js +1 -0
  25. package/dst/Variable.d.ts +13 -0
  26. package/dst/Variable.js +25 -0
  27. package/dst/atom/ArrayAtom.d.ts +11 -0
  28. package/dst/atom/ArrayAtom.js +38 -0
  29. package/dst/atom/FunctionAtom.d.ts +17 -0
  30. package/dst/atom/FunctionAtom.js +54 -0
  31. package/dst/atom/ObjectAtom.d.ts +11 -0
  32. package/dst/atom/ObjectAtom.js +44 -0
  33. package/dst/atom/PrimitiveAtom.d.ts +8 -0
  34. package/dst/atom/PrimitiveAtom.js +26 -0
  35. package/dst/cjs/Affinirum.js +540 -0
  36. package/dst/cjs/Constant.js +30 -0
  37. package/dst/cjs/Constants.js +25 -0
  38. package/dst/cjs/Functions.js +88 -0
  39. package/dst/cjs/Keywords.js +20 -0
  40. package/dst/cjs/Node.js +26 -0
  41. package/dst/cjs/ParserFrame.js +84 -0
  42. package/dst/cjs/ParserState.js +566 -0
  43. package/dst/cjs/StaticScope.js +48 -0
  44. package/dst/cjs/Type.js +200 -0
  45. package/dst/cjs/Value.js +2 -0
  46. package/dst/cjs/Variable.js +29 -0
  47. package/dst/cjs/atom/ArrayAtom.js +42 -0
  48. package/dst/cjs/atom/FunctionAtom.js +58 -0
  49. package/dst/cjs/atom/ObjectAtom.js +48 -0
  50. package/dst/cjs/atom/PrimitiveAtom.js +30 -0
  51. package/dst/cjs/constant/Array.js +93 -0
  52. package/dst/cjs/constant/Boolean.js +25 -0
  53. package/dst/cjs/constant/Buffer.js +68 -0
  54. package/dst/cjs/constant/Enumerable.js +34 -0
  55. package/dst/cjs/constant/Float.js +85 -0
  56. package/dst/cjs/constant/Integer.js +104 -0
  57. package/dst/cjs/constant/Iterable.js +24 -0
  58. package/dst/cjs/constant/Number.js +59 -0
  59. package/dst/cjs/constant/Object.js +13 -0
  60. package/dst/cjs/constant/String.js +197 -0
  61. package/dst/cjs/constant/Timestamp.js +56 -0
  62. package/dst/cjs/constant/Unknown.js +101 -0
  63. package/dst/cjs/constant/notation/AN.js +46 -0
  64. package/dst/cjs/constant/notation/JSON.js +14 -0
  65. package/dst/cjs/index.js +19 -0
  66. package/dst/cjs/node/ArrayNode.js +34 -0
  67. package/dst/cjs/node/BlockNode.js +33 -0
  68. package/dst/cjs/node/CallNode.js +54 -0
  69. package/dst/cjs/node/ConstantNode.js +33 -0
  70. package/dst/cjs/node/LoopNode.js +34 -0
  71. package/dst/cjs/node/ObjectNode.js +42 -0
  72. package/dst/cjs/node/SwitchNode.js +45 -0
  73. package/dst/cjs/node/VariableNode.js +30 -0
  74. package/dst/cjs/package.json +3 -0
  75. package/dst/constant/Array.d.ts +22 -0
  76. package/dst/constant/Array.js +90 -0
  77. package/dst/constant/Boolean.d.ts +11 -0
  78. package/dst/constant/Boolean.js +22 -0
  79. package/dst/constant/Buffer.d.ts +10 -0
  80. package/dst/constant/Buffer.js +61 -0
  81. package/dst/constant/Enumerable.d.ts +5 -0
  82. package/dst/constant/Enumerable.js +31 -0
  83. package/dst/constant/Float.d.ts +22 -0
  84. package/dst/constant/Float.js +80 -0
  85. package/dst/constant/Integer.d.ts +10 -0
  86. package/dst/constant/Integer.js +100 -0
  87. package/dst/constant/Iterable.d.ts +3 -0
  88. package/dst/constant/Iterable.js +21 -0
  89. package/dst/constant/Number.d.ts +14 -0
  90. package/dst/constant/Number.js +56 -0
  91. package/dst/constant/Object.d.ts +7 -0
  92. package/dst/constant/Object.js +10 -0
  93. package/dst/constant/String.d.ts +34 -0
  94. package/dst/constant/String.js +179 -0
  95. package/dst/constant/Timestamp.d.ts +20 -0
  96. package/dst/constant/Timestamp.js +50 -0
  97. package/dst/constant/Unknown.d.ts +10 -0
  98. package/dst/constant/Unknown.js +95 -0
  99. package/dst/constant/notation/AN.d.ts +6 -0
  100. package/dst/constant/notation/AN.js +42 -0
  101. package/dst/constant/notation/JSON.d.ts +7 -0
  102. package/dst/constant/notation/JSON.js +10 -0
  103. package/dst/index.d.ts +3 -0
  104. package/dst/index.js +3 -0
  105. package/dst/node/ArrayNode.d.ts +12 -0
  106. package/dst/node/ArrayNode.js +30 -0
  107. package/dst/node/BlockNode.d.ts +12 -0
  108. package/dst/node/BlockNode.js +29 -0
  109. package/dst/node/CallNode.d.ts +14 -0
  110. package/dst/node/CallNode.js +50 -0
  111. package/dst/node/ConstantNode.d.ts +15 -0
  112. package/dst/node/ConstantNode.js +29 -0
  113. package/dst/node/LoopNode.d.ts +13 -0
  114. package/dst/node/LoopNode.js +30 -0
  115. package/dst/node/ObjectNode.d.ts +13 -0
  116. package/dst/node/ObjectNode.js +38 -0
  117. package/dst/node/SwitchNode.d.ts +14 -0
  118. package/dst/node/SwitchNode.js +41 -0
  119. package/dst/node/VariableNode.d.ts +14 -0
  120. package/dst/node/VariableNode.js +26 -0
  121. package/package.json +67 -0
@@ -0,0 +1,562 @@
1
+ import { funcAt } from './constant/Iterable.js';
2
+ import { funcOr, funcAnd, funcNot } from './constant/Boolean.js';
3
+ import { parseBuffer } from './constant/Buffer.js';
4
+ import { funcAdd } from './constant/Enumerable.js';
5
+ import { isSign, isAlpha, isNumeric, isAlphanumeric, isHexadecimal, isQuotation, isDateSymbol, isTimeSymbol, isDateTimeSeparator } from './constant/String.js';
6
+ import { Constant } from './Constant.js';
7
+ import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower } from './constant/Number.js';
8
+ import { funcCoalesce, funcEqual, funcNotEqual } from './constant/Unknown.js';
9
+ import { Type } from './Type.js';
10
+ import { ParserFrame } from './ParserFrame.js';
11
+ class Literal {
12
+ value;
13
+ constructor(value) {
14
+ this.value = value;
15
+ }
16
+ }
17
+ const valueTrue = new Literal(true);
18
+ const valueFalse = new Literal(false);
19
+ const valueNull = new Literal(undefined);
20
+ class Assignment {
21
+ operator;
22
+ constructor(operator) {
23
+ this.operator = operator;
24
+ }
25
+ }
26
+ const funcAssignment = new Assignment();
27
+ const funcOrAssignment = new Assignment(funcOr);
28
+ const funcAndAssignment = new Assignment(funcAnd);
29
+ const funcAddAssignment = new Assignment(funcAdd);
30
+ const funcSubtractAssignment = new Assignment(funcSubtract);
31
+ const funcMultiplyAssignment = new Assignment(funcMultiply);
32
+ const funcDivideAssignment = new Assignment(funcDivide);
33
+ const funcRemainderAssignment = new Assignment(funcRemainder);
34
+ const symbolParenthesesOpen = Symbol();
35
+ const symbolParenthesesClose = Symbol();
36
+ const symbolBracketsOpen = Symbol();
37
+ const symbolBracketsClose = Symbol();
38
+ const symbolBracesOpen = Symbol();
39
+ const symbolBracesClose = Symbol();
40
+ const symbolSemicolonSeparator = Symbol();
41
+ const symbolColonSeparator = Symbol();
42
+ const symbolCommaSeparator = Symbol();
43
+ const symbolTildaMark = Symbol();
44
+ const symbolOptionalType = Symbol();
45
+ const symbolVariadicFunction = Symbol();
46
+ const symbolVariableDefinition = Symbol();
47
+ const symbolConstantDefinition = Symbol();
48
+ const symbolWhile = Symbol();
49
+ const symbolIf = Symbol();
50
+ const symbolElse = Symbol();
51
+ export class ParserState extends ParserFrame {
52
+ _fragment;
53
+ constructor(expr) {
54
+ super(expr);
55
+ }
56
+ get literalValue() {
57
+ return this._fragment.value;
58
+ }
59
+ get assignmentOperator() {
60
+ return this._fragment.operator;
61
+ }
62
+ get operator() {
63
+ return this._fragment;
64
+ }
65
+ get type() {
66
+ return this._fragment;
67
+ }
68
+ get token() {
69
+ return this._fragment;
70
+ }
71
+ get isOperator() {
72
+ return this._fragment instanceof Constant;
73
+ }
74
+ get isLiteral() {
75
+ return this._fragment instanceof Literal;
76
+ }
77
+ get isAssignment() {
78
+ return this._fragment instanceof Assignment;
79
+ }
80
+ get isType() {
81
+ return this._fragment instanceof Type;
82
+ }
83
+ get isToken() {
84
+ return typeof this._fragment === 'string';
85
+ }
86
+ get isParenthesesOpen() {
87
+ return this._fragment === symbolParenthesesOpen;
88
+ }
89
+ get isParenthesesClose() {
90
+ return this._fragment === symbolParenthesesClose;
91
+ }
92
+ get isBracketsOpen() {
93
+ return this._fragment === symbolBracketsOpen;
94
+ }
95
+ get isBracketsClose() {
96
+ return this._fragment === symbolBracketsClose;
97
+ }
98
+ get isBracesOpen() {
99
+ return this._fragment === symbolBracesOpen;
100
+ }
101
+ get isBracesClose() {
102
+ return this._fragment === symbolBracesClose;
103
+ }
104
+ get isSemicolonSeparator() {
105
+ return this._fragment === symbolSemicolonSeparator;
106
+ }
107
+ get isColonSeparator() {
108
+ return this._fragment === symbolColonSeparator;
109
+ }
110
+ get isCommaSeparator() {
111
+ return this._fragment === symbolCommaSeparator;
112
+ }
113
+ get isTildaMark() {
114
+ return this._fragment === symbolTildaMark;
115
+ }
116
+ get isOptionalType() {
117
+ return this._fragment === symbolOptionalType;
118
+ }
119
+ get isVariadicFunction() {
120
+ return this._fragment === symbolVariadicFunction;
121
+ }
122
+ get isVariableDefinition() {
123
+ return this._fragment === symbolVariableDefinition;
124
+ }
125
+ get isConstantDefinition() {
126
+ return this._fragment === symbolConstantDefinition;
127
+ }
128
+ get isWhile() {
129
+ return this._fragment === symbolWhile;
130
+ }
131
+ get isIf() {
132
+ return this._fragment === symbolIf;
133
+ }
134
+ get isElse() {
135
+ return this._fragment === symbolElse;
136
+ }
137
+ get isVoid() {
138
+ return this._fragment == null;
139
+ }
140
+ openParentheses() {
141
+ if (!this.isParenthesesOpen) {
142
+ this.throwError('missing opening parentheses');
143
+ }
144
+ return this;
145
+ }
146
+ closeParentheses() {
147
+ if (!this.isParenthesesClose) {
148
+ this.throwError('missing closing parentheses');
149
+ }
150
+ return this;
151
+ }
152
+ openBrackets() {
153
+ if (!this.isBracketsOpen) {
154
+ this.throwError('missing opening brackets');
155
+ }
156
+ return this;
157
+ }
158
+ closeBrackets() {
159
+ if (!this.isBracketsClose) {
160
+ this.throwError('missing closing brackets');
161
+ }
162
+ return this;
163
+ }
164
+ openBraces() {
165
+ if (!this.isBracesOpen) {
166
+ this.throwError('missing opening braces');
167
+ }
168
+ return this;
169
+ }
170
+ closeBraces() {
171
+ if (!this.isBracesClose) {
172
+ this.throwError('missing closing braces');
173
+ }
174
+ return this;
175
+ }
176
+ separateByColon() {
177
+ if (!this.isColonSeparator) {
178
+ this.throwError('missing colon separator');
179
+ }
180
+ return this;
181
+ }
182
+ clone() {
183
+ const state = new ParserState(this._expr);
184
+ state._start = this._start;
185
+ state._end = this._end;
186
+ state._fragment = this._fragment;
187
+ return state;
188
+ }
189
+ next() {
190
+ this._fragment = undefined;
191
+ while (this._end < this._expr.length && this._fragment == null) {
192
+ this._start = this._end;
193
+ const c = this._expr.charAt(this._end);
194
+ ++this._end;
195
+ switch (c) {
196
+ case ' ':
197
+ case '\t':
198
+ case '\n':
199
+ case '\r': break;
200
+ case '(':
201
+ this._fragment = symbolParenthesesOpen;
202
+ break;
203
+ case ')':
204
+ this._fragment = symbolParenthesesClose;
205
+ break;
206
+ case '[':
207
+ this._fragment = symbolBracketsOpen;
208
+ break;
209
+ case ']':
210
+ this._fragment = symbolBracketsClose;
211
+ break;
212
+ case '{':
213
+ this._fragment = symbolBracesOpen;
214
+ break;
215
+ case '}':
216
+ this._fragment = symbolBracesClose;
217
+ break;
218
+ case ';':
219
+ this._fragment = symbolSemicolonSeparator;
220
+ break;
221
+ case ':':
222
+ this._fragment = symbolColonSeparator;
223
+ break;
224
+ case ',':
225
+ this._fragment = symbolCommaSeparator;
226
+ break;
227
+ case '~':
228
+ this._fragment = symbolTildaMark;
229
+ break;
230
+ case '?':
231
+ switch (this._expr.charAt(this._end)) {
232
+ case '?':
233
+ ++this._end;
234
+ this._fragment = Type.Unknown;
235
+ break;
236
+ case ':':
237
+ ++this._end;
238
+ this._fragment = funcCoalesce;
239
+ break;
240
+ default:
241
+ this._fragment = symbolOptionalType;
242
+ break;
243
+ }
244
+ break;
245
+ case '|':
246
+ switch (this._expr.charAt(this._end)) {
247
+ case '=':
248
+ ++this._end;
249
+ this._fragment = funcOrAssignment;
250
+ break;
251
+ default:
252
+ this._fragment = funcOr;
253
+ break;
254
+ }
255
+ break;
256
+ case '&':
257
+ switch (this._expr.charAt(this._end)) {
258
+ case '=':
259
+ ++this._end;
260
+ this._fragment = funcAndAssignment;
261
+ break;
262
+ default:
263
+ this._fragment = funcAnd;
264
+ break;
265
+ }
266
+ break;
267
+ case '>':
268
+ switch (this._expr.charAt(this._end)) {
269
+ case '=':
270
+ ++this._end;
271
+ this._fragment = funcGreaterOrEqual;
272
+ break;
273
+ default:
274
+ this._fragment = funcGreaterThan;
275
+ break;
276
+ }
277
+ break;
278
+ case '<':
279
+ switch (this._expr.charAt(this._end)) {
280
+ case '=':
281
+ ++this._end;
282
+ this._fragment = funcLessOrEqual;
283
+ break;
284
+ default:
285
+ this._fragment = funcLessThan;
286
+ break;
287
+ }
288
+ break;
289
+ case '!':
290
+ switch (this._expr.charAt(this._end)) {
291
+ case '=':
292
+ ++this._end;
293
+ this._fragment = funcNotEqual;
294
+ break;
295
+ default:
296
+ this._fragment = funcNot;
297
+ break;
298
+ }
299
+ break;
300
+ case '=':
301
+ switch (this._expr.charAt(this._end)) {
302
+ case '=':
303
+ ++this._end;
304
+ this._fragment = funcEqual;
305
+ break;
306
+ default:
307
+ this._fragment = funcAssignment;
308
+ break;
309
+ }
310
+ break;
311
+ case '+':
312
+ switch (this._expr.charAt(this._end)) {
313
+ case '=':
314
+ ++this._end;
315
+ this._fragment = funcAddAssignment;
316
+ break;
317
+ default:
318
+ this._fragment = funcAdd;
319
+ break;
320
+ }
321
+ break;
322
+ case '-':
323
+ switch (this._expr.charAt(this._end)) {
324
+ case '=':
325
+ ++this._end;
326
+ this._fragment = funcSubtractAssignment;
327
+ break;
328
+ default:
329
+ this._fragment = funcSubtract;
330
+ break;
331
+ }
332
+ break;
333
+ case '*':
334
+ switch (this._expr.charAt(this._end)) {
335
+ case '=':
336
+ ++this._end;
337
+ this._fragment = funcMultiplyAssignment;
338
+ break;
339
+ default:
340
+ this._fragment = funcMultiply;
341
+ break;
342
+ }
343
+ break;
344
+ case '/':
345
+ switch (this._expr.charAt(this._end)) {
346
+ case '=':
347
+ ++this._end;
348
+ this._fragment = funcDivideAssignment;
349
+ break;
350
+ default:
351
+ this._fragment = funcDivide;
352
+ break;
353
+ }
354
+ break;
355
+ case '%':
356
+ switch (this._expr.charAt(this._end)) {
357
+ case '=':
358
+ ++this._end;
359
+ this._fragment = funcRemainderAssignment;
360
+ break;
361
+ default:
362
+ this._fragment = funcRemainder;
363
+ break;
364
+ }
365
+ break;
366
+ case '$':
367
+ switch (this._expr.charAt(this._end)) {
368
+ case '$':
369
+ while (this._expr.charAt(this._end) !== '' && this._expr.charAt(this._end) !== '\n') {
370
+ ++this._end;
371
+ }
372
+ break;
373
+ default:
374
+ while (this._expr.charAt(this._end) !== '' && this._expr.charAt(this._end) !== c) {
375
+ ++this._end;
376
+ }
377
+ if (this._end >= this._expr.length) {
378
+ this._start = this._expr.length;
379
+ throw new Error(`missing closing comment mark ${c}`);
380
+ }
381
+ ++this._end;
382
+ break;
383
+ }
384
+ break;
385
+ case '^':
386
+ this._fragment = funcPower;
387
+ break;
388
+ case '.':
389
+ switch (this._expr.charAt(this._end)) {
390
+ case '.':
391
+ if (this._expr.charAt(++this._end) === '.') {
392
+ ++this._end;
393
+ this._fragment = symbolVariadicFunction;
394
+ }
395
+ else {
396
+ throw new Error('incomplete ellipsis ...');
397
+ }
398
+ break;
399
+ default:
400
+ this._fragment = funcAt;
401
+ break;
402
+ }
403
+ break;
404
+ case '@':
405
+ while (isDateSymbol(this._expr.charAt(this._end))) {
406
+ ++this._end;
407
+ }
408
+ if (isDateTimeSeparator(this._expr.charAt(this._end))) {
409
+ ++this._end;
410
+ while (isTimeSymbol(this._expr.charAt(this._end))) {
411
+ ++this._end;
412
+ }
413
+ if (this._expr.charAt(this._end) === '.') {
414
+ ++this._end;
415
+ while (isNumeric(this._expr.charAt(this._end))) {
416
+ ++this._end;
417
+ }
418
+ if (this._expr.charAt(this._end) === 'Z') {
419
+ ++this._end;
420
+ }
421
+ }
422
+ }
423
+ this._fragment = new Literal(new Date(this._expr.substring(this._start + 1, this._end)));
424
+ break;
425
+ case '#':
426
+ while (isHexadecimal(this._expr.charAt(this._end))) {
427
+ ++this._end;
428
+ }
429
+ this._fragment = new Literal(parseBuffer(this._expr.substring(this._start + 1, this._end)));
430
+ break;
431
+ default:
432
+ if (isAlpha(c)) {
433
+ while (isAlphanumeric(this._expr.charAt(this._end))) {
434
+ ++this._end;
435
+ }
436
+ const token = this._expr.substring(this._start, this._end);
437
+ switch (token) {
438
+ case 'true':
439
+ this._fragment = valueTrue;
440
+ break;
441
+ case 'false':
442
+ this._fragment = valueFalse;
443
+ break;
444
+ case 'null':
445
+ this._fragment = valueNull;
446
+ break;
447
+ case 'void':
448
+ this._fragment = Type.Void;
449
+ break;
450
+ case 'bool':
451
+ case 'boolean':
452
+ this._fragment = Type.Boolean;
453
+ break;
454
+ case 'time':
455
+ case 'timestamp':
456
+ this._fragment = Type.Timestamp;
457
+ break;
458
+ case 'flo':
459
+ case 'float':
460
+ this._fragment = Type.Float;
461
+ break;
462
+ case 'int':
463
+ case 'integer':
464
+ this._fragment = Type.Integer;
465
+ break;
466
+ case 'buf':
467
+ case 'buffer':
468
+ this._fragment = Type.Buffer;
469
+ break;
470
+ case 'str':
471
+ case 'string':
472
+ this._fragment = Type.String;
473
+ break;
474
+ case 'arr':
475
+ case 'array':
476
+ this._fragment = Type.Array;
477
+ break;
478
+ case 'obj':
479
+ case 'object':
480
+ this._fragment = Type.Object;
481
+ break;
482
+ case 'func':
483
+ case 'function':
484
+ this._fragment = Type.Function;
485
+ break;
486
+ case 'var':
487
+ case 'variable':
488
+ this._fragment = symbolVariableDefinition;
489
+ break;
490
+ case 'const':
491
+ case 'constant':
492
+ this._fragment = symbolConstantDefinition;
493
+ break;
494
+ case 'while':
495
+ this._fragment = symbolWhile;
496
+ break;
497
+ case 'if':
498
+ this._fragment = symbolIf;
499
+ break;
500
+ case 'else':
501
+ this._fragment = symbolElse;
502
+ break;
503
+ default:
504
+ this._fragment = token;
505
+ break;
506
+ }
507
+ }
508
+ else if (isNumeric(c)) {
509
+ let integer = true;
510
+ while (isNumeric(this._expr.charAt(this._end))) {
511
+ ++this._end;
512
+ }
513
+ if (this._expr.charAt(this._end) === '.') {
514
+ ++this._end;
515
+ if (isNumeric(this._expr.charAt(this._end))) {
516
+ ++this._end;
517
+ while (isNumeric(this._expr.charAt(this._end))) {
518
+ ++this._end;
519
+ }
520
+ integer = false;
521
+ }
522
+ else {
523
+ --this._end;
524
+ }
525
+ }
526
+ if (this._expr.charAt(this._end) === 'e') {
527
+ ++this._end;
528
+ if (isNumeric(this._expr.charAt(this._end)) || isSign(this._expr.charAt(this._end))) {
529
+ ++this._end;
530
+ while (isNumeric(this._expr.charAt(this._end))) {
531
+ ++this._end;
532
+ }
533
+ }
534
+ integer = false;
535
+ }
536
+ this._fragment = integer
537
+ ? new Literal(BigInt(this._expr.substring(this._start, this._end)))
538
+ : new Literal(parseFloat(this._expr.substring(this._start, this._end)));
539
+ }
540
+ else if (isQuotation(c)) {
541
+ while (this._expr.charAt(this._end) !== '' && this._expr.charAt(this._end) !== c) {
542
+ ++this._end;
543
+ }
544
+ if (this._end >= this._expr.length) {
545
+ this._start = this._expr.length;
546
+ throw new Error(`missing closing quotation mark ${c}`);
547
+ }
548
+ this._fragment = new Literal(this._expr.substring(this._start + 1, this._end));
549
+ ++this._end;
550
+ }
551
+ else {
552
+ throw new Error(`unknown symbol ${c}`);
553
+ }
554
+ break;
555
+ }
556
+ }
557
+ if (this._end > this._expr.length) {
558
+ this._start = this._end = this._expr.length;
559
+ }
560
+ return this;
561
+ }
562
+ }
@@ -0,0 +1,13 @@
1
+ import { Variable } from './Variable.js';
2
+ export declare class StaticScope {
3
+ protected _superscope?: StaticScope;
4
+ protected _subscopes: StaticScope[];
5
+ protected _variables: Map<string, Variable>;
6
+ protected _locals: Set<string>;
7
+ has(name: string): boolean;
8
+ get(name: string): Variable | undefined;
9
+ global(name: string, variable: Variable): StaticScope;
10
+ local(name: string, variable: Variable): StaticScope;
11
+ subscope(variables: Map<string, Variable>): StaticScope;
12
+ variables(): Record<string, Variable>;
13
+ }
@@ -0,0 +1,44 @@
1
+ export class StaticScope {
2
+ _superscope;
3
+ _subscopes = [];
4
+ _variables = new Map();
5
+ _locals = new Set();
6
+ has(name) {
7
+ return this._variables.has(name) || Boolean(this._superscope?.has(name));
8
+ }
9
+ get(name) {
10
+ return this._variables.get(name) ?? this._superscope?.get(name);
11
+ }
12
+ global(name, variable) {
13
+ if (this._superscope) {
14
+ this._superscope.global(name, variable);
15
+ }
16
+ else {
17
+ this._variables.set(name, variable);
18
+ }
19
+ return this;
20
+ }
21
+ local(name, variable) {
22
+ this._variables.set(name, variable);
23
+ this._locals.add(name);
24
+ return this;
25
+ }
26
+ subscope(variables) {
27
+ const scope = new StaticScope();
28
+ scope._superscope = this;
29
+ this._subscopes.push(scope);
30
+ for (const [name, variable] of variables) {
31
+ scope.local(name, variable);
32
+ }
33
+ return scope;
34
+ }
35
+ variables() {
36
+ const variables = {};
37
+ for (const [name, variable] of this._variables) {
38
+ if (!this._locals.has(name)) {
39
+ variables[name] = variable;
40
+ }
41
+ }
42
+ return variables;
43
+ }
44
+ }
package/dst/Type.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { Value } from './Value.js';
2
+ import { PrimitiveAtom } from './atom/PrimitiveAtom.js';
3
+ import { ArrayAtom } from './atom/ArrayAtom.js';
4
+ import { ObjectAtom } from './atom/ObjectAtom.js';
5
+ import { FunctionAtom } from './atom/FunctionAtom.js';
6
+ export type Primitive = 'void' | 'boolean' | 'timestamp' | 'float' | 'integer' | 'buffer' | 'string';
7
+ type Atom = PrimitiveAtom | ArrayAtom | ObjectAtom | FunctionAtom;
8
+ export interface IType {
9
+ match(subtype: IType): boolean;
10
+ weight(): number;
11
+ toString(): string;
12
+ }
13
+ export declare class Type implements IType {
14
+ protected readonly _atoms: Atom[];
15
+ private constructor();
16
+ get isUnknown(): boolean;
17
+ get isAtom(): boolean;
18
+ get isOptional(): boolean;
19
+ get isVoid(): boolean;
20
+ get isBoolean(): boolean;
21
+ get isTimestamp(): boolean;
22
+ get isFloat(): boolean;
23
+ get isInteger(): boolean;
24
+ get isBuffer(): boolean;
25
+ get isString(): boolean;
26
+ get isArray(): boolean;
27
+ get isObject(): boolean;
28
+ get isFunction(): boolean;
29
+ get isNumeric(): boolean;
30
+ toOptional(): Type;
31
+ mergeFunctionAtomRetType(type: Type): Type;
32
+ mergeFunctionAtom(type: Type, argc: number): FunctionAtom | undefined;
33
+ reduce(mask: Type): Type | undefined;
34
+ match(type: IType): boolean;
35
+ weight(): number;
36
+ toString(): string;
37
+ static union(...types: Type[]): Type;
38
+ static of(value: Value): Type;
39
+ static isPrimitiveType(value: Value): value is string | number | bigint | boolean | void | Date | ArrayBuffer | null | undefined;
40
+ static arrayType(itemTypes?: Type[]): Type;
41
+ static objectType(propTypes?: Record<string, Type>): Type;
42
+ static functionType(retType?: Type, argTypes?: Type[], isVariadic?: boolean): Type;
43
+ static readonly Unknown: Type;
44
+ static readonly Void: Type;
45
+ static readonly Boolean: Type;
46
+ static readonly OptionalBoolean: Type;
47
+ static readonly Timestamp: Type;
48
+ static readonly OptionalTimestamp: Type;
49
+ static readonly Float: Type;
50
+ static readonly OptionalFloat: Type;
51
+ static readonly Integer: Type;
52
+ static readonly OptionalInteger: Type;
53
+ static readonly Buffer: Type;
54
+ static readonly OptionalBuffer: Type;
55
+ static readonly String: Type;
56
+ static readonly OptionalString: Type;
57
+ static readonly Array: Type;
58
+ static readonly OptionalArray: Type;
59
+ static readonly Object: Type;
60
+ static readonly OptionalObject: Type;
61
+ static readonly Function: Type;
62
+ static readonly OptionalFunction: Type;
63
+ static readonly Number: Type;
64
+ static readonly OptionalNumber: Type;
65
+ static readonly Enumerable: Type;
66
+ static readonly OptionalEnumerable: Type;
67
+ static readonly Iterable: Type;
68
+ static readonly OptionalIterable: Type;
69
+ private static _primitiveType;
70
+ private static _functionAtom;
71
+ }
72
+ export {};