@mojir/lits 2.0.11 → 2.0.13
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/dist/cli/cli.js +1669 -1629
- package/dist/cli/reference/api.d.ts +10 -10
- package/dist/cli/reference/index.d.ts +2 -2
- package/dist/cli/src/builtin/normalExpressions/categories/sequence.d.ts +1 -3
- package/dist/cli/src/parser/AlgebraicParser.d.ts +5 -0
- package/dist/cli/src/tokenizer/algebraic/algebraicTokenizers.d.ts +3 -2
- package/dist/cli/src/tokenizer/algebraic/algebraicTokens.d.ts +50 -32
- package/dist/cli/src/tokenizer/polish/polishTokenizers.d.ts +1 -0
- package/dist/cli/src/tokenizer/tokens.d.ts +2 -2
- package/dist/index.esm.js +1668 -1628
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1668 -1628
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +1668 -1628
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +10 -10
- package/dist/reference/index.d.ts +2 -2
- package/dist/src/builtin/normalExpressions/categories/sequence.d.ts +1 -3
- package/dist/src/parser/AlgebraicParser.d.ts +5 -0
- package/dist/src/tokenizer/algebraic/algebraicTokenizers.d.ts +3 -2
- package/dist/src/tokenizer/algebraic/algebraicTokens.d.ts +50 -32
- package/dist/src/tokenizer/polish/polishTokenizers.d.ts +1 -0
- package/dist/src/tokenizer/tokens.d.ts +2 -2
- package/dist/testFramework.esm.js +911 -773
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +911 -773
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -368,19 +368,17 @@ var algebraicOnlyValueTokenTypes = [
|
|
|
368
368
|
'A_SingleLineComment',
|
|
369
369
|
'A_MultiLineComment',
|
|
370
370
|
'A_Number',
|
|
371
|
+
'A_BasePrefixedNumber',
|
|
371
372
|
];
|
|
372
373
|
var algebraicValueTokenTypes = __spreadArray(__spreadArray([], __read(commomValueTokenTypes), false), __read(algebraicOnlyValueTokenTypes), false);
|
|
373
374
|
__spreadArray(__spreadArray([], __read(algebraicSimpleTokenTypes), false), __read(algebraicValueTokenTypes), false);
|
|
374
|
-
var
|
|
375
|
-
// Unary only operators
|
|
375
|
+
var symbolicUnaryOperators = [
|
|
376
376
|
'!', // logical NOT
|
|
377
377
|
'~', // bitwise NOT
|
|
378
|
-
'
|
|
379
|
-
'
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
'...',
|
|
383
|
-
'.', // property accessor
|
|
378
|
+
'+', // addition
|
|
379
|
+
'-', // subtraction
|
|
380
|
+
];
|
|
381
|
+
var symbolicBinaryOperators = [
|
|
384
382
|
'**', // exponentiation
|
|
385
383
|
'*', // multiplication
|
|
386
384
|
'/', // division
|
|
@@ -404,12 +402,74 @@ var AlgebraicOperators = [
|
|
|
404
402
|
'||', // logical OR
|
|
405
403
|
'??', // nullish coalescing
|
|
406
404
|
];
|
|
407
|
-
|
|
408
|
-
|
|
405
|
+
var otherSymbolicOperators = [
|
|
406
|
+
'=>', // lambda
|
|
407
|
+
'...', // rest
|
|
408
|
+
'.', // property accessor
|
|
409
|
+
',', // item separator
|
|
410
|
+
'=', // property assignment
|
|
411
|
+
];
|
|
412
|
+
var symbolicOperators = __spreadArray(__spreadArray(__spreadArray([], __read(symbolicUnaryOperators), false), __read(symbolicBinaryOperators), false), __read(otherSymbolicOperators), false);
|
|
413
|
+
var nonFunctionOperators = [
|
|
414
|
+
'??',
|
|
415
|
+
'and',
|
|
416
|
+
'comment',
|
|
417
|
+
'cond',
|
|
418
|
+
'declared?',
|
|
419
|
+
'if',
|
|
420
|
+
'if-not',
|
|
421
|
+
'or',
|
|
422
|
+
'when',
|
|
423
|
+
'when-not',
|
|
424
|
+
'do',
|
|
425
|
+
'time!',
|
|
426
|
+
'throw',
|
|
427
|
+
'let',
|
|
428
|
+
'def',
|
|
429
|
+
'defs',
|
|
430
|
+
'if-let',
|
|
431
|
+
'when-let',
|
|
432
|
+
'when-first',
|
|
433
|
+
'fn',
|
|
434
|
+
'defn',
|
|
435
|
+
'defns',
|
|
436
|
+
'try',
|
|
437
|
+
'recur',
|
|
438
|
+
'loop',
|
|
439
|
+
'doseq',
|
|
440
|
+
'while',
|
|
441
|
+
];
|
|
442
|
+
var nonFunctionOperatorSet = new Set(nonFunctionOperators);
|
|
443
|
+
function isFunctionOperator(operator) {
|
|
444
|
+
return !nonFunctionOperatorSet.has(operator);
|
|
445
|
+
}
|
|
446
|
+
var symbolicUnaryOperatorSet = new Set(symbolicUnaryOperators);
|
|
447
|
+
function isSymbolicUnaryOperator(operator) {
|
|
448
|
+
return symbolicUnaryOperatorSet.has(operator);
|
|
449
|
+
}
|
|
450
|
+
var symbolicBinaryOperatorSet = new Set(symbolicBinaryOperators);
|
|
451
|
+
function isSymbolicBinaryOperator(operator) {
|
|
452
|
+
return symbolicBinaryOperatorSet.has(operator);
|
|
453
|
+
}
|
|
454
|
+
var symbolicOperatorSet = new Set(symbolicOperators);
|
|
455
|
+
function isSymbolicOperator(operator) {
|
|
456
|
+
return symbolicOperatorSet.has(operator);
|
|
409
457
|
}
|
|
410
458
|
function isA_SymbolToken(token) {
|
|
411
459
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_Symbol';
|
|
412
460
|
}
|
|
461
|
+
function assertA_SymbolToken(token) {
|
|
462
|
+
if (!isA_SymbolToken(token)) {
|
|
463
|
+
throwUnexpectedToken('A_Symbol', token);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
function asA_SymbolToken(token) {
|
|
467
|
+
assertA_SymbolToken(token);
|
|
468
|
+
return token;
|
|
469
|
+
}
|
|
470
|
+
function isA_BinaryOperatorToken(token) {
|
|
471
|
+
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_Operator' && isSymbolicBinaryOperator(token[1]);
|
|
472
|
+
}
|
|
413
473
|
function isA_ReservedSymbolToken(token) {
|
|
414
474
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_ReservedSymbol';
|
|
415
475
|
}
|
|
@@ -430,9 +490,10 @@ function isA_OperatorToken(token, operatorName) {
|
|
|
430
490
|
}
|
|
431
491
|
function assertA_OperatorToken(token, operatorName) {
|
|
432
492
|
if (!isA_OperatorToken(token, operatorName)) {
|
|
433
|
-
{
|
|
493
|
+
if (operatorName) {
|
|
434
494
|
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), undefined);
|
|
435
495
|
}
|
|
496
|
+
throwUnexpectedToken('A_Operator', token);
|
|
436
497
|
}
|
|
437
498
|
}
|
|
438
499
|
function isA_WhitespaceToken(token) {
|
|
@@ -441,6 +502,9 @@ function isA_WhitespaceToken(token) {
|
|
|
441
502
|
function isA_NumberToken(token) {
|
|
442
503
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_Number';
|
|
443
504
|
}
|
|
505
|
+
function isA_BasePrefixedNumberToken(token) {
|
|
506
|
+
return (token === null || token === void 0 ? void 0 : token[0]) === 'A_BasePrefixedNumber';
|
|
507
|
+
}
|
|
444
508
|
|
|
445
509
|
var modifierNames = ['&', '&let', '&when', '&while'];
|
|
446
510
|
var polishOnlySimpleTokenTypes = [
|
|
@@ -1406,7 +1470,7 @@ var collectionNormalExpression = {
|
|
|
1406
1470
|
},
|
|
1407
1471
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
1408
1472
|
},
|
|
1409
|
-
'
|
|
1473
|
+
'get_in': {
|
|
1410
1474
|
evaluate: function (params, sourceCodeInfo) {
|
|
1411
1475
|
var e_1, _a;
|
|
1412
1476
|
var _b;
|
|
@@ -1480,13 +1544,20 @@ var collectionNormalExpression = {
|
|
|
1480
1544
|
assertColl(coll, sourceCodeInfo);
|
|
1481
1545
|
if (Array.isArray(coll))
|
|
1482
1546
|
return coll.includes(value);
|
|
1483
|
-
if (typeof coll === 'string')
|
|
1484
|
-
|
|
1547
|
+
if (typeof coll === 'string') {
|
|
1548
|
+
if (typeof value === 'string') {
|
|
1549
|
+
return coll.includes(value);
|
|
1550
|
+
}
|
|
1551
|
+
else if (typeof value === 'number') {
|
|
1552
|
+
return coll.includes("".concat(value));
|
|
1553
|
+
}
|
|
1554
|
+
return false;
|
|
1555
|
+
}
|
|
1485
1556
|
return Object.values(coll).includes(value);
|
|
1486
1557
|
},
|
|
1487
1558
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1488
1559
|
},
|
|
1489
|
-
'
|
|
1560
|
+
'has_some?': {
|
|
1490
1561
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1491
1562
|
var e_2, _b, e_3, _c, e_4, _d;
|
|
1492
1563
|
var _e = __read(_a, 2), coll = _e[0], seq = _e[1];
|
|
@@ -1546,7 +1617,7 @@ var collectionNormalExpression = {
|
|
|
1546
1617
|
},
|
|
1547
1618
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1548
1619
|
},
|
|
1549
|
-
'
|
|
1620
|
+
'has_every?': {
|
|
1550
1621
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1551
1622
|
var e_5, _b, e_6, _c, e_7, _d;
|
|
1552
1623
|
var _e = __read(_a, 2), coll = _e[0], seq = _e[1];
|
|
@@ -1618,7 +1689,7 @@ var collectionNormalExpression = {
|
|
|
1618
1689
|
},
|
|
1619
1690
|
validate: function (node) { return assertNumberOfParams(3, node); },
|
|
1620
1691
|
},
|
|
1621
|
-
'
|
|
1692
|
+
'assoc_in': {
|
|
1622
1693
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1623
1694
|
var _b = __read(_a, 3), originalColl = _b[0], keys = _b[1], value = _b[2];
|
|
1624
1695
|
assertColl(originalColl, sourceCodeInfo);
|
|
@@ -1654,7 +1725,7 @@ var collectionNormalExpression = {
|
|
|
1654
1725
|
},
|
|
1655
1726
|
validate: function (node) { return assertNumberOfParams({ min: 3 }, node); },
|
|
1656
1727
|
},
|
|
1657
|
-
'
|
|
1728
|
+
'update_in': {
|
|
1658
1729
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1659
1730
|
var _c = __read(_a), originalColl = _c[0], keys = _c[1], fn = _c[2], params = _c.slice(3);
|
|
1660
1731
|
var executeFunction = _b.executeFunction;
|
|
@@ -1704,7 +1775,7 @@ var collectionNormalExpression = {
|
|
|
1704
1775
|
},
|
|
1705
1776
|
validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
1706
1777
|
},
|
|
1707
|
-
'
|
|
1778
|
+
'not_empty': {
|
|
1708
1779
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1709
1780
|
var _b = __read(_a, 1), coll = _b[0];
|
|
1710
1781
|
if (coll === null)
|
|
@@ -1720,10 +1791,10 @@ var collectionNormalExpression = {
|
|
|
1720
1791
|
},
|
|
1721
1792
|
'every?': {
|
|
1722
1793
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1723
|
-
var _c = __read(_a, 2),
|
|
1794
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
1724
1795
|
var executeFunction = _b.executeFunction;
|
|
1725
|
-
assertLitsFunction(fn, sourceCodeInfo);
|
|
1726
1796
|
assertColl(coll, sourceCodeInfo);
|
|
1797
|
+
assertLitsFunction(fn, sourceCodeInfo);
|
|
1727
1798
|
if (Array.isArray(coll))
|
|
1728
1799
|
return coll.every(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1729
1800
|
if (typeof coll === 'string')
|
|
@@ -1734,7 +1805,7 @@ var collectionNormalExpression = {
|
|
|
1734
1805
|
},
|
|
1735
1806
|
'any?': {
|
|
1736
1807
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1737
|
-
var _c = __read(_a, 2),
|
|
1808
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
1738
1809
|
var executeFunction = _b.executeFunction;
|
|
1739
1810
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
1740
1811
|
assertColl(coll, sourceCodeInfo);
|
|
@@ -1746,9 +1817,9 @@ var collectionNormalExpression = {
|
|
|
1746
1817
|
},
|
|
1747
1818
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1748
1819
|
},
|
|
1749
|
-
'
|
|
1820
|
+
'not_any?': {
|
|
1750
1821
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1751
|
-
var _c = __read(_a, 2),
|
|
1822
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
1752
1823
|
var executeFunction = _b.executeFunction;
|
|
1753
1824
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
1754
1825
|
assertColl(coll, sourceCodeInfo);
|
|
@@ -1760,9 +1831,9 @@ var collectionNormalExpression = {
|
|
|
1760
1831
|
},
|
|
1761
1832
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1762
1833
|
},
|
|
1763
|
-
'
|
|
1834
|
+
'not_every?': {
|
|
1764
1835
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1765
|
-
var _c = __read(_a, 2),
|
|
1836
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
1766
1837
|
var executeFunction = _b.executeFunction;
|
|
1767
1838
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
1768
1839
|
assertColl(coll, sourceCodeInfo);
|
|
@@ -1776,77 +1847,82 @@ var collectionNormalExpression = {
|
|
|
1776
1847
|
},
|
|
1777
1848
|
};
|
|
1778
1849
|
|
|
1779
|
-
var
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
var newVal = executeFunction(fn, [elem], contextStack, sourceCodeInfo);
|
|
1795
|
-
assertString(newVal, sourceCodeInfo, { char: true });
|
|
1796
|
-
return newVal;
|
|
1797
|
-
})
|
|
1798
|
-
.join('');
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
else {
|
|
1802
|
-
params.slice(2).forEach(function (collParam) {
|
|
1803
|
-
if (isStringSeq)
|
|
1804
|
-
assertString(collParam, sourceCodeInfo);
|
|
1805
|
-
else
|
|
1806
|
-
assertArray(collParam, sourceCodeInfo);
|
|
1807
|
-
if (length !== collParam.length)
|
|
1808
|
-
throw new LitsError('All arguments to "map" must have the same length.', sourceCodeInfo);
|
|
1809
|
-
});
|
|
1810
|
-
if (isStringSeq) {
|
|
1811
|
-
var result = '';
|
|
1812
|
-
var _loop_1 = function (i) {
|
|
1813
|
-
var fnParams = params.slice(1).map(function (l) { return l[i]; });
|
|
1814
|
-
var newValue = executeFunction(fn, fnParams, contextStack, sourceCodeInfo);
|
|
1815
|
-
assertString(newValue, sourceCodeInfo, { char: true });
|
|
1816
|
-
result += newValue;
|
|
1817
|
-
};
|
|
1818
|
-
for (var i = 0; i < length; i += 1) {
|
|
1819
|
-
_loop_1(i);
|
|
1850
|
+
var arrayNormalExpression = {
|
|
1851
|
+
array: {
|
|
1852
|
+
evaluate: function (params) { return params; },
|
|
1853
|
+
},
|
|
1854
|
+
range: {
|
|
1855
|
+
evaluate: function (params, sourceCodeInfo) {
|
|
1856
|
+
var _a = __read(params, 3), first = _a[0], second = _a[1], third = _a[2];
|
|
1857
|
+
var from;
|
|
1858
|
+
var to;
|
|
1859
|
+
var step;
|
|
1860
|
+
assertNumber(first, sourceCodeInfo, { finite: true });
|
|
1861
|
+
if (params.length === 1) {
|
|
1862
|
+
from = 0;
|
|
1863
|
+
to = first;
|
|
1864
|
+
step = to >= 0 ? 1 : -1;
|
|
1820
1865
|
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1866
|
+
else if (params.length === 2) {
|
|
1867
|
+
assertNumber(second, sourceCodeInfo, { finite: true });
|
|
1868
|
+
from = first;
|
|
1869
|
+
to = second;
|
|
1870
|
+
step = to >= from ? 1 : -1;
|
|
1871
|
+
}
|
|
1872
|
+
else {
|
|
1873
|
+
assertNumber(second, sourceCodeInfo, { finite: true });
|
|
1874
|
+
assertNumber(third, sourceCodeInfo, { finite: true });
|
|
1875
|
+
from = first;
|
|
1876
|
+
to = second;
|
|
1877
|
+
step = third;
|
|
1878
|
+
if (to > from)
|
|
1879
|
+
assertNumber(step, sourceCodeInfo, { positive: true });
|
|
1880
|
+
else if (to < from)
|
|
1881
|
+
assertNumber(step, sourceCodeInfo, { negative: true });
|
|
1882
|
+
else
|
|
1883
|
+
assertNumber(step, sourceCodeInfo, { nonZero: true });
|
|
1831
1884
|
}
|
|
1885
|
+
var result = [];
|
|
1886
|
+
for (var i = from; step < 0 ? i > to : i < to; i += step)
|
|
1887
|
+
result.push(i);
|
|
1832
1888
|
return result;
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
'cons': {
|
|
1889
|
+
},
|
|
1890
|
+
validate: function (node) { return assertNumberOfParams({ min: 1, max: 3 }, node); },
|
|
1891
|
+
},
|
|
1892
|
+
repeat: {
|
|
1838
1893
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1839
|
-
var _b = __read(_a, 2),
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1894
|
+
var _b = __read(_a, 2), value = _b[0], count = _b[1];
|
|
1895
|
+
assertNumber(count, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
1896
|
+
var result = [];
|
|
1897
|
+
for (var i = 0; i < count; i += 1)
|
|
1898
|
+
result.push(value);
|
|
1899
|
+
return result;
|
|
1900
|
+
},
|
|
1901
|
+
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1902
|
+
},
|
|
1903
|
+
flatten: {
|
|
1904
|
+
evaluate: function (_a) {
|
|
1905
|
+
var _b = __read(_a, 1), seq = _b[0];
|
|
1906
|
+
if (!Array.isArray(seq))
|
|
1907
|
+
return [];
|
|
1908
|
+
return seq.flat(Number.POSITIVE_INFINITY);
|
|
1909
|
+
},
|
|
1910
|
+
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
1911
|
+
},
|
|
1912
|
+
mapcat: {
|
|
1913
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1914
|
+
var _c = __read(_a, 2), arr = _c[0], fn = _c[1];
|
|
1915
|
+
var executeFunction = _b.executeFunction;
|
|
1916
|
+
assertArray(arr, sourceCodeInfo);
|
|
1917
|
+
assertLitsFunction(fn, sourceCodeInfo);
|
|
1918
|
+
return arr.map(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); }).flat(1);
|
|
1846
1919
|
},
|
|
1847
1920
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1848
1921
|
},
|
|
1849
|
-
|
|
1922
|
+
};
|
|
1923
|
+
|
|
1924
|
+
var sequenceNormalExpression = {
|
|
1925
|
+
nth: {
|
|
1850
1926
|
evaluate: function (params, sourceCodeInfo) {
|
|
1851
1927
|
var _a = __read(params, 2), seq = _a[0], i = _a[1];
|
|
1852
1928
|
var defaultValue = toAny(params[2]);
|
|
@@ -1858,12 +1934,12 @@ var sequenceNormalExpression = {
|
|
|
1858
1934
|
},
|
|
1859
1935
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
1860
1936
|
},
|
|
1861
|
-
|
|
1937
|
+
filter: {
|
|
1862
1938
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1863
|
-
var _c = __read(_a, 2),
|
|
1939
|
+
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
1864
1940
|
var executeFunction = _b.executeFunction;
|
|
1865
|
-
assertLitsFunction(fn, sourceCodeInfo);
|
|
1866
1941
|
assertSeq(seq, sourceCodeInfo);
|
|
1942
|
+
assertLitsFunction(fn, sourceCodeInfo);
|
|
1867
1943
|
if (Array.isArray(seq))
|
|
1868
1944
|
return seq.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1869
1945
|
return seq
|
|
@@ -1873,7 +1949,7 @@ var sequenceNormalExpression = {
|
|
|
1873
1949
|
},
|
|
1874
1950
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1875
1951
|
},
|
|
1876
|
-
|
|
1952
|
+
first: {
|
|
1877
1953
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1878
1954
|
var _b = __read(_a, 1), array = _b[0];
|
|
1879
1955
|
if (array === null)
|
|
@@ -1883,7 +1959,7 @@ var sequenceNormalExpression = {
|
|
|
1883
1959
|
},
|
|
1884
1960
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
1885
1961
|
},
|
|
1886
|
-
|
|
1962
|
+
last: {
|
|
1887
1963
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1888
1964
|
var _b = __read(_a, 1), array = _b[0];
|
|
1889
1965
|
if (array === null)
|
|
@@ -1893,25 +1969,42 @@ var sequenceNormalExpression = {
|
|
|
1893
1969
|
},
|
|
1894
1970
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
1895
1971
|
},
|
|
1896
|
-
|
|
1897
|
-
evaluate:
|
|
1898
|
-
|
|
1972
|
+
map: {
|
|
1973
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1974
|
+
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
1975
|
+
var executeFunction = _b.executeFunction;
|
|
1976
|
+
assertSeq(seq, sourceCodeInfo);
|
|
1977
|
+
assertLitsFunction(fn, sourceCodeInfo);
|
|
1978
|
+
if (Array.isArray(seq)) {
|
|
1979
|
+
return seq.map(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1980
|
+
}
|
|
1981
|
+
else {
|
|
1982
|
+
return seq
|
|
1983
|
+
.split('')
|
|
1984
|
+
.map(function (elem) {
|
|
1985
|
+
var newVal = executeFunction(fn, [elem], contextStack, sourceCodeInfo);
|
|
1986
|
+
assertString(newVal, sourceCodeInfo, { char: true });
|
|
1987
|
+
return newVal;
|
|
1988
|
+
})
|
|
1989
|
+
.join('');
|
|
1990
|
+
}
|
|
1991
|
+
},
|
|
1992
|
+
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1899
1993
|
},
|
|
1900
|
-
|
|
1994
|
+
pop: {
|
|
1901
1995
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1902
1996
|
var _b = __read(_a, 1), seq = _b[0];
|
|
1903
1997
|
assertSeq(seq, sourceCodeInfo);
|
|
1904
|
-
if (typeof seq === 'string')
|
|
1998
|
+
if (typeof seq === 'string') {
|
|
1905
1999
|
return seq.substring(0, seq.length - 1);
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
return copy;
|
|
2000
|
+
}
|
|
2001
|
+
return seq.slice(0, seq.length - 1);
|
|
1909
2002
|
},
|
|
1910
2003
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
1911
2004
|
},
|
|
1912
|
-
|
|
2005
|
+
position: {
|
|
1913
2006
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1914
|
-
var _c = __read(_a, 2),
|
|
2007
|
+
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
1915
2008
|
var executeFunction = _b.executeFunction;
|
|
1916
2009
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
1917
2010
|
if (seq === null)
|
|
@@ -1928,7 +2021,7 @@ var sequenceNormalExpression = {
|
|
|
1928
2021
|
},
|
|
1929
2022
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1930
2023
|
},
|
|
1931
|
-
|
|
2024
|
+
index_of: {
|
|
1932
2025
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1933
2026
|
var _b = __read(_a, 2), seq = _b[0], value = _b[1];
|
|
1934
2027
|
assertAny(value, sourceCodeInfo);
|
|
@@ -1947,7 +2040,7 @@ var sequenceNormalExpression = {
|
|
|
1947
2040
|
},
|
|
1948
2041
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
1949
2042
|
},
|
|
1950
|
-
|
|
2043
|
+
push: {
|
|
1951
2044
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1952
2045
|
var _b = __read(_a), seq = _b[0], values = _b.slice(1);
|
|
1953
2046
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -1961,20 +2054,19 @@ var sequenceNormalExpression = {
|
|
|
1961
2054
|
},
|
|
1962
2055
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
1963
2056
|
},
|
|
1964
|
-
|
|
2057
|
+
reductions: {
|
|
1965
2058
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1966
2059
|
var executeFunction = _a.executeFunction;
|
|
1967
|
-
var
|
|
2060
|
+
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
2061
|
+
assertSeq(seq, sourceCodeInfo);
|
|
1968
2062
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
1969
2063
|
if (params.length === 2) {
|
|
1970
|
-
|
|
1971
|
-
assertSeq(arr, sourceCodeInfo);
|
|
1972
|
-
if (arr.length === 0)
|
|
2064
|
+
if (seq.length === 0)
|
|
1973
2065
|
return [executeFunction(fn, [], contextStack, sourceCodeInfo)];
|
|
1974
|
-
else if (
|
|
1975
|
-
return [toAny(
|
|
1976
|
-
if (typeof
|
|
1977
|
-
var chars =
|
|
2066
|
+
else if (seq.length === 1)
|
|
2067
|
+
return [toAny(seq[0])];
|
|
2068
|
+
if (typeof seq === 'string') {
|
|
2069
|
+
var chars = seq.split('');
|
|
1978
2070
|
var resultArray_1 = [asAny(chars[0], sourceCodeInfo)];
|
|
1979
2071
|
chars.slice(1).reduce(function (result, elem) {
|
|
1980
2072
|
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
@@ -1984,19 +2076,18 @@ var sequenceNormalExpression = {
|
|
|
1984
2076
|
return resultArray_1;
|
|
1985
2077
|
}
|
|
1986
2078
|
else {
|
|
1987
|
-
var resultArray_2 = [toAny(
|
|
1988
|
-
|
|
2079
|
+
var resultArray_2 = [toAny(seq[0])];
|
|
2080
|
+
seq.slice(1).reduce(function (result, elem) {
|
|
1989
2081
|
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1990
2082
|
resultArray_2.push(newVal);
|
|
1991
2083
|
return newVal;
|
|
1992
|
-
}, toAny(
|
|
2084
|
+
}, toAny(seq[0]));
|
|
1993
2085
|
return resultArray_2;
|
|
1994
2086
|
}
|
|
1995
2087
|
}
|
|
1996
2088
|
else {
|
|
1997
|
-
var
|
|
2089
|
+
var val = params[2];
|
|
1998
2090
|
assertAny(val, sourceCodeInfo);
|
|
1999
|
-
assertSeq(seq, sourceCodeInfo);
|
|
2000
2091
|
if (typeof seq === 'string') {
|
|
2001
2092
|
assertString(val, sourceCodeInfo);
|
|
2002
2093
|
if (seq.length === 0)
|
|
@@ -2024,35 +2115,33 @@ var sequenceNormalExpression = {
|
|
|
2024
2115
|
},
|
|
2025
2116
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
2026
2117
|
},
|
|
2027
|
-
|
|
2118
|
+
reduce: {
|
|
2028
2119
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
2029
2120
|
var executeFunction = _a.executeFunction;
|
|
2030
|
-
var
|
|
2121
|
+
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
2122
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2031
2123
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
2032
2124
|
if (params.length === 2) {
|
|
2033
|
-
|
|
2034
|
-
assertSeq(arr, sourceCodeInfo);
|
|
2035
|
-
if (arr.length === 0)
|
|
2125
|
+
if (seq.length === 0)
|
|
2036
2126
|
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
2037
|
-
else if (
|
|
2038
|
-
return toAny(
|
|
2039
|
-
if (typeof
|
|
2040
|
-
var chars =
|
|
2127
|
+
else if (seq.length === 1)
|
|
2128
|
+
return toAny(seq[0]);
|
|
2129
|
+
if (typeof seq === 'string') {
|
|
2130
|
+
var chars = seq.split('');
|
|
2041
2131
|
return chars.slice(1).reduce(function (result, elem) {
|
|
2042
2132
|
var val = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
2043
2133
|
return val;
|
|
2044
2134
|
}, asAny(chars[0], sourceCodeInfo));
|
|
2045
2135
|
}
|
|
2046
2136
|
else {
|
|
2047
|
-
return
|
|
2137
|
+
return seq.slice(1).reduce(function (result, elem) {
|
|
2048
2138
|
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
2049
|
-
}, toAny(
|
|
2139
|
+
}, toAny(seq[0]));
|
|
2050
2140
|
}
|
|
2051
2141
|
}
|
|
2052
2142
|
else {
|
|
2053
|
-
var
|
|
2143
|
+
var val = params[2];
|
|
2054
2144
|
assertAny(val, sourceCodeInfo);
|
|
2055
|
-
assertSeq(seq, sourceCodeInfo);
|
|
2056
2145
|
if (typeof seq === 'string') {
|
|
2057
2146
|
assertString(val, sourceCodeInfo);
|
|
2058
2147
|
if (seq.length === 0)
|
|
@@ -2073,14 +2162,13 @@ var sequenceNormalExpression = {
|
|
|
2073
2162
|
},
|
|
2074
2163
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
2075
2164
|
},
|
|
2076
|
-
|
|
2165
|
+
reduce_right: {
|
|
2077
2166
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
2078
2167
|
var executeFunction = _a.executeFunction;
|
|
2079
|
-
var
|
|
2168
|
+
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
2169
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2080
2170
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
2081
2171
|
if (params.length === 2) {
|
|
2082
|
-
var _b = __read(params, 2), seq = _b[1];
|
|
2083
|
-
assertSeq(seq, sourceCodeInfo);
|
|
2084
2172
|
if (seq.length === 0)
|
|
2085
2173
|
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
2086
2174
|
else if (seq.length === 1)
|
|
@@ -2100,7 +2188,7 @@ var sequenceNormalExpression = {
|
|
|
2100
2188
|
}
|
|
2101
2189
|
}
|
|
2102
2190
|
else {
|
|
2103
|
-
var
|
|
2191
|
+
var val = params[2];
|
|
2104
2192
|
assertAny(val, sourceCodeInfo);
|
|
2105
2193
|
assertSeq(seq, sourceCodeInfo);
|
|
2106
2194
|
if (typeof seq === 'string') {
|
|
@@ -2122,20 +2210,20 @@ var sequenceNormalExpression = {
|
|
|
2122
2210
|
},
|
|
2123
2211
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
2124
2212
|
},
|
|
2125
|
-
|
|
2213
|
+
rest: {
|
|
2126
2214
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2127
|
-
var _b = __read(_a, 1),
|
|
2128
|
-
assertSeq(
|
|
2129
|
-
if (Array.isArray(
|
|
2130
|
-
if (
|
|
2215
|
+
var _b = __read(_a, 1), seq = _b[0];
|
|
2216
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2217
|
+
if (Array.isArray(seq)) {
|
|
2218
|
+
if (seq.length <= 1)
|
|
2131
2219
|
return [];
|
|
2132
|
-
return
|
|
2220
|
+
return seq.slice(1);
|
|
2133
2221
|
}
|
|
2134
|
-
return
|
|
2222
|
+
return seq.substring(1);
|
|
2135
2223
|
},
|
|
2136
2224
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2137
2225
|
},
|
|
2138
|
-
|
|
2226
|
+
nthrest: {
|
|
2139
2227
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2140
2228
|
var _b = __read(_a, 2), seq = _b[0], count = _b[1];
|
|
2141
2229
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -2147,22 +2235,22 @@ var sequenceNormalExpression = {
|
|
|
2147
2235
|
},
|
|
2148
2236
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2149
2237
|
},
|
|
2150
|
-
|
|
2238
|
+
next: {
|
|
2151
2239
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2152
|
-
var _b = __read(_a, 1),
|
|
2153
|
-
assertSeq(
|
|
2154
|
-
if (Array.isArray(
|
|
2155
|
-
if (
|
|
2240
|
+
var _b = __read(_a, 1), seq = _b[0];
|
|
2241
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2242
|
+
if (Array.isArray(seq)) {
|
|
2243
|
+
if (seq.length <= 1)
|
|
2156
2244
|
return null;
|
|
2157
|
-
return
|
|
2245
|
+
return seq.slice(1);
|
|
2158
2246
|
}
|
|
2159
|
-
if (
|
|
2247
|
+
if (seq.length <= 1)
|
|
2160
2248
|
return null;
|
|
2161
|
-
return
|
|
2249
|
+
return seq.substring(1);
|
|
2162
2250
|
},
|
|
2163
2251
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2164
2252
|
},
|
|
2165
|
-
|
|
2253
|
+
nthnext: {
|
|
2166
2254
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2167
2255
|
var _b = __read(_a, 2), seq = _b[0], count = _b[1];
|
|
2168
2256
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -2176,7 +2264,7 @@ var sequenceNormalExpression = {
|
|
|
2176
2264
|
},
|
|
2177
2265
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2178
2266
|
},
|
|
2179
|
-
|
|
2267
|
+
reverse: {
|
|
2180
2268
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2181
2269
|
var _b = __read(_a, 1), seq = _b[0];
|
|
2182
2270
|
if (seq === null)
|
|
@@ -2188,17 +2276,17 @@ var sequenceNormalExpression = {
|
|
|
2188
2276
|
},
|
|
2189
2277
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2190
2278
|
},
|
|
2191
|
-
|
|
2279
|
+
second: {
|
|
2192
2280
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2193
|
-
var _b = __read(_a, 1),
|
|
2194
|
-
if (
|
|
2281
|
+
var _b = __read(_a, 1), seq = _b[0];
|
|
2282
|
+
if (seq === null)
|
|
2195
2283
|
return null;
|
|
2196
|
-
assertSeq(
|
|
2197
|
-
return toAny(
|
|
2284
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2285
|
+
return toAny(seq[1]);
|
|
2198
2286
|
},
|
|
2199
2287
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2200
2288
|
},
|
|
2201
|
-
|
|
2289
|
+
shift: {
|
|
2202
2290
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2203
2291
|
var _b = __read(_a, 1), seq = _b[0];
|
|
2204
2292
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -2210,7 +2298,7 @@ var sequenceNormalExpression = {
|
|
|
2210
2298
|
},
|
|
2211
2299
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2212
2300
|
},
|
|
2213
|
-
|
|
2301
|
+
slice: {
|
|
2214
2302
|
evaluate: function (params, sourceCodeInfo) {
|
|
2215
2303
|
var _a = __read(params, 3), seq = _a[0], from = _a[1], to = _a[2];
|
|
2216
2304
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -2224,10 +2312,10 @@ var sequenceNormalExpression = {
|
|
|
2224
2312
|
},
|
|
2225
2313
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 3 }, node); },
|
|
2226
2314
|
},
|
|
2227
|
-
|
|
2315
|
+
some: {
|
|
2228
2316
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
2229
2317
|
var _c;
|
|
2230
|
-
var _d = __read(_a, 2),
|
|
2318
|
+
var _d = __read(_a, 2), seq = _d[0], fn = _d[1];
|
|
2231
2319
|
var executeFunction = _b.executeFunction;
|
|
2232
2320
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
2233
2321
|
if (seq === null)
|
|
@@ -2241,12 +2329,12 @@ var sequenceNormalExpression = {
|
|
|
2241
2329
|
},
|
|
2242
2330
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2243
2331
|
},
|
|
2244
|
-
|
|
2332
|
+
sort: {
|
|
2245
2333
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
2246
2334
|
var executeFunction = _a.executeFunction;
|
|
2335
|
+
var _b = __read(params, 1), seq = _b[0];
|
|
2247
2336
|
var defaultComparer = params.length === 1;
|
|
2248
|
-
var
|
|
2249
|
-
var comparer = defaultComparer ? null : params[0];
|
|
2337
|
+
var comparer = defaultComparer ? null : params[1];
|
|
2250
2338
|
assertSeq(seq, sourceCodeInfo);
|
|
2251
2339
|
if (typeof seq === 'string') {
|
|
2252
2340
|
var result_1 = seq.split('');
|
|
@@ -2279,13 +2367,14 @@ var sequenceNormalExpression = {
|
|
|
2279
2367
|
},
|
|
2280
2368
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
2281
2369
|
},
|
|
2282
|
-
|
|
2370
|
+
sort_by: {
|
|
2283
2371
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
2284
2372
|
var executeFunction = _a.executeFunction;
|
|
2373
|
+
var _b = __read(params, 2), seq = _b[0], keyfn = _b[1];
|
|
2285
2374
|
var defaultComparer = params.length === 2;
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
var
|
|
2375
|
+
assertSeq(seq, sourceCodeInfo);
|
|
2376
|
+
assertAny(keyfn, sourceCodeInfo);
|
|
2377
|
+
var comparer = defaultComparer ? null : params[2];
|
|
2289
2378
|
if (typeof seq === 'string') {
|
|
2290
2379
|
var result_2 = seq.split('');
|
|
2291
2380
|
if (defaultComparer) {
|
|
@@ -2329,9 +2418,9 @@ var sequenceNormalExpression = {
|
|
|
2329
2418
|
},
|
|
2330
2419
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
2331
2420
|
},
|
|
2332
|
-
|
|
2421
|
+
take: {
|
|
2333
2422
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2334
|
-
var _b = __read(_a, 2),
|
|
2423
|
+
var _b = __read(_a, 2), input = _b[0], n = _b[1];
|
|
2335
2424
|
assertNumber(n, sourceCodeInfo);
|
|
2336
2425
|
assertSeq(input, sourceCodeInfo);
|
|
2337
2426
|
var num = Math.max(Math.ceil(n), 0);
|
|
@@ -2339,9 +2428,9 @@ var sequenceNormalExpression = {
|
|
|
2339
2428
|
},
|
|
2340
2429
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2341
2430
|
},
|
|
2342
|
-
|
|
2431
|
+
take_last: {
|
|
2343
2432
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2344
|
-
var _b = __read(_a, 2),
|
|
2433
|
+
var _b = __read(_a, 2), array = _b[0], n = _b[1];
|
|
2345
2434
|
assertSeq(array, sourceCodeInfo);
|
|
2346
2435
|
assertNumber(n, sourceCodeInfo);
|
|
2347
2436
|
var num = Math.max(Math.ceil(n), 0);
|
|
@@ -2350,10 +2439,10 @@ var sequenceNormalExpression = {
|
|
|
2350
2439
|
},
|
|
2351
2440
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2352
2441
|
},
|
|
2353
|
-
|
|
2442
|
+
take_while: {
|
|
2354
2443
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
2355
2444
|
var e_1, _c;
|
|
2356
|
-
var _d = __read(_a, 2),
|
|
2445
|
+
var _d = __read(_a, 2), seq = _d[0], fn = _d[1];
|
|
2357
2446
|
var executeFunction = _b.executeFunction;
|
|
2358
2447
|
assertSeq(seq, sourceCodeInfo);
|
|
2359
2448
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
@@ -2378,9 +2467,9 @@ var sequenceNormalExpression = {
|
|
|
2378
2467
|
},
|
|
2379
2468
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2380
2469
|
},
|
|
2381
|
-
|
|
2470
|
+
drop: {
|
|
2382
2471
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2383
|
-
var _b = __read(_a, 2),
|
|
2472
|
+
var _b = __read(_a, 2), input = _b[0], n = _b[1];
|
|
2384
2473
|
assertNumber(n, sourceCodeInfo);
|
|
2385
2474
|
var num = Math.max(Math.ceil(n), 0);
|
|
2386
2475
|
assertSeq(input, sourceCodeInfo);
|
|
@@ -2388,9 +2477,9 @@ var sequenceNormalExpression = {
|
|
|
2388
2477
|
},
|
|
2389
2478
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2390
2479
|
},
|
|
2391
|
-
|
|
2480
|
+
drop_last: {
|
|
2392
2481
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2393
|
-
var _b = __read(_a, 2),
|
|
2482
|
+
var _b = __read(_a, 2), array = _b[0], n = _b[1];
|
|
2394
2483
|
assertSeq(array, sourceCodeInfo);
|
|
2395
2484
|
assertNumber(n, sourceCodeInfo);
|
|
2396
2485
|
var num = Math.max(Math.ceil(n), 0);
|
|
@@ -2399,9 +2488,9 @@ var sequenceNormalExpression = {
|
|
|
2399
2488
|
},
|
|
2400
2489
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2401
2490
|
},
|
|
2402
|
-
|
|
2491
|
+
drop_while: {
|
|
2403
2492
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
2404
|
-
var _c = __read(_a, 2),
|
|
2493
|
+
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
2405
2494
|
var executeFunction = _b.executeFunction;
|
|
2406
2495
|
assertSeq(seq, sourceCodeInfo);
|
|
2407
2496
|
assertLitsFunction(fn, sourceCodeInfo);
|
|
@@ -2415,7 +2504,7 @@ var sequenceNormalExpression = {
|
|
|
2415
2504
|
},
|
|
2416
2505
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2417
2506
|
},
|
|
2418
|
-
|
|
2507
|
+
unshift: {
|
|
2419
2508
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2420
2509
|
var _b = __read(_a), seq = _b[0], values = _b.slice(1);
|
|
2421
2510
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -2429,59 +2518,7 @@ var sequenceNormalExpression = {
|
|
|
2429
2518
|
},
|
|
2430
2519
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
2431
2520
|
},
|
|
2432
|
-
|
|
2433
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
2434
|
-
var _b = __read(_a, 2), prob = _b[0], seq = _b[1];
|
|
2435
|
-
assertNumber(prob, sourceCodeInfo, { finite: true });
|
|
2436
|
-
assertSeq(seq, sourceCodeInfo);
|
|
2437
|
-
if (typeof seq === 'string') {
|
|
2438
|
-
return seq
|
|
2439
|
-
.split('')
|
|
2440
|
-
.filter(function () { return Math.random() < prob; })
|
|
2441
|
-
.join('');
|
|
2442
|
-
}
|
|
2443
|
-
else {
|
|
2444
|
-
return seq.filter(function () { return Math.random() < prob; });
|
|
2445
|
-
}
|
|
2446
|
-
},
|
|
2447
|
-
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2448
|
-
},
|
|
2449
|
-
'rand-nth!': {
|
|
2450
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
2451
|
-
var _b = __read(_a, 1), seq = _b[0];
|
|
2452
|
-
assertSeq(seq, sourceCodeInfo);
|
|
2453
|
-
if (seq.length === 0)
|
|
2454
|
-
return null;
|
|
2455
|
-
var index = Math.floor(Math.random() * seq.length);
|
|
2456
|
-
if (typeof seq === 'string')
|
|
2457
|
-
return toAny(seq.split('')[index]);
|
|
2458
|
-
return toAny(seq[index]);
|
|
2459
|
-
},
|
|
2460
|
-
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2461
|
-
},
|
|
2462
|
-
'shuffle!': {
|
|
2463
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
2464
|
-
var _b = __read(_a, 1), input = _b[0];
|
|
2465
|
-
assertSeq(input, sourceCodeInfo);
|
|
2466
|
-
var array = typeof input === 'string' ? __spreadArray([], __read(input.split('')), false) : __spreadArray([], __read(input), false);
|
|
2467
|
-
var remainingLength = array.length;
|
|
2468
|
-
var arrayElement;
|
|
2469
|
-
var pickedIndex;
|
|
2470
|
-
// Fisher–Yates Shuffle
|
|
2471
|
-
while (remainingLength) {
|
|
2472
|
-
remainingLength -= 1;
|
|
2473
|
-
// Pick a remaining element
|
|
2474
|
-
pickedIndex = Math.floor(Math.random() * remainingLength);
|
|
2475
|
-
// And swap it with the current element.
|
|
2476
|
-
arrayElement = toAny(array[remainingLength]);
|
|
2477
|
-
array[remainingLength] = toAny(array[pickedIndex]);
|
|
2478
|
-
array[pickedIndex] = arrayElement;
|
|
2479
|
-
}
|
|
2480
|
-
return typeof input === 'string' ? array.join('') : array;
|
|
2481
|
-
},
|
|
2482
|
-
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2483
|
-
},
|
|
2484
|
-
'distinct': {
|
|
2521
|
+
distinct: {
|
|
2485
2522
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2486
2523
|
var _b = __read(_a, 1), input = _b[0];
|
|
2487
2524
|
assertSeq(input, sourceCodeInfo);
|
|
@@ -2491,7 +2528,7 @@ var sequenceNormalExpression = {
|
|
|
2491
2528
|
},
|
|
2492
2529
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2493
2530
|
},
|
|
2494
|
-
|
|
2531
|
+
remove: {
|
|
2495
2532
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
2496
2533
|
var _c = __read(_a, 2), fn = _c[0], input = _c[1];
|
|
2497
2534
|
var executeFunction = _b.executeFunction;
|
|
@@ -2506,7 +2543,7 @@ var sequenceNormalExpression = {
|
|
|
2506
2543
|
},
|
|
2507
2544
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2508
2545
|
},
|
|
2509
|
-
|
|
2546
|
+
remove_at: {
|
|
2510
2547
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2511
2548
|
var _b = __read(_a, 2), index = _b[0], input = _b[1];
|
|
2512
2549
|
assertNumber(index, sourceCodeInfo);
|
|
@@ -2523,7 +2560,7 @@ var sequenceNormalExpression = {
|
|
|
2523
2560
|
},
|
|
2524
2561
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2525
2562
|
},
|
|
2526
|
-
|
|
2563
|
+
split_at: {
|
|
2527
2564
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2528
2565
|
var _b = __read(_a, 2), pos = _b[0], seq = _b[1];
|
|
2529
2566
|
assertNumber(pos, sourceCodeInfo, { finite: true });
|
|
@@ -2533,7 +2570,7 @@ var sequenceNormalExpression = {
|
|
|
2533
2570
|
},
|
|
2534
2571
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2535
2572
|
},
|
|
2536
|
-
|
|
2573
|
+
split_with: {
|
|
2537
2574
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
2538
2575
|
var _c = __read(_a, 2), fn = _c[0], seq = _c[1];
|
|
2539
2576
|
var executeFunction = _b.executeFunction;
|
|
@@ -2548,7 +2585,7 @@ var sequenceNormalExpression = {
|
|
|
2548
2585
|
},
|
|
2549
2586
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2550
2587
|
},
|
|
2551
|
-
|
|
2588
|
+
frequencies: {
|
|
2552
2589
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2553
2590
|
var _b = __read(_a, 1), seq = _b[0];
|
|
2554
2591
|
assertSeq(seq, sourceCodeInfo);
|
|
@@ -2564,7 +2601,7 @@ var sequenceNormalExpression = {
|
|
|
2564
2601
|
},
|
|
2565
2602
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2566
2603
|
},
|
|
2567
|
-
|
|
2604
|
+
group_by: {
|
|
2568
2605
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
2569
2606
|
var _c = __read(_a, 2), fn = _c[0], seq = _c[1];
|
|
2570
2607
|
var executeFunction = _b.executeFunction;
|
|
@@ -2582,7 +2619,7 @@ var sequenceNormalExpression = {
|
|
|
2582
2619
|
},
|
|
2583
2620
|
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2584
2621
|
},
|
|
2585
|
-
|
|
2622
|
+
partition: {
|
|
2586
2623
|
evaluate: function (params, sourceCodeInfo) {
|
|
2587
2624
|
var len = params.length;
|
|
2588
2625
|
var n = toNonNegativeInteger(asNumber(params[0], sourceCodeInfo));
|
|
@@ -2597,7 +2634,7 @@ var sequenceNormalExpression = {
|
|
|
2597
2634
|
},
|
|
2598
2635
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 4 }, node); },
|
|
2599
2636
|
},
|
|
2600
|
-
|
|
2637
|
+
partition_all: {
|
|
2601
2638
|
evaluate: function (params, sourceCodeInfo) {
|
|
2602
2639
|
var len = params.length;
|
|
2603
2640
|
var n = toNonNegativeInteger(asNumber(params[0], sourceCodeInfo));
|
|
@@ -2607,7 +2644,7 @@ var sequenceNormalExpression = {
|
|
|
2607
2644
|
},
|
|
2608
2645
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
2609
2646
|
},
|
|
2610
|
-
|
|
2647
|
+
partition_by: {
|
|
2611
2648
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
2612
2649
|
var _c = __read(_a, 2), fn = _c[0], seq = _c[1];
|
|
2613
2650
|
var executeFunction = _b.executeFunction;
|
|
@@ -2657,94 +2694,22 @@ function partition(n, step, seq, pad, sourceCodeInfo) {
|
|
|
2657
2694
|
return isStringSeq ? result.map(function (x) { return x.join(''); }) : result;
|
|
2658
2695
|
}
|
|
2659
2696
|
|
|
2660
|
-
var
|
|
2661
|
-
|
|
2662
|
-
evaluate: function (
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
var _a = __read(params, 3), first = _a[0], second = _a[1], third = _a[2];
|
|
2667
|
-
var from;
|
|
2668
|
-
var to;
|
|
2669
|
-
var step;
|
|
2670
|
-
assertNumber(first, sourceCodeInfo, { finite: true });
|
|
2671
|
-
if (params.length === 1) {
|
|
2672
|
-
from = 0;
|
|
2673
|
-
to = first;
|
|
2674
|
-
step = to >= 0 ? 1 : -1;
|
|
2675
|
-
}
|
|
2676
|
-
else if (params.length === 2) {
|
|
2677
|
-
assertNumber(second, sourceCodeInfo, { finite: true });
|
|
2678
|
-
from = first;
|
|
2679
|
-
to = second;
|
|
2680
|
-
step = to >= from ? 1 : -1;
|
|
2681
|
-
}
|
|
2682
|
-
else {
|
|
2683
|
-
assertNumber(second, sourceCodeInfo, { finite: true });
|
|
2684
|
-
assertNumber(third, sourceCodeInfo, { finite: true });
|
|
2685
|
-
from = first;
|
|
2686
|
-
to = second;
|
|
2687
|
-
step = third;
|
|
2688
|
-
if (to > from)
|
|
2689
|
-
assertNumber(step, sourceCodeInfo, { positive: true });
|
|
2690
|
-
else if (to < from)
|
|
2691
|
-
assertNumber(step, sourceCodeInfo, { negative: true });
|
|
2692
|
-
else
|
|
2693
|
-
assertNumber(step, sourceCodeInfo, { nonZero: true });
|
|
2694
|
-
}
|
|
2695
|
-
var result = [];
|
|
2696
|
-
for (var i = from; step < 0 ? i > to : i < to; i += step)
|
|
2697
|
-
result.push(i);
|
|
2698
|
-
return result;
|
|
2697
|
+
var mathNormalExpression = {
|
|
2698
|
+
'inc': {
|
|
2699
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
2700
|
+
var _b = __read(_a, 1), first = _b[0];
|
|
2701
|
+
assertNumber(first, sourceCodeInfo);
|
|
2702
|
+
return first + 1;
|
|
2699
2703
|
},
|
|
2700
|
-
validate: function (node) { return assertNumberOfParams(
|
|
2704
|
+
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2701
2705
|
},
|
|
2702
|
-
|
|
2706
|
+
'dec': {
|
|
2703
2707
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2704
|
-
var _b = __read(_a,
|
|
2705
|
-
assertNumber(
|
|
2706
|
-
|
|
2707
|
-
for (var i = 0; i < count; i += 1)
|
|
2708
|
-
result.push(value);
|
|
2709
|
-
return result;
|
|
2708
|
+
var _b = __read(_a, 1), first = _b[0];
|
|
2709
|
+
assertNumber(first, sourceCodeInfo);
|
|
2710
|
+
return first - 1;
|
|
2710
2711
|
},
|
|
2711
|
-
validate: function (node) { return assertNumberOfParams(
|
|
2712
|
-
},
|
|
2713
|
-
flatten: {
|
|
2714
|
-
evaluate: function (_a) {
|
|
2715
|
-
var _b = __read(_a, 1), seq = _b[0];
|
|
2716
|
-
if (!Array.isArray(seq))
|
|
2717
|
-
return [];
|
|
2718
|
-
return seq.flat(Number.POSITIVE_INFINITY);
|
|
2719
|
-
},
|
|
2720
|
-
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2721
|
-
},
|
|
2722
|
-
mapcat: {
|
|
2723
|
-
evaluate: function (params, sourceCodeInfo, contextStack, helpers) {
|
|
2724
|
-
var mapResult = evaluateMap(params, sourceCodeInfo, contextStack, helpers);
|
|
2725
|
-
assertArray(mapResult, sourceCodeInfo);
|
|
2726
|
-
return mapResult.flat(1);
|
|
2727
|
-
},
|
|
2728
|
-
validate: function (node) { return assertNumberOfParams(2, node); },
|
|
2729
|
-
},
|
|
2730
|
-
};
|
|
2731
|
-
|
|
2732
|
-
var mathNormalExpression = {
|
|
2733
|
-
'inc': {
|
|
2734
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
2735
|
-
var _b = __read(_a, 1), first = _b[0];
|
|
2736
|
-
assertNumber(first, sourceCodeInfo);
|
|
2737
|
-
return first + 1;
|
|
2738
|
-
},
|
|
2739
|
-
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2740
|
-
},
|
|
2741
|
-
'dec': {
|
|
2742
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
2743
|
-
var _b = __read(_a, 1), first = _b[0];
|
|
2744
|
-
assertNumber(first, sourceCodeInfo);
|
|
2745
|
-
return first - 1;
|
|
2746
|
-
},
|
|
2747
|
-
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2712
|
+
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2748
2713
|
},
|
|
2749
2714
|
'+': {
|
|
2750
2715
|
evaluate: function (params, sourceCodeInfo) {
|
|
@@ -2883,21 +2848,6 @@ var mathNormalExpression = {
|
|
|
2883
2848
|
},
|
|
2884
2849
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2885
2850
|
},
|
|
2886
|
-
'rand!': {
|
|
2887
|
-
evaluate: function (parameters, sourceCodeInfo) {
|
|
2888
|
-
var num = asNumber(parameters.length === 1 ? parameters[0] : 1, sourceCodeInfo);
|
|
2889
|
-
return Math.random() * num;
|
|
2890
|
-
},
|
|
2891
|
-
validate: function (node) { return assertNumberOfParams({ min: 0, max: 1 }, node); },
|
|
2892
|
-
},
|
|
2893
|
-
'rand-int!': {
|
|
2894
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
2895
|
-
var _b = __read(_a, 1), first = _b[0];
|
|
2896
|
-
assertNumber(first, sourceCodeInfo);
|
|
2897
|
-
return Math.floor(Math.random() * Math.abs(first)) * Math.sign(first);
|
|
2898
|
-
},
|
|
2899
|
-
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2900
|
-
},
|
|
2901
2851
|
'min': {
|
|
2902
2852
|
evaluate: function (_a, sourceCodeInfo) {
|
|
2903
2853
|
var _b = __read(_a), first = _b[0], rest = _b.slice(1);
|
|
@@ -2940,25 +2890,25 @@ var mathNormalExpression = {
|
|
|
2940
2890
|
},
|
|
2941
2891
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
2942
2892
|
},
|
|
2943
|
-
'
|
|
2893
|
+
'max_safe_integer': {
|
|
2944
2894
|
evaluate: function () {
|
|
2945
2895
|
return Number.MAX_SAFE_INTEGER;
|
|
2946
2896
|
},
|
|
2947
2897
|
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
2948
2898
|
},
|
|
2949
|
-
'
|
|
2899
|
+
'min_safe_integer': {
|
|
2950
2900
|
evaluate: function () {
|
|
2951
2901
|
return Number.MIN_SAFE_INTEGER;
|
|
2952
2902
|
},
|
|
2953
2903
|
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
2954
2904
|
},
|
|
2955
|
-
'
|
|
2905
|
+
'max_value': {
|
|
2956
2906
|
evaluate: function () {
|
|
2957
2907
|
return Number.MAX_VALUE;
|
|
2958
2908
|
},
|
|
2959
2909
|
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
2960
2910
|
},
|
|
2961
|
-
'
|
|
2911
|
+
'min_value': {
|
|
2962
2912
|
evaluate: function () {
|
|
2963
2913
|
return Number.MIN_VALUE;
|
|
2964
2914
|
},
|
|
@@ -2970,13 +2920,13 @@ var mathNormalExpression = {
|
|
|
2970
2920
|
},
|
|
2971
2921
|
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
2972
2922
|
},
|
|
2973
|
-
'
|
|
2923
|
+
'positive_infinity': {
|
|
2974
2924
|
evaluate: function () {
|
|
2975
2925
|
return Number.POSITIVE_INFINITY;
|
|
2976
2926
|
},
|
|
2977
2927
|
validate: function (node) { return assertNumberOfParams(0, node); },
|
|
2978
2928
|
},
|
|
2979
|
-
'
|
|
2929
|
+
'negative_infinity': {
|
|
2980
2930
|
evaluate: function () {
|
|
2981
2931
|
return Number.NEGATIVE_INFINITY;
|
|
2982
2932
|
},
|
|
@@ -3130,12 +3080,12 @@ var mathNormalExpression = {
|
|
|
3130
3080
|
},
|
|
3131
3081
|
};
|
|
3132
3082
|
|
|
3133
|
-
var version = "2.0.
|
|
3083
|
+
var version = "2.0.13";
|
|
3134
3084
|
|
|
3135
3085
|
var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
3136
3086
|
var xyRegexp = /[xy]/g;
|
|
3137
3087
|
var miscNormalExpression = {
|
|
3138
|
-
'
|
|
3088
|
+
'!=': {
|
|
3139
3089
|
evaluate: function (params) {
|
|
3140
3090
|
for (var i = 0; i < params.length - 1; i += 1) {
|
|
3141
3091
|
for (var j = i + 1; j < params.length; j += 1) {
|
|
@@ -3386,7 +3336,7 @@ var assertNormalExpression = {
|
|
|
3386
3336
|
},
|
|
3387
3337
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3388
3338
|
},
|
|
3389
|
-
'assert
|
|
3339
|
+
'assert!=': {
|
|
3390
3340
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3391
3341
|
var _b = __read(_a, 3), first = _b[0], second = _b[1], message = _b[2];
|
|
3392
3342
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3396,7 +3346,7 @@ var assertNormalExpression = {
|
|
|
3396
3346
|
},
|
|
3397
3347
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3398
3348
|
},
|
|
3399
|
-
'
|
|
3349
|
+
'assert_equal': {
|
|
3400
3350
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3401
3351
|
var _b = __read(_a, 3), first = _b[0], second = _b[1], message = _b[2];
|
|
3402
3352
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3407,7 +3357,7 @@ var assertNormalExpression = {
|
|
|
3407
3357
|
},
|
|
3408
3358
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3409
3359
|
},
|
|
3410
|
-
'
|
|
3360
|
+
'assert_not_equal': {
|
|
3411
3361
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3412
3362
|
var _b = __read(_a, 3), first = _b[0], second = _b[1], message = _b[2];
|
|
3413
3363
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3418,7 +3368,7 @@ var assertNormalExpression = {
|
|
|
3418
3368
|
},
|
|
3419
3369
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3420
3370
|
},
|
|
3421
|
-
'
|
|
3371
|
+
'assert_gt': {
|
|
3422
3372
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3423
3373
|
var _b = __read(_a, 3), first = _b[0], second = _b[1], message = _b[2];
|
|
3424
3374
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3428,7 +3378,7 @@ var assertNormalExpression = {
|
|
|
3428
3378
|
},
|
|
3429
3379
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3430
3380
|
},
|
|
3431
|
-
'
|
|
3381
|
+
'assert_gte': {
|
|
3432
3382
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3433
3383
|
var _b = __read(_a, 3), first = _b[0], second = _b[1], message = _b[2];
|
|
3434
3384
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3438,7 +3388,7 @@ var assertNormalExpression = {
|
|
|
3438
3388
|
},
|
|
3439
3389
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3440
3390
|
},
|
|
3441
|
-
'
|
|
3391
|
+
'assert_lt': {
|
|
3442
3392
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3443
3393
|
var _b = __read(_a, 3), first = _b[0], second = _b[1], message = _b[2];
|
|
3444
3394
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3448,7 +3398,7 @@ var assertNormalExpression = {
|
|
|
3448
3398
|
},
|
|
3449
3399
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3450
3400
|
},
|
|
3451
|
-
'
|
|
3401
|
+
'assert_lte': {
|
|
3452
3402
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3453
3403
|
var _b = __read(_a, 3), first = _b[0], second = _b[1], message = _b[2];
|
|
3454
3404
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3458,7 +3408,7 @@ var assertNormalExpression = {
|
|
|
3458
3408
|
},
|
|
3459
3409
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3460
3410
|
},
|
|
3461
|
-
'
|
|
3411
|
+
'assert_true': {
|
|
3462
3412
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3463
3413
|
var _b = __read(_a, 2), first = _b[0], message = _b[1];
|
|
3464
3414
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3468,7 +3418,7 @@ var assertNormalExpression = {
|
|
|
3468
3418
|
},
|
|
3469
3419
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
3470
3420
|
},
|
|
3471
|
-
'
|
|
3421
|
+
'assert_false': {
|
|
3472
3422
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3473
3423
|
var _b = __read(_a, 2), first = _b[0], message = _b[1];
|
|
3474
3424
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3478,7 +3428,7 @@ var assertNormalExpression = {
|
|
|
3478
3428
|
},
|
|
3479
3429
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
3480
3430
|
},
|
|
3481
|
-
'
|
|
3431
|
+
'assert_truthy': {
|
|
3482
3432
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3483
3433
|
var _b = __read(_a, 2), first = _b[0], message = _b[1];
|
|
3484
3434
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3488,7 +3438,7 @@ var assertNormalExpression = {
|
|
|
3488
3438
|
},
|
|
3489
3439
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
3490
3440
|
},
|
|
3491
|
-
'
|
|
3441
|
+
'assert_falsy': {
|
|
3492
3442
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3493
3443
|
var _b = __read(_a, 2), first = _b[0], message = _b[1];
|
|
3494
3444
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3498,7 +3448,7 @@ var assertNormalExpression = {
|
|
|
3498
3448
|
},
|
|
3499
3449
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
3500
3450
|
},
|
|
3501
|
-
'
|
|
3451
|
+
'assert_null': {
|
|
3502
3452
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3503
3453
|
var _b = __read(_a, 2), first = _b[0], message = _b[1];
|
|
3504
3454
|
message = typeof message === 'string' && message ? " \"".concat(message, "\"") : '';
|
|
@@ -3508,7 +3458,7 @@ var assertNormalExpression = {
|
|
|
3508
3458
|
},
|
|
3509
3459
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
3510
3460
|
},
|
|
3511
|
-
'
|
|
3461
|
+
'assert_throws': {
|
|
3512
3462
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
3513
3463
|
var _c = __read(_a, 2), func = _c[0], message = _c[1];
|
|
3514
3464
|
var executeFunction = _b.executeFunction;
|
|
@@ -3524,7 +3474,7 @@ var assertNormalExpression = {
|
|
|
3524
3474
|
},
|
|
3525
3475
|
validate: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
|
|
3526
3476
|
},
|
|
3527
|
-
'
|
|
3477
|
+
'assert_throws_error': {
|
|
3528
3478
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
3529
3479
|
var _c = __read(_a, 3), func = _c[0], throwMessage = _c[1], message = _c[2];
|
|
3530
3480
|
var executeFunction = _b.executeFunction;
|
|
@@ -3545,7 +3495,7 @@ var assertNormalExpression = {
|
|
|
3545
3495
|
},
|
|
3546
3496
|
validate: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
|
|
3547
3497
|
},
|
|
3548
|
-
'
|
|
3498
|
+
'assert_not_throws': {
|
|
3549
3499
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
3550
3500
|
var _c = __read(_a, 2), func = _c[0], message = _c[1];
|
|
3551
3501
|
var executeFunction = _b.executeFunction;
|
|
@@ -3579,25 +3529,25 @@ var objectNormalExpression = {
|
|
|
3579
3529
|
},
|
|
3580
3530
|
'keys': {
|
|
3581
3531
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3582
|
-
var _b = __read(_a, 1),
|
|
3583
|
-
assertObj(
|
|
3584
|
-
return Object.keys(
|
|
3532
|
+
var _b = __read(_a, 1), obj = _b[0];
|
|
3533
|
+
assertObj(obj, sourceCodeInfo);
|
|
3534
|
+
return Object.keys(obj);
|
|
3585
3535
|
},
|
|
3586
3536
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3587
3537
|
},
|
|
3588
3538
|
'vals': {
|
|
3589
3539
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3590
|
-
var _b = __read(_a, 1),
|
|
3591
|
-
assertObj(
|
|
3592
|
-
return Object.values(
|
|
3540
|
+
var _b = __read(_a, 1), obj = _b[0];
|
|
3541
|
+
assertObj(obj, sourceCodeInfo);
|
|
3542
|
+
return Object.values(obj);
|
|
3593
3543
|
},
|
|
3594
3544
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3595
3545
|
},
|
|
3596
3546
|
'entries': {
|
|
3597
3547
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3598
|
-
var _b = __read(_a, 1),
|
|
3599
|
-
assertObj(
|
|
3600
|
-
return Object.entries(
|
|
3548
|
+
var _b = __read(_a, 1), obj = _b[0];
|
|
3549
|
+
assertObj(obj, sourceCodeInfo);
|
|
3550
|
+
return Object.entries(obj);
|
|
3601
3551
|
},
|
|
3602
3552
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3603
3553
|
},
|
|
@@ -3639,11 +3589,11 @@ var objectNormalExpression = {
|
|
|
3639
3589
|
'merge-with': {
|
|
3640
3590
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
3641
3591
|
var executeFunction = _a.executeFunction;
|
|
3642
|
-
var
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
return null;
|
|
3592
|
+
var first = params[0];
|
|
3593
|
+
var fn = params.at(-1);
|
|
3594
|
+
var rest = params.slice(1, -1);
|
|
3646
3595
|
assertObj(first, sourceCodeInfo);
|
|
3596
|
+
assertLitsFunction(fn, sourceCodeInfo);
|
|
3647
3597
|
return rest.reduce(function (result, obj) {
|
|
3648
3598
|
assertObj(obj, sourceCodeInfo);
|
|
3649
3599
|
Object.entries(obj).forEach(function (entry) {
|
|
@@ -3657,7 +3607,7 @@ var objectNormalExpression = {
|
|
|
3657
3607
|
return result;
|
|
3658
3608
|
}, __assign({}, first));
|
|
3659
3609
|
},
|
|
3660
|
-
validate: function (node) { return assertNumberOfParams({ min:
|
|
3610
|
+
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
3661
3611
|
},
|
|
3662
3612
|
'zipmap': {
|
|
3663
3613
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -3823,7 +3773,7 @@ var predicatesNormalExpression = {
|
|
|
3823
3773
|
},
|
|
3824
3774
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3825
3775
|
},
|
|
3826
|
-
'
|
|
3776
|
+
'positive_infinity?': {
|
|
3827
3777
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3828
3778
|
var _b = __read(_a, 1), value = _b[0];
|
|
3829
3779
|
assertNumber(value, sourceCodeInfo);
|
|
@@ -3831,7 +3781,7 @@ var predicatesNormalExpression = {
|
|
|
3831
3781
|
},
|
|
3832
3782
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3833
3783
|
},
|
|
3834
|
-
'
|
|
3784
|
+
'negative_infinity?': {
|
|
3835
3785
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3836
3786
|
var _b = __read(_a, 1), value = _b[0];
|
|
3837
3787
|
assertNumber(value, sourceCodeInfo);
|
|
@@ -3867,7 +3817,7 @@ var predicatesNormalExpression = {
|
|
|
3867
3817
|
},
|
|
3868
3818
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
3869
3819
|
},
|
|
3870
|
-
'
|
|
3820
|
+
'not_empty?': {
|
|
3871
3821
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3872
3822
|
var _b = __read(_a, 1), coll = _b[0];
|
|
3873
3823
|
if (coll === null)
|
|
@@ -4201,7 +4151,7 @@ function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
|
|
|
4201
4151
|
}
|
|
4202
4152
|
|
|
4203
4153
|
var functionalNormalExpression = {
|
|
4204
|
-
|
|
4154
|
+
apply: {
|
|
4205
4155
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4206
4156
|
var _c = __read(_a), func = _c[0], params = _c.slice(1);
|
|
4207
4157
|
var executeFunction = _b.executeFunction;
|
|
@@ -4214,14 +4164,14 @@ var functionalNormalExpression = {
|
|
|
4214
4164
|
},
|
|
4215
4165
|
validate: function (node) { return assertNumberOfParams({ min: 2 }, node); },
|
|
4216
4166
|
},
|
|
4217
|
-
|
|
4167
|
+
identity: {
|
|
4218
4168
|
evaluate: function (_a) {
|
|
4219
4169
|
var _b = __read(_a, 1), value = _b[0];
|
|
4220
4170
|
return toAny(value);
|
|
4221
4171
|
},
|
|
4222
4172
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4223
4173
|
},
|
|
4224
|
-
|
|
4174
|
+
partial: {
|
|
4225
4175
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4226
4176
|
var _b;
|
|
4227
4177
|
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
@@ -4235,7 +4185,7 @@ var functionalNormalExpression = {
|
|
|
4235
4185
|
},
|
|
4236
4186
|
validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
4237
4187
|
},
|
|
4238
|
-
|
|
4188
|
+
comp: {
|
|
4239
4189
|
evaluate: function (fns, sourceCodeInfo) {
|
|
4240
4190
|
var _a;
|
|
4241
4191
|
if (fns.length > 1) {
|
|
@@ -4252,7 +4202,7 @@ var functionalNormalExpression = {
|
|
|
4252
4202
|
_a;
|
|
4253
4203
|
},
|
|
4254
4204
|
},
|
|
4255
|
-
|
|
4205
|
+
constantly: {
|
|
4256
4206
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4257
4207
|
var _b;
|
|
4258
4208
|
var _c = __read(_a, 1), value = _c[0];
|
|
@@ -4265,7 +4215,7 @@ var functionalNormalExpression = {
|
|
|
4265
4215
|
},
|
|
4266
4216
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4267
4217
|
},
|
|
4268
|
-
|
|
4218
|
+
juxt: {
|
|
4269
4219
|
evaluate: function (fns, sourceCodeInfo) {
|
|
4270
4220
|
var _a;
|
|
4271
4221
|
return _a = {},
|
|
@@ -4277,7 +4227,7 @@ var functionalNormalExpression = {
|
|
|
4277
4227
|
},
|
|
4278
4228
|
validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
4279
4229
|
},
|
|
4280
|
-
|
|
4230
|
+
complement: {
|
|
4281
4231
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4282
4232
|
var _b;
|
|
4283
4233
|
var _c = __read(_a, 1), fn = _c[0];
|
|
@@ -4290,7 +4240,7 @@ var functionalNormalExpression = {
|
|
|
4290
4240
|
},
|
|
4291
4241
|
validate: function (node) { return assertNumberOfParams(1, node); },
|
|
4292
4242
|
},
|
|
4293
|
-
|
|
4243
|
+
every_pred: {
|
|
4294
4244
|
evaluate: function (fns, sourceCodeInfo) {
|
|
4295
4245
|
var _a;
|
|
4296
4246
|
return _a = {},
|
|
@@ -4302,7 +4252,7 @@ var functionalNormalExpression = {
|
|
|
4302
4252
|
},
|
|
4303
4253
|
validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
4304
4254
|
},
|
|
4305
|
-
|
|
4255
|
+
some_pred: {
|
|
4306
4256
|
evaluate: function (fns, sourceCodeInfo) {
|
|
4307
4257
|
var _a;
|
|
4308
4258
|
return _a = {},
|
|
@@ -4314,7 +4264,7 @@ var functionalNormalExpression = {
|
|
|
4314
4264
|
},
|
|
4315
4265
|
validate: function (node) { return assertNumberOfParams({ min: 1 }, node); },
|
|
4316
4266
|
},
|
|
4317
|
-
|
|
4267
|
+
fnil: {
|
|
4318
4268
|
evaluate: function (_a, sourceCodeInfo) {
|
|
4319
4269
|
var _b;
|
|
4320
4270
|
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
@@ -6887,13 +6837,34 @@ function parseSymbol(tokenStream, parseState) {
|
|
|
6887
6837
|
if (!isA_SymbolToken(tkn) && !isP_SymbolToken(tkn)) {
|
|
6888
6838
|
throw new LitsError("Expected symbol token, got ".concat(tkn[0]), (_a = getTokenDebugData(tkn)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
6889
6839
|
}
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6840
|
+
if (tkn[1][0] !== '\'') {
|
|
6841
|
+
return {
|
|
6842
|
+
t: AstNodeType.Symbol,
|
|
6843
|
+
v: tkn[1],
|
|
6844
|
+
p: [],
|
|
6845
|
+
n: undefined,
|
|
6846
|
+
token: getTokenDebugData(tkn) && tkn,
|
|
6847
|
+
};
|
|
6848
|
+
}
|
|
6849
|
+
else {
|
|
6850
|
+
var value = tkn[1].substring(1, tkn[1].length - 1)
|
|
6851
|
+
.replace(/(\\{2})|(\\')|\\(.)/g, function (_, backslash, singleQuote, normalChar) {
|
|
6852
|
+
if (backslash) {
|
|
6853
|
+
return '\\';
|
|
6854
|
+
}
|
|
6855
|
+
if (singleQuote) {
|
|
6856
|
+
return '\'';
|
|
6857
|
+
}
|
|
6858
|
+
return "\\".concat(normalChar);
|
|
6859
|
+
});
|
|
6860
|
+
return {
|
|
6861
|
+
t: AstNodeType.Symbol,
|
|
6862
|
+
v: value,
|
|
6863
|
+
p: [],
|
|
6864
|
+
n: undefined,
|
|
6865
|
+
token: getTokenDebugData(tkn) && tkn,
|
|
6866
|
+
};
|
|
6867
|
+
}
|
|
6897
6868
|
}
|
|
6898
6869
|
function parseReservedSymbol(tokenStream, parseState) {
|
|
6899
6870
|
var _a;
|
|
@@ -6912,7 +6883,23 @@ function parseReservedSymbol(tokenStream, parseState) {
|
|
|
6912
6883
|
function parseNumber(tokenStream, parseState) {
|
|
6913
6884
|
var _a;
|
|
6914
6885
|
var tkn = tokenStream.tokens[parseState.position++];
|
|
6915
|
-
if (
|
|
6886
|
+
if (isA_NumberToken(tkn)) {
|
|
6887
|
+
var numberString_1 = tkn[1];
|
|
6888
|
+
var periodToken = tokenStream.tokens[parseState.position];
|
|
6889
|
+
var decimalToken = tokenStream.tokens[parseState.position + 1];
|
|
6890
|
+
if (isA_OperatorToken(periodToken, '.') && isA_NumberToken(decimalToken)) {
|
|
6891
|
+
numberString_1 += ".".concat(decimalToken[1]);
|
|
6892
|
+
parseState.position += 2;
|
|
6893
|
+
}
|
|
6894
|
+
return {
|
|
6895
|
+
t: AstNodeType.Number,
|
|
6896
|
+
v: Number(numberString_1),
|
|
6897
|
+
p: [],
|
|
6898
|
+
n: undefined,
|
|
6899
|
+
token: getTokenDebugData(tkn) && tkn,
|
|
6900
|
+
};
|
|
6901
|
+
}
|
|
6902
|
+
if (!isP_NumberToken(tkn) && !isA_BasePrefixedNumberToken(tkn)) {
|
|
6916
6903
|
throw new LitsError("Expected number token, got ".concat(tkn), (_a = getTokenDebugData(tkn)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
6917
6904
|
}
|
|
6918
6905
|
var value = tkn[1];
|
|
@@ -6964,63 +6951,60 @@ function parseString(tokenStream, parseState) {
|
|
|
6964
6951
|
};
|
|
6965
6952
|
}
|
|
6966
6953
|
|
|
6967
|
-
var exponentiationPrecedence =
|
|
6954
|
+
var exponentiationPrecedence = 10;
|
|
6955
|
+
var binaryFunctionalOperatorPrecedence = 1;
|
|
6968
6956
|
var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
|
|
6969
|
-
function getPrecedence(
|
|
6970
|
-
var operatorSign = operator[1];
|
|
6957
|
+
function getPrecedence(operatorSign) {
|
|
6971
6958
|
switch (operatorSign) {
|
|
6972
|
-
case '.': // accessor
|
|
6973
|
-
return 10;
|
|
6974
6959
|
case '**': // exponentiation
|
|
6975
6960
|
return exponentiationPrecedence;
|
|
6976
6961
|
case '*': // multiplication
|
|
6977
6962
|
case '/': // division
|
|
6978
6963
|
case '%': // remainder
|
|
6979
|
-
return
|
|
6964
|
+
return 9;
|
|
6980
6965
|
case '+': // addition
|
|
6981
6966
|
case '-': // subtraction
|
|
6982
|
-
return
|
|
6967
|
+
return 8;
|
|
6983
6968
|
case '<<': // left shift
|
|
6984
6969
|
case '>>': // signed right shift
|
|
6985
6970
|
case '>>>': // unsigned right shift
|
|
6986
|
-
return
|
|
6971
|
+
return 7;
|
|
6987
6972
|
case '++': // string concatenation
|
|
6988
|
-
return
|
|
6973
|
+
return 6;
|
|
6989
6974
|
case '<': // less than
|
|
6990
6975
|
case '<=': // less than or equal
|
|
6991
6976
|
case '>': // greater than
|
|
6992
6977
|
case '>=': // greater than or equal
|
|
6993
|
-
return
|
|
6978
|
+
return 5;
|
|
6994
6979
|
case '==': // equal
|
|
6995
6980
|
case '!=': // not equal
|
|
6996
|
-
return
|
|
6981
|
+
return 4;
|
|
6997
6982
|
case '&': // bitwise AND
|
|
6998
6983
|
case '^': // bitwise XOR
|
|
6999
6984
|
case '|': // bitwise OR
|
|
7000
|
-
return
|
|
6985
|
+
return 3;
|
|
7001
6986
|
case '&&': // logical AND
|
|
7002
6987
|
case '||': // logical OR
|
|
7003
6988
|
case '??': // nullish coalescing
|
|
7004
|
-
return
|
|
7005
|
-
|
|
7006
|
-
case '!': // logical NOT
|
|
7007
|
-
case '~': // bitwise NOT
|
|
7008
|
-
case '=': // property assignemnt operator
|
|
7009
|
-
case ',': // element delimiter
|
|
7010
|
-
case '=>': // Only used in lamda function parser
|
|
7011
|
-
case '...': // Only used in lamda function parser
|
|
7012
|
-
throw new Error("Unknown binary operator: ".concat(operatorSign));
|
|
6989
|
+
return 2;
|
|
6990
|
+
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
7013
6991
|
default:
|
|
7014
6992
|
throw new Error("Unknown binary operator: ".concat(operatorSign));
|
|
7015
6993
|
}
|
|
7016
6994
|
}
|
|
7017
6995
|
function createNamedNormalExpressionNode(name, params, token) {
|
|
7018
|
-
|
|
6996
|
+
var _a;
|
|
6997
|
+
var node = {
|
|
7019
6998
|
t: AstNodeType.NormalExpression,
|
|
7020
6999
|
n: name,
|
|
7021
7000
|
p: params,
|
|
7022
7001
|
token: getTokenDebugData(token) && token,
|
|
7023
7002
|
};
|
|
7003
|
+
var builtinExpression = builtin.normalExpressions[node.n];
|
|
7004
|
+
if (builtinExpression) {
|
|
7005
|
+
(_a = builtinExpression.validate) === null || _a === void 0 ? void 0 : _a.call(builtinExpression, __assign(__assign({}, node), { p: withoutCommentNodes(node.p) }));
|
|
7006
|
+
}
|
|
7007
|
+
return node;
|
|
7024
7008
|
}
|
|
7025
7009
|
function fromSymbolToStringNode(symbol) {
|
|
7026
7010
|
return {
|
|
@@ -7057,9 +7041,8 @@ function fromUnaryAlgebraicToAstNode(operator, operand) {
|
|
|
7057
7041
|
throw new Error("Unknown operator: ".concat(operatorName));
|
|
7058
7042
|
}
|
|
7059
7043
|
}
|
|
7060
|
-
function
|
|
7044
|
+
function fromBinaryOperatorToAstNode(operator, left, right, token) {
|
|
7061
7045
|
var _a, _b, _c;
|
|
7062
|
-
var token = hasTokenDebugData(operator) ? operator : undefined;
|
|
7063
7046
|
var operatorName = operator[1];
|
|
7064
7047
|
switch (operatorName) {
|
|
7065
7048
|
case '.':
|
|
@@ -7098,7 +7081,7 @@ function fromBinaryAlgebraicToAstNode(operator, left, right) {
|
|
|
7098
7081
|
case '==':
|
|
7099
7082
|
return createNamedNormalExpressionNode('=', [left, right], token);
|
|
7100
7083
|
case '!=':
|
|
7101
|
-
return createNamedNormalExpressionNode('
|
|
7084
|
+
return createNamedNormalExpressionNode('!=', [left, right], token);
|
|
7102
7085
|
case '&':
|
|
7103
7086
|
return createNamedNormalExpressionNode('bit-and', [left, right], token);
|
|
7104
7087
|
case '^':
|
|
@@ -7155,45 +7138,82 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7155
7138
|
var left = this.parseOperand();
|
|
7156
7139
|
while (!this.isAtEnd() && !isA_OperatorToken(this.peek(), ',') && !isRBracketToken(this.peek()) && !isRParenToken(this.peek())) {
|
|
7157
7140
|
var operator = this.peek();
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
}
|
|
7165
|
-
// Handle index accessor
|
|
7166
|
-
else if (isLBracketToken(operator)) {
|
|
7167
|
-
if (precedence >= 9) {
|
|
7141
|
+
if (isA_BinaryOperatorToken(operator)) {
|
|
7142
|
+
var name_1 = operator[1];
|
|
7143
|
+
var newPrecedece = getPrecedence(name_1);
|
|
7144
|
+
if (newPrecedece <= precedence
|
|
7145
|
+
// ** (exponentiation) is right associative
|
|
7146
|
+
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
7168
7147
|
break;
|
|
7169
7148
|
}
|
|
7170
7149
|
this.advance();
|
|
7171
|
-
var right = this.parseExpression(
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
}
|
|
7175
|
-
this.advance();
|
|
7176
|
-
left = createAccessorNode(left, right, operator);
|
|
7150
|
+
var right = this.parseExpression(newPrecedece);
|
|
7151
|
+
var token = hasTokenDebugData(operator) ? operator : undefined;
|
|
7152
|
+
left = fromBinaryOperatorToAstNode(operator, left, right, token);
|
|
7177
7153
|
}
|
|
7178
|
-
else {
|
|
7179
|
-
if (!
|
|
7154
|
+
else if (isA_SymbolToken(operator)) {
|
|
7155
|
+
if (!isFunctionOperator(operator[1])) {
|
|
7180
7156
|
break;
|
|
7181
7157
|
}
|
|
7182
|
-
var newPrecedece =
|
|
7183
|
-
if (newPrecedece <= precedence
|
|
7184
|
-
// ** (exponentiation) is right associative
|
|
7185
|
-
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
7158
|
+
var newPrecedece = binaryFunctionalOperatorPrecedence;
|
|
7159
|
+
if (newPrecedece <= precedence) {
|
|
7186
7160
|
break;
|
|
7187
7161
|
}
|
|
7188
7162
|
this.advance();
|
|
7189
7163
|
var right = this.parseExpression(newPrecedece);
|
|
7190
|
-
|
|
7164
|
+
var token = hasTokenDebugData(operator) ? operator : undefined;
|
|
7165
|
+
left = createNamedNormalExpressionNode(operator[1], [left, right], token);
|
|
7191
7166
|
}
|
|
7167
|
+
else {
|
|
7168
|
+
break;
|
|
7169
|
+
}
|
|
7170
|
+
}
|
|
7171
|
+
if (!left) {
|
|
7172
|
+
throw new LitsError('Expected operand', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7192
7173
|
}
|
|
7193
7174
|
return left;
|
|
7194
7175
|
};
|
|
7195
7176
|
AlgebraicParser.prototype.parseOperand = function () {
|
|
7196
|
-
var _a;
|
|
7177
|
+
var _a, _b;
|
|
7178
|
+
var operand = this.parseOperandPart();
|
|
7179
|
+
var token = this.peek();
|
|
7180
|
+
while (isA_OperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
7181
|
+
if (token[1] === '.') {
|
|
7182
|
+
this.advance();
|
|
7183
|
+
var symbolToken = this.peek();
|
|
7184
|
+
if (!isA_SymbolToken(symbolToken)) {
|
|
7185
|
+
throw new LitsError('Expected symbol', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7186
|
+
}
|
|
7187
|
+
var stringNode = {
|
|
7188
|
+
t: AstNodeType.String,
|
|
7189
|
+
v: symbolToken[1],
|
|
7190
|
+
token: getTokenDebugData(symbolToken) && symbolToken,
|
|
7191
|
+
p: [],
|
|
7192
|
+
n: undefined,
|
|
7193
|
+
};
|
|
7194
|
+
operand = createAccessorNode(operand, stringNode, token);
|
|
7195
|
+
this.advance();
|
|
7196
|
+
token = this.peek();
|
|
7197
|
+
}
|
|
7198
|
+
else if (isLBracketToken(token)) {
|
|
7199
|
+
this.advance();
|
|
7200
|
+
var expression = this.parseExpression();
|
|
7201
|
+
if (!isRBracketToken(this.peek())) {
|
|
7202
|
+
throw new LitsError('Expected closing bracket', (_b = getTokenDebugData(this.peek())) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
7203
|
+
}
|
|
7204
|
+
operand = createAccessorNode(operand, expression, token);
|
|
7205
|
+
this.advance();
|
|
7206
|
+
token = this.peek();
|
|
7207
|
+
}
|
|
7208
|
+
else if (isLParenToken(token)) {
|
|
7209
|
+
operand = this.parseFunctionCall(operand);
|
|
7210
|
+
token = this.peek();
|
|
7211
|
+
}
|
|
7212
|
+
}
|
|
7213
|
+
return operand;
|
|
7214
|
+
};
|
|
7215
|
+
AlgebraicParser.prototype.parseOperandPart = function () {
|
|
7216
|
+
var _a, _b;
|
|
7197
7217
|
var token = this.peek();
|
|
7198
7218
|
// Parentheses
|
|
7199
7219
|
if (isLParenToken(token)) {
|
|
@@ -7212,14 +7232,17 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7212
7232
|
return expression;
|
|
7213
7233
|
}
|
|
7214
7234
|
// Unary operators
|
|
7215
|
-
if (isA_OperatorToken(token)) {
|
|
7235
|
+
else if (isA_OperatorToken(token)) {
|
|
7216
7236
|
var operatorName = token[1];
|
|
7217
|
-
if (
|
|
7237
|
+
if (isSymbolicUnaryOperator(operatorName)) {
|
|
7218
7238
|
this.advance();
|
|
7219
7239
|
var operand = this.parseOperand();
|
|
7240
|
+
if (operand === null) {
|
|
7241
|
+
throw new LitsError('Expected operand', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7242
|
+
}
|
|
7220
7243
|
return fromUnaryAlgebraicToAstNode(token, operand);
|
|
7221
7244
|
}
|
|
7222
|
-
|
|
7245
|
+
if (operatorName === '=>') {
|
|
7223
7246
|
return this.parseShorthandLamdaFunction();
|
|
7224
7247
|
}
|
|
7225
7248
|
else {
|
|
@@ -7237,6 +7260,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7237
7260
|
var tokenType = token[0];
|
|
7238
7261
|
switch (tokenType) {
|
|
7239
7262
|
case 'A_Number':
|
|
7263
|
+
case 'A_BasePrefixedNumber':
|
|
7240
7264
|
return parseNumber(this.tokenStream, this.parseState);
|
|
7241
7265
|
case 'String':
|
|
7242
7266
|
return parseString(this.tokenStream, this.parseState);
|
|
@@ -7272,18 +7296,21 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7272
7296
|
return node;
|
|
7273
7297
|
}
|
|
7274
7298
|
default:
|
|
7275
|
-
throw new LitsError("Unknown token type: ".concat(tokenType), (
|
|
7299
|
+
throw new LitsError("Unknown token type: ".concat(tokenType), (_b = getTokenDebugData(token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
7276
7300
|
}
|
|
7277
7301
|
};
|
|
7278
7302
|
AlgebraicParser.prototype.parseObject = function () {
|
|
7279
|
-
var _a, _b;
|
|
7303
|
+
var _a, _b, _c;
|
|
7280
7304
|
var firstToken = asLBraceToken(this.peek());
|
|
7281
7305
|
this.advance();
|
|
7282
7306
|
var params = [];
|
|
7283
7307
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
7284
7308
|
var key = this.parseOperand();
|
|
7309
|
+
if (key === null) {
|
|
7310
|
+
throw new LitsError('Expected key', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7311
|
+
}
|
|
7285
7312
|
if (key.t !== AstNodeType.Symbol && key.t !== AstNodeType.String) {
|
|
7286
|
-
throw new LitsError('Expected key to be a symbol or a string', (
|
|
7313
|
+
throw new LitsError('Expected key to be a symbol or a string', (_b = getTokenDebugData(this.peek())) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
7287
7314
|
}
|
|
7288
7315
|
params.push({
|
|
7289
7316
|
t: AstNodeType.String,
|
|
@@ -7297,7 +7324,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7297
7324
|
params.push(this.parseExpression());
|
|
7298
7325
|
var nextToken = this.peek();
|
|
7299
7326
|
if (!isA_OperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
7300
|
-
throw new LitsError('Expected comma or closing brace', (
|
|
7327
|
+
throw new LitsError('Expected comma or closing brace', (_c = getTokenDebugData(this.peek())) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
7301
7328
|
}
|
|
7302
7329
|
if (isA_OperatorToken(nextToken, ',')) {
|
|
7303
7330
|
this.advance();
|
|
@@ -7337,9 +7364,13 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7337
7364
|
};
|
|
7338
7365
|
};
|
|
7339
7366
|
AlgebraicParser.prototype.parseFunctionCall = function (symbol) {
|
|
7340
|
-
var _a, _b
|
|
7341
|
-
var
|
|
7367
|
+
var _a, _b;
|
|
7368
|
+
var isNamedFunction = symbol.t === AstNodeType.Symbol;
|
|
7342
7369
|
this.advance();
|
|
7370
|
+
if (isNamedFunction && symbol.v === 'for') {
|
|
7371
|
+
return this.parseFor(symbol);
|
|
7372
|
+
}
|
|
7373
|
+
var params = [];
|
|
7343
7374
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
7344
7375
|
params.push(this.parseExpression());
|
|
7345
7376
|
var nextToken = this.peek();
|
|
@@ -7354,10 +7385,10 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7354
7385
|
throw new LitsError('Expected closing parenthesis', (_b = getTokenDebugData(this.peek())) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
|
|
7355
7386
|
}
|
|
7356
7387
|
this.advance();
|
|
7357
|
-
if (
|
|
7388
|
+
if (isNamedFunction) {
|
|
7358
7389
|
if (specialExpressionKeys.includes(symbol.v)) {
|
|
7359
|
-
var
|
|
7360
|
-
switch (
|
|
7390
|
+
var name_2 = symbol.v;
|
|
7391
|
+
switch (name_2) {
|
|
7361
7392
|
case '??':
|
|
7362
7393
|
case 'and':
|
|
7363
7394
|
case 'comment':
|
|
@@ -7371,14 +7402,14 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7371
7402
|
case 'do':
|
|
7372
7403
|
case 'time!':
|
|
7373
7404
|
case 'throw': {
|
|
7374
|
-
var
|
|
7405
|
+
var node = {
|
|
7375
7406
|
t: AstNodeType.SpecialExpression,
|
|
7376
|
-
n:
|
|
7407
|
+
n: name_2,
|
|
7377
7408
|
p: params,
|
|
7378
7409
|
token: getTokenDebugData(symbol.token) && symbol.token,
|
|
7379
7410
|
};
|
|
7380
|
-
builtin.specialExpressions[
|
|
7381
|
-
return
|
|
7411
|
+
builtin.specialExpressions[node.n].validateParameterCount(node);
|
|
7412
|
+
return node;
|
|
7382
7413
|
}
|
|
7383
7414
|
case 'let':
|
|
7384
7415
|
return this.parseLet(symbol, params);
|
|
@@ -7394,18 +7425,12 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7394
7425
|
case 'recur':
|
|
7395
7426
|
case 'loop':
|
|
7396
7427
|
case 'doseq':
|
|
7397
|
-
|
|
7398
|
-
throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
|
|
7428
|
+
throw new Error("Special expression ".concat(name_2, " is not available in algebraic notation"));
|
|
7399
7429
|
default:
|
|
7400
|
-
throw new Error("Unknown special expression: ".concat(
|
|
7430
|
+
throw new Error("Unknown special expression: ".concat(name_2));
|
|
7401
7431
|
}
|
|
7402
7432
|
}
|
|
7403
|
-
|
|
7404
|
-
var builtinExpression = builtin.normalExpressions[node.n];
|
|
7405
|
-
if (builtinExpression) {
|
|
7406
|
-
(_c = builtinExpression.validate) === null || _c === void 0 ? void 0 : _c.call(builtinExpression, __assign(__assign({}, node), { p: withoutCommentNodes(node.p) }));
|
|
7407
|
-
}
|
|
7408
|
-
return node;
|
|
7433
|
+
return createNamedNormalExpressionNode(symbol.v, params, symbol.token);
|
|
7409
7434
|
}
|
|
7410
7435
|
else {
|
|
7411
7436
|
return {
|
|
@@ -7496,7 +7521,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7496
7521
|
};
|
|
7497
7522
|
};
|
|
7498
7523
|
AlgebraicParser.prototype.parseShorthandLamdaFunction = function () {
|
|
7499
|
-
var _a, _b, _c
|
|
7524
|
+
var _a, _b, _c;
|
|
7500
7525
|
var firstToken = this.peek();
|
|
7501
7526
|
this.advance();
|
|
7502
7527
|
var startPos = this.parseState.position;
|
|
@@ -7521,9 +7546,6 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7521
7546
|
throw new LitsError('Can\'t specify more than 20 arguments', (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
|
|
7522
7547
|
}
|
|
7523
7548
|
}
|
|
7524
|
-
if (isA_OperatorToken(tkn, '=>')) {
|
|
7525
|
-
throw new LitsError('Nested shortcut functions are not allowed', (_d = getTokenDebugData(firstToken)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo);
|
|
7526
|
-
}
|
|
7527
7549
|
}
|
|
7528
7550
|
var mandatoryArguments = [];
|
|
7529
7551
|
for (var i = 1; i <= arity; i += 1) {
|
|
@@ -7551,10 +7573,10 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7551
7573
|
};
|
|
7552
7574
|
return node;
|
|
7553
7575
|
};
|
|
7554
|
-
AlgebraicParser.prototype.parseLet = function (
|
|
7576
|
+
AlgebraicParser.prototype.parseLet = function (letSymbol, params) {
|
|
7555
7577
|
var _a, _b;
|
|
7556
7578
|
if (params.length !== 2) {
|
|
7557
|
-
throw new LitsError('let expects two arguments', (_a = getTokenDebugData(
|
|
7579
|
+
throw new LitsError('let expects two arguments', (_a = getTokenDebugData(letSymbol.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7558
7580
|
}
|
|
7559
7581
|
var letObject = params[0];
|
|
7560
7582
|
if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
|
|
@@ -7566,7 +7588,7 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7566
7588
|
t: AstNodeType.SpecialExpression,
|
|
7567
7589
|
n: 'let',
|
|
7568
7590
|
p: [expression],
|
|
7569
|
-
token: getTokenDebugData(
|
|
7591
|
+
token: getTokenDebugData(letSymbol.token) && letSymbol.token,
|
|
7570
7592
|
bs: letBindings.map(function (pair) {
|
|
7571
7593
|
var key = pair[0];
|
|
7572
7594
|
var value = pair[1];
|
|
@@ -7580,12 +7602,122 @@ var AlgebraicParser = /** @class */ (function () {
|
|
|
7580
7602
|
}),
|
|
7581
7603
|
};
|
|
7582
7604
|
};
|
|
7605
|
+
AlgebraicParser.prototype.parseFor = function (forSymbol) {
|
|
7606
|
+
var forLoopBindings = [
|
|
7607
|
+
this.parseForLoopBinding(),
|
|
7608
|
+
];
|
|
7609
|
+
var nextToken = this.peekAhead();
|
|
7610
|
+
while (isA_SymbolToken(nextToken) && nextToken[1] === 'of') {
|
|
7611
|
+
forLoopBindings.push(this.parseForLoopBinding());
|
|
7612
|
+
nextToken = this.peekAhead();
|
|
7613
|
+
}
|
|
7614
|
+
var expression = this.parseExpression();
|
|
7615
|
+
assertRParenToken(this.peek());
|
|
7616
|
+
this.advance();
|
|
7617
|
+
return {
|
|
7618
|
+
t: AstNodeType.SpecialExpression,
|
|
7619
|
+
n: 'for',
|
|
7620
|
+
p: [expression],
|
|
7621
|
+
token: getTokenDebugData(forSymbol.token) && forSymbol.token,
|
|
7622
|
+
l: forLoopBindings,
|
|
7623
|
+
};
|
|
7624
|
+
};
|
|
7625
|
+
// export interface LoopBindingNode {
|
|
7626
|
+
// b: BindingNode // Binding
|
|
7627
|
+
// m: Array<'&let' | '&when' | '&while'> // Modifiers
|
|
7628
|
+
// l?: BindingNode[] // Let-Bindings
|
|
7629
|
+
// wn?: AstNode // When Node
|
|
7630
|
+
// we?: AstNode // While Node
|
|
7631
|
+
// }
|
|
7632
|
+
AlgebraicParser.prototype.parseForLoopBinding = function () {
|
|
7633
|
+
var _a;
|
|
7634
|
+
var bindingNode = this.parseBinding();
|
|
7635
|
+
if (isA_OperatorToken(this.peek(), ',')) {
|
|
7636
|
+
this.advance();
|
|
7637
|
+
return {
|
|
7638
|
+
b: bindingNode,
|
|
7639
|
+
m: [],
|
|
7640
|
+
};
|
|
7641
|
+
}
|
|
7642
|
+
var modifiers = [];
|
|
7643
|
+
var token = this.peek();
|
|
7644
|
+
if (!isA_SymbolToken(token)) {
|
|
7645
|
+
throw new LitsError('Expected symbol let, when or while', (_a = getTokenDebugData(token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7646
|
+
}
|
|
7647
|
+
var letBindings;
|
|
7648
|
+
if (token[1] === 'let') {
|
|
7649
|
+
modifiers.push('&let');
|
|
7650
|
+
letBindings = [];
|
|
7651
|
+
this.advance();
|
|
7652
|
+
var letObject = this.parseObject();
|
|
7653
|
+
letBindings = arrayToPairs(letObject.p).map(function (pair) {
|
|
7654
|
+
var key = pair[0];
|
|
7655
|
+
var value = pair[1];
|
|
7656
|
+
return {
|
|
7657
|
+
t: AstNodeType.Binding,
|
|
7658
|
+
n: key.v,
|
|
7659
|
+
v: value,
|
|
7660
|
+
p: [],
|
|
7661
|
+
token: getTokenDebugData(key.token) && key.token,
|
|
7662
|
+
};
|
|
7663
|
+
});
|
|
7664
|
+
}
|
|
7665
|
+
token = this.peek();
|
|
7666
|
+
var whenNode;
|
|
7667
|
+
var whileNode;
|
|
7668
|
+
while (isA_SymbolToken(token)
|
|
7669
|
+
&& ((token[1] === 'when' && !modifiers.includes('&when'))
|
|
7670
|
+
|| (token[1] === 'while' && !modifiers.includes('&while')))) {
|
|
7671
|
+
this.advance();
|
|
7672
|
+
if (token[1] === 'when') {
|
|
7673
|
+
modifiers.push('&when');
|
|
7674
|
+
whenNode = this.parseExpression();
|
|
7675
|
+
}
|
|
7676
|
+
else {
|
|
7677
|
+
modifiers.push('&while');
|
|
7678
|
+
whileNode = this.parseExpression();
|
|
7679
|
+
}
|
|
7680
|
+
token = this.peek();
|
|
7681
|
+
}
|
|
7682
|
+
assertA_OperatorToken(token, ',');
|
|
7683
|
+
this.advance();
|
|
7684
|
+
return {
|
|
7685
|
+
b: bindingNode,
|
|
7686
|
+
m: modifiers,
|
|
7687
|
+
l: letBindings,
|
|
7688
|
+
wn: whenNode,
|
|
7689
|
+
we: whileNode,
|
|
7690
|
+
};
|
|
7691
|
+
};
|
|
7692
|
+
AlgebraicParser.prototype.parseBinding = function () {
|
|
7693
|
+
var _a;
|
|
7694
|
+
var firstToken = asA_SymbolToken(this.peek());
|
|
7695
|
+
var name = firstToken[1];
|
|
7696
|
+
this.advance();
|
|
7697
|
+
var ofSymbol = asA_SymbolToken(this.peek());
|
|
7698
|
+
if (ofSymbol[1] !== 'of') {
|
|
7699
|
+
throw new LitsError('Expected "of"', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
|
|
7700
|
+
}
|
|
7701
|
+
this.advance();
|
|
7702
|
+
var value = this.parseExpression();
|
|
7703
|
+
var node = {
|
|
7704
|
+
t: AstNodeType.Binding,
|
|
7705
|
+
n: name,
|
|
7706
|
+
v: value,
|
|
7707
|
+
p: [],
|
|
7708
|
+
token: getTokenDebugData(firstToken) && firstToken,
|
|
7709
|
+
};
|
|
7710
|
+
return node;
|
|
7711
|
+
};
|
|
7583
7712
|
AlgebraicParser.prototype.isAtEnd = function () {
|
|
7584
7713
|
return this.parseState.position >= this.tokenStream.tokens.length;
|
|
7585
7714
|
};
|
|
7586
7715
|
AlgebraicParser.prototype.peek = function () {
|
|
7587
7716
|
return this.tokenStream.tokens[this.parseState.position];
|
|
7588
7717
|
};
|
|
7718
|
+
AlgebraicParser.prototype.peekAhead = function () {
|
|
7719
|
+
return this.tokenStream.tokens[this.parseState.position + 1];
|
|
7720
|
+
};
|
|
7589
7721
|
return AlgebraicParser;
|
|
7590
7722
|
}());
|
|
7591
7723
|
|
|
@@ -7777,12 +7909,12 @@ function parseBindings(tokenStream, parseState) {
|
|
|
7777
7909
|
return bindings;
|
|
7778
7910
|
}
|
|
7779
7911
|
function parseBinding(tokenStream, parseState) {
|
|
7780
|
-
var firstToken = asP_SymbolToken(tokenStream.tokens[parseState.position
|
|
7781
|
-
var name =
|
|
7912
|
+
var firstToken = asP_SymbolToken(tokenStream.tokens[parseState.position]);
|
|
7913
|
+
var name = parseSymbol(tokenStream, parseState);
|
|
7782
7914
|
var value = parseState.parseToken(tokenStream, parseState);
|
|
7783
7915
|
var node = {
|
|
7784
7916
|
t: AstNodeType.Binding,
|
|
7785
|
-
n: name,
|
|
7917
|
+
n: name.v,
|
|
7786
7918
|
v: value,
|
|
7787
7919
|
p: [],
|
|
7788
7920
|
token: getTokenDebugData(firstToken) && firstToken,
|
|
@@ -8021,20 +8153,30 @@ var commonTokenizers = [
|
|
|
8021
8153
|
tokenizeString,
|
|
8022
8154
|
];
|
|
8023
8155
|
|
|
8024
|
-
var
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
}
|
|
8035
|
-
|
|
8156
|
+
var algebraicReservedNamesRecord = {
|
|
8157
|
+
'true': { value: true },
|
|
8158
|
+
'false': { value: false },
|
|
8159
|
+
'nil': { value: null },
|
|
8160
|
+
'null': { value: null },
|
|
8161
|
+
'def': { value: null, forbidden: true },
|
|
8162
|
+
'defs': { value: null, forbidden: true },
|
|
8163
|
+
'if-let': { value: null, forbidden: true },
|
|
8164
|
+
'when-let': { value: null, forbidden: true },
|
|
8165
|
+
'when-first': { value: null, forbidden: true },
|
|
8166
|
+
'fn': { value: null, forbidden: true },
|
|
8167
|
+
'defn': { value: null, forbidden: true },
|
|
8168
|
+
'defns': { value: null, forbidden: true },
|
|
8169
|
+
'try': { value: null, forbidden: true },
|
|
8170
|
+
'recur': { value: null, forbidden: true },
|
|
8171
|
+
'loop': { value: null, forbidden: true },
|
|
8172
|
+
'time!': { value: null, forbidden: true },
|
|
8173
|
+
'doseq': { value: null, forbidden: true },
|
|
8036
8174
|
};
|
|
8037
|
-
|
|
8175
|
+
|
|
8176
|
+
var identifierRegExp = new RegExp(algebraicIdentifierCharacterClass);
|
|
8177
|
+
var identifierFirstCharacterRegExp = new RegExp(algebraicIdentifierFirstCharacterClass);
|
|
8178
|
+
var whitespaceRegExp$1 = /\s/;
|
|
8179
|
+
var tokenizeA_Whitespace = function (input, position) {
|
|
8038
8180
|
var char = input[position];
|
|
8039
8181
|
if (!char || !whitespaceRegExp$1.test(char)) {
|
|
8040
8182
|
return NO_MATCH;
|
|
@@ -8047,109 +8189,74 @@ var tokenizeP_Whitespace = function (input, position) {
|
|
|
8047
8189
|
position += 1;
|
|
8048
8190
|
char = input[position];
|
|
8049
8191
|
}
|
|
8050
|
-
return [value.length, ['
|
|
8192
|
+
return [value.length, ['A_Whitespace', value]];
|
|
8051
8193
|
};
|
|
8052
|
-
var endOfNumberRegExp = /[\s)\]},;#`]/;
|
|
8053
8194
|
var decimalNumberRegExp$1 = /\d/;
|
|
8054
8195
|
var octalNumberRegExp$1 = /[0-7]/;
|
|
8055
8196
|
var hexNumberRegExp$1 = /[0-9a-f]/i;
|
|
8056
8197
|
var binaryNumberRegExp$1 = /[01]/;
|
|
8057
|
-
var
|
|
8058
|
-
var tokenizeP_Number = function (input, position) {
|
|
8059
|
-
var type = 'decimal';
|
|
8060
|
-
var firstChar = input[position];
|
|
8061
|
-
if (!firstCharRegExp$1.test(firstChar))
|
|
8062
|
-
return NO_MATCH;
|
|
8063
|
-
var hasDecimals = firstChar === '.';
|
|
8198
|
+
var tokenizeA_Number = function (input, position) {
|
|
8064
8199
|
var i;
|
|
8065
|
-
for (i = position
|
|
8200
|
+
for (i = position; i < input.length; i += 1) {
|
|
8066
8201
|
var char = input[i];
|
|
8067
|
-
if (
|
|
8202
|
+
if (!decimalNumberRegExp$1.test(char)) {
|
|
8068
8203
|
break;
|
|
8069
|
-
if (char === '.') {
|
|
8070
|
-
var nextChar = input[i + 1];
|
|
8071
|
-
if (typeof nextChar === 'string' && !decimalNumberRegExp$1.test(nextChar))
|
|
8072
|
-
break;
|
|
8073
|
-
}
|
|
8074
|
-
if (i === position + 1 && firstChar === '0') {
|
|
8075
|
-
if (char === 'b' || char === 'B') {
|
|
8076
|
-
type = 'binary';
|
|
8077
|
-
continue;
|
|
8078
|
-
}
|
|
8079
|
-
if (char === 'o' || char === 'O') {
|
|
8080
|
-
type = 'octal';
|
|
8081
|
-
continue;
|
|
8082
|
-
}
|
|
8083
|
-
if (char === 'x' || char === 'X') {
|
|
8084
|
-
type = 'hex';
|
|
8085
|
-
continue;
|
|
8086
|
-
}
|
|
8087
|
-
}
|
|
8088
|
-
if (type === 'decimal' && hasDecimals) {
|
|
8089
|
-
if (!decimalNumberRegExp$1.test(char))
|
|
8090
|
-
return NO_MATCH;
|
|
8091
|
-
}
|
|
8092
|
-
else if (type === 'binary') {
|
|
8093
|
-
if (!binaryNumberRegExp$1.test(char))
|
|
8094
|
-
return NO_MATCH;
|
|
8095
|
-
}
|
|
8096
|
-
else if (type === 'octal') {
|
|
8097
|
-
if (!octalNumberRegExp$1.test(char))
|
|
8098
|
-
return NO_MATCH;
|
|
8099
|
-
}
|
|
8100
|
-
else if (type === 'hex') {
|
|
8101
|
-
if (!hexNumberRegExp$1.test(char))
|
|
8102
|
-
return NO_MATCH;
|
|
8103
|
-
}
|
|
8104
|
-
else {
|
|
8105
|
-
if (char === '.') {
|
|
8106
|
-
hasDecimals = true;
|
|
8107
|
-
continue;
|
|
8108
|
-
}
|
|
8109
|
-
if (!decimalNumberRegExp$1.test(char))
|
|
8110
|
-
return NO_MATCH;
|
|
8111
8204
|
}
|
|
8112
8205
|
}
|
|
8113
8206
|
var length = i - position;
|
|
8114
|
-
|
|
8115
|
-
if ((type !== 'decimal' && length <= 2) || value === '.' || value === '-')
|
|
8207
|
+
if (length === 0) {
|
|
8116
8208
|
return NO_MATCH;
|
|
8117
|
-
|
|
8209
|
+
}
|
|
8210
|
+
return [length, ['A_Number', input.substring(position, i)]];
|
|
8118
8211
|
};
|
|
8119
|
-
var
|
|
8120
|
-
|
|
8121
|
-
var char = input[position];
|
|
8122
|
-
var length = 0;
|
|
8123
|
-
var value = '';
|
|
8124
|
-
if (!char || !P_symbolRegExp.test(char))
|
|
8212
|
+
var tokenizeA_BasePrefixedNumber = function (input, position) {
|
|
8213
|
+
if (input[position] !== '0') {
|
|
8125
8214
|
return NO_MATCH;
|
|
8126
|
-
while (char && P_symbolRegExp.test(char)) {
|
|
8127
|
-
value += char;
|
|
8128
|
-
length += 1;
|
|
8129
|
-
char = input[position + length];
|
|
8130
8215
|
}
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8216
|
+
var baseChar = input[position + 1];
|
|
8217
|
+
var type = baseChar === 'b' || baseChar === 'B'
|
|
8218
|
+
? 'binary'
|
|
8219
|
+
: baseChar === 'o' || baseChar === 'O'
|
|
8220
|
+
? 'octal'
|
|
8221
|
+
: baseChar === 'x' || baseChar === 'X'
|
|
8222
|
+
? 'hex'
|
|
8223
|
+
: null;
|
|
8224
|
+
if (type === null) {
|
|
8135
8225
|
return NO_MATCH;
|
|
8136
|
-
|
|
8226
|
+
}
|
|
8227
|
+
var i;
|
|
8228
|
+
for (i = position + 2; i < input.length; i += 1) {
|
|
8229
|
+
var char = input[i];
|
|
8230
|
+
if (type === 'binary' && !binaryNumberRegExp$1.test(char)) {
|
|
8231
|
+
break;
|
|
8232
|
+
}
|
|
8233
|
+
if (type === 'octal' && !octalNumberRegExp$1.test(char)) {
|
|
8234
|
+
break;
|
|
8235
|
+
}
|
|
8236
|
+
if (type === 'hex' && !hexNumberRegExp$1.test(char)) {
|
|
8237
|
+
break;
|
|
8238
|
+
}
|
|
8239
|
+
}
|
|
8240
|
+
var length = i - position;
|
|
8241
|
+
if (length <= 2) {
|
|
8242
|
+
return NO_MATCH;
|
|
8243
|
+
}
|
|
8244
|
+
return [length, ['A_BasePrefixedNumber', input.substring(position, i)]];
|
|
8137
8245
|
};
|
|
8138
|
-
var
|
|
8246
|
+
var tokenizeA_ReservedSymbolToken = function (input, position) {
|
|
8139
8247
|
var e_1, _a;
|
|
8140
8248
|
try {
|
|
8141
|
-
for (var _b = __values(Object.entries(
|
|
8249
|
+
for (var _b = __values(Object.entries(algebraicReservedNamesRecord)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8142
8250
|
var _d = __read(_c.value, 2), reservedName = _d[0], forbidden = _d[1].forbidden;
|
|
8143
|
-
var
|
|
8144
|
-
var nextChar = input[position +
|
|
8145
|
-
if (nextChar &&
|
|
8251
|
+
var length_1 = reservedName.length;
|
|
8252
|
+
var nextChar = input[position + length_1];
|
|
8253
|
+
if (nextChar && identifierRegExp.test(nextChar))
|
|
8146
8254
|
continue;
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
if (symbol === reservedName) {
|
|
8255
|
+
var name_1 = input.substring(position, position + length_1);
|
|
8256
|
+
if (name_1 === reservedName) {
|
|
8150
8257
|
if (forbidden)
|
|
8151
|
-
throw new LitsError("".concat(
|
|
8152
|
-
return [
|
|
8258
|
+
throw new LitsError("".concat(name_1, " is forbidden!"), undefined);
|
|
8259
|
+
return [length_1, ['A_ReservedSymbol', reservedName]];
|
|
8153
8260
|
}
|
|
8154
8261
|
}
|
|
8155
8262
|
}
|
|
@@ -8162,103 +8269,119 @@ var tokenizeP_ReservedSymbol = function (input, position) {
|
|
|
8162
8269
|
}
|
|
8163
8270
|
return NO_MATCH;
|
|
8164
8271
|
};
|
|
8165
|
-
var
|
|
8166
|
-
|
|
8272
|
+
var tokenizeA_Symbol = function (input, position) {
|
|
8273
|
+
var value = input[position];
|
|
8274
|
+
if (!value) {
|
|
8167
8275
|
return NO_MATCH;
|
|
8168
|
-
var symbolDescription = tokenizeP_Symbol(input, position + 1);
|
|
8169
|
-
if (isNoMatch(symbolDescription)) {
|
|
8170
|
-
return symbolDescription;
|
|
8171
8276
|
}
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
var
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
var value = modifierName;
|
|
8184
|
-
return [length_3, ['P_Modifier', value]];
|
|
8277
|
+
if (value === '\'') {
|
|
8278
|
+
var length_2 = 1;
|
|
8279
|
+
var char = input[position + length_2];
|
|
8280
|
+
var escaping = false;
|
|
8281
|
+
while (char !== '\'' || escaping) {
|
|
8282
|
+
if (char === undefined)
|
|
8283
|
+
throw new LitsError("Unclosed string at position ".concat(position, "."), undefined);
|
|
8284
|
+
length_2 += 1;
|
|
8285
|
+
if (escaping) {
|
|
8286
|
+
escaping = false;
|
|
8287
|
+
value += char;
|
|
8185
8288
|
}
|
|
8289
|
+
else {
|
|
8290
|
+
if (char === '\\') {
|
|
8291
|
+
escaping = true;
|
|
8292
|
+
}
|
|
8293
|
+
value += char;
|
|
8294
|
+
}
|
|
8295
|
+
char = input[position + length_2];
|
|
8186
8296
|
}
|
|
8297
|
+
value += '\''; // closing quote
|
|
8298
|
+
return [length_2 + 1, ['A_Symbol', value]];
|
|
8187
8299
|
}
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8300
|
+
if (identifierFirstCharacterRegExp.test(value)) {
|
|
8301
|
+
var initialPosition = position;
|
|
8302
|
+
position += 1;
|
|
8303
|
+
var char = input[position];
|
|
8304
|
+
while (char && identifierRegExp.test(char)) {
|
|
8305
|
+
value += char;
|
|
8306
|
+
position += 1;
|
|
8307
|
+
char = input[position];
|
|
8192
8308
|
}
|
|
8193
|
-
|
|
8309
|
+
return [position - initialPosition, ['A_Symbol', value]];
|
|
8194
8310
|
}
|
|
8195
8311
|
return NO_MATCH;
|
|
8196
8312
|
};
|
|
8197
|
-
var
|
|
8198
|
-
var
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8313
|
+
var tokenizeA_Operator = function (input, position) {
|
|
8314
|
+
var _a;
|
|
8315
|
+
var threeChars = input.slice(position, position + 3);
|
|
8316
|
+
if (position + 2 < input.length && isSymbolicOperator(threeChars)) {
|
|
8317
|
+
return [3, ['A_Operator', threeChars]];
|
|
8318
|
+
}
|
|
8319
|
+
var twoChars = input.slice(position, position + 2);
|
|
8320
|
+
if (position + 1 < input.length && isSymbolicOperator(twoChars)) {
|
|
8321
|
+
return [2, ['A_Operator', twoChars]];
|
|
8322
|
+
}
|
|
8323
|
+
var oneChar = (_a = input[position]) !== null && _a !== void 0 ? _a : '';
|
|
8324
|
+
if (isSymbolicOperator(oneChar)) {
|
|
8325
|
+
return [1, ['A_Operator', oneChar]];
|
|
8326
|
+
}
|
|
8327
|
+
return NO_MATCH;
|
|
8202
8328
|
};
|
|
8203
|
-
var
|
|
8204
|
-
if (input[position]
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
var length = stringLength + 1;
|
|
8211
|
-
var options = '';
|
|
8212
|
-
while (input[position] === 'g' || input[position] === 'i') {
|
|
8213
|
-
if (options.includes(input[position])) {
|
|
8214
|
-
throw new LitsError("Duplicated regexp option \"".concat(input[position], "\" at position ").concat(position, "."), undefined);
|
|
8329
|
+
var tokenizeA_MultiLineComment = function (input, position) {
|
|
8330
|
+
if (input[position] === '/' && input[position + 1] === '*') {
|
|
8331
|
+
var length_3 = 2;
|
|
8332
|
+
var value = '/*';
|
|
8333
|
+
while (input[position + length_3] !== '*' && input[position + length_3 + 1] !== '/' && position + length_3 + 1 < input.length) {
|
|
8334
|
+
value += input[position + length_3];
|
|
8335
|
+
length_3 += 1;
|
|
8215
8336
|
}
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8337
|
+
if (position + length_3 + 1 >= input.length) {
|
|
8338
|
+
throw new LitsError('Comment not closed', undefined);
|
|
8339
|
+
}
|
|
8340
|
+
value += '*/';
|
|
8341
|
+
length_3 += 2;
|
|
8342
|
+
return [length_3, ['A_MultiLineComment', value]];
|
|
8219
8343
|
}
|
|
8220
|
-
return
|
|
8344
|
+
return NO_MATCH;
|
|
8345
|
+
};
|
|
8346
|
+
var tokenizeA_SingleLineComment = function (input, position) {
|
|
8347
|
+
if (input[position] === '/' && input[position + 1] === '/') {
|
|
8348
|
+
var length_4 = 2;
|
|
8349
|
+
var value = '//';
|
|
8350
|
+
while (input[position + length_4] !== '\n' && position + length_4 < input.length) {
|
|
8351
|
+
value += input[position + length_4];
|
|
8352
|
+
length_4 += 1;
|
|
8353
|
+
}
|
|
8354
|
+
return [length_4, ['A_SingleLineComment', value]];
|
|
8355
|
+
}
|
|
8356
|
+
return NO_MATCH;
|
|
8221
8357
|
};
|
|
8222
8358
|
// All tokenizers, order matters!
|
|
8223
|
-
var
|
|
8224
|
-
|
|
8225
|
-
|
|
8359
|
+
var algebraicTokenizers = __spreadArray(__spreadArray([
|
|
8360
|
+
tokenizeA_Whitespace,
|
|
8361
|
+
tokenizeA_MultiLineComment,
|
|
8362
|
+
tokenizeA_SingleLineComment
|
|
8226
8363
|
], __read(commonTokenizers), false), [
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
tokenizeP_RegexpShorthand,
|
|
8233
|
-
tokenizeP_FnShorthand,
|
|
8234
|
-
tokenizeP_CollectionAccessor,
|
|
8364
|
+
tokenizeA_BasePrefixedNumber,
|
|
8365
|
+
tokenizeA_Number,
|
|
8366
|
+
tokenizeA_Operator,
|
|
8367
|
+
tokenizeA_ReservedSymbolToken,
|
|
8368
|
+
tokenizeA_Symbol,
|
|
8235
8369
|
], false);
|
|
8236
8370
|
|
|
8237
|
-
var
|
|
8238
|
-
|
|
8239
|
-
'
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
'defns': { value: null, forbidden: true },
|
|
8250
|
-
'try': { value: null, forbidden: true },
|
|
8251
|
-
'recur': { value: null, forbidden: true },
|
|
8252
|
-
'loop': { value: null, forbidden: true },
|
|
8253
|
-
'time!': { value: null, forbidden: true },
|
|
8254
|
-
'doseq': { value: null, forbidden: true },
|
|
8255
|
-
'for': { value: null, forbidden: true },
|
|
8371
|
+
var whitespaceRegExp = /\s|,/;
|
|
8372
|
+
var tokenizeP_Comment = function (input, position) {
|
|
8373
|
+
if (input[position] === ';') {
|
|
8374
|
+
var length_1 = 0;
|
|
8375
|
+
var value = '';
|
|
8376
|
+
while (input[position + length_1] !== '\n' && position + length_1 < input.length) {
|
|
8377
|
+
value += input[position + length_1];
|
|
8378
|
+
length_1 += 1;
|
|
8379
|
+
}
|
|
8380
|
+
return [length_1, ['P_Comment', value]];
|
|
8381
|
+
}
|
|
8382
|
+
return NO_MATCH;
|
|
8256
8383
|
};
|
|
8257
|
-
|
|
8258
|
-
var identifierRegExp = new RegExp(algebraicIdentifierCharacterClass);
|
|
8259
|
-
var identifierFirstCharacterRegExp = new RegExp(algebraicIdentifierFirstCharacterClass);
|
|
8260
|
-
var whitespaceRegExp = /\s/;
|
|
8261
|
-
var tokenizeA_Whitespace = function (input, position) {
|
|
8384
|
+
var tokenizeP_Whitespace = function (input, position) {
|
|
8262
8385
|
var char = input[position];
|
|
8263
8386
|
if (!char || !whitespaceRegExp.test(char)) {
|
|
8264
8387
|
return NO_MATCH;
|
|
@@ -8271,14 +8394,15 @@ var tokenizeA_Whitespace = function (input, position) {
|
|
|
8271
8394
|
position += 1;
|
|
8272
8395
|
char = input[position];
|
|
8273
8396
|
}
|
|
8274
|
-
return [value.length, ['
|
|
8397
|
+
return [value.length, ['P_Whitespace', value]];
|
|
8275
8398
|
};
|
|
8399
|
+
var endOfNumberRegExp = /[\s)\]},;#`]/;
|
|
8276
8400
|
var decimalNumberRegExp = /\d/;
|
|
8277
8401
|
var octalNumberRegExp = /[0-7]/;
|
|
8278
8402
|
var hexNumberRegExp = /[0-9a-f]/i;
|
|
8279
8403
|
var binaryNumberRegExp = /[01]/;
|
|
8280
|
-
var firstCharRegExp = /[0-9
|
|
8281
|
-
var
|
|
8404
|
+
var firstCharRegExp = /[0-9.-]/;
|
|
8405
|
+
var tokenizeP_Number = function (input, position) {
|
|
8282
8406
|
var type = 'decimal';
|
|
8283
8407
|
var firstChar = input[position];
|
|
8284
8408
|
if (!firstCharRegExp.test(firstChar))
|
|
@@ -8287,7 +8411,14 @@ var tokenizeA_Number = function (input, position) {
|
|
|
8287
8411
|
var i;
|
|
8288
8412
|
for (i = position + 1; i < input.length; i += 1) {
|
|
8289
8413
|
var char = input[i];
|
|
8290
|
-
if ((
|
|
8414
|
+
if (endOfNumberRegExp.test(char))
|
|
8415
|
+
break;
|
|
8416
|
+
if (char === '.') {
|
|
8417
|
+
var nextChar = input[i + 1];
|
|
8418
|
+
if (typeof nextChar === 'string' && !decimalNumberRegExp.test(nextChar))
|
|
8419
|
+
break;
|
|
8420
|
+
}
|
|
8421
|
+
if (i === position + 1 && firstChar === '0') {
|
|
8291
8422
|
if (char === 'b' || char === 'B') {
|
|
8292
8423
|
type = 'binary';
|
|
8293
8424
|
continue;
|
|
@@ -8301,30 +8432,6 @@ var tokenizeA_Number = function (input, position) {
|
|
|
8301
8432
|
continue;
|
|
8302
8433
|
}
|
|
8303
8434
|
}
|
|
8304
|
-
if (type === 'decimal') {
|
|
8305
|
-
if (hasDecimals) {
|
|
8306
|
-
if (!decimalNumberRegExp.test(char)) {
|
|
8307
|
-
break;
|
|
8308
|
-
}
|
|
8309
|
-
}
|
|
8310
|
-
else if (char !== '.' && !decimalNumberRegExp.test(char)) {
|
|
8311
|
-
break;
|
|
8312
|
-
}
|
|
8313
|
-
}
|
|
8314
|
-
if (type === 'binary' && !binaryNumberRegExp.test(char)) {
|
|
8315
|
-
break;
|
|
8316
|
-
}
|
|
8317
|
-
if (type === 'octal' && !octalNumberRegExp.test(char)) {
|
|
8318
|
-
break;
|
|
8319
|
-
}
|
|
8320
|
-
if (type === 'hex' && !hexNumberRegExp.test(char)) {
|
|
8321
|
-
break;
|
|
8322
|
-
}
|
|
8323
|
-
if (char === '.') {
|
|
8324
|
-
var nextChar = input[i + 1];
|
|
8325
|
-
if (typeof nextChar === 'string' && !decimalNumberRegExp.test(nextChar))
|
|
8326
|
-
break;
|
|
8327
|
-
}
|
|
8328
8435
|
if (type === 'decimal' && hasDecimals) {
|
|
8329
8436
|
if (!decimalNumberRegExp.test(char))
|
|
8330
8437
|
return NO_MATCH;
|
|
@@ -8354,22 +8461,70 @@ var tokenizeA_Number = function (input, position) {
|
|
|
8354
8461
|
var value = input.substring(position, i);
|
|
8355
8462
|
if ((type !== 'decimal' && length <= 2) || value === '.' || value === '-')
|
|
8356
8463
|
return NO_MATCH;
|
|
8357
|
-
return [length, ['
|
|
8464
|
+
return [length, ['P_Number', value]];
|
|
8358
8465
|
};
|
|
8359
|
-
var
|
|
8466
|
+
var P_symbolRegExp = new RegExp(polishIdentifierCharacterClass);
|
|
8467
|
+
var tokenizeP_Symbol = function (input, position) {
|
|
8468
|
+
var value = input[position];
|
|
8469
|
+
if (!value) {
|
|
8470
|
+
return NO_MATCH;
|
|
8471
|
+
}
|
|
8472
|
+
if (value === '\'') {
|
|
8473
|
+
var length_2 = 1;
|
|
8474
|
+
var char = input[position + length_2];
|
|
8475
|
+
var escaping = false;
|
|
8476
|
+
while (char !== '\'' || escaping) {
|
|
8477
|
+
if (char === undefined)
|
|
8478
|
+
throw new LitsError("Unclosed string at position ".concat(position, "."), undefined);
|
|
8479
|
+
length_2 += 1;
|
|
8480
|
+
if (escaping) {
|
|
8481
|
+
escaping = false;
|
|
8482
|
+
value += char;
|
|
8483
|
+
}
|
|
8484
|
+
else {
|
|
8485
|
+
if (char === '\\') {
|
|
8486
|
+
escaping = true;
|
|
8487
|
+
}
|
|
8488
|
+
value += char;
|
|
8489
|
+
}
|
|
8490
|
+
char = input[position + length_2];
|
|
8491
|
+
}
|
|
8492
|
+
value += '\''; // closing quote
|
|
8493
|
+
return [length_2 + 1, ['P_Symbol', value]];
|
|
8494
|
+
}
|
|
8495
|
+
if (P_symbolRegExp.test(value)) {
|
|
8496
|
+
var initialPosition = position;
|
|
8497
|
+
position += 1;
|
|
8498
|
+
var char = input[position];
|
|
8499
|
+
while (char && P_symbolRegExp.test(char)) {
|
|
8500
|
+
value += char;
|
|
8501
|
+
position += 1;
|
|
8502
|
+
char = input[position];
|
|
8503
|
+
}
|
|
8504
|
+
return [position - initialPosition, ['P_Symbol', value]];
|
|
8505
|
+
}
|
|
8506
|
+
return NO_MATCH;
|
|
8507
|
+
};
|
|
8508
|
+
var tokenizeP_FnShorthand = function (input, position) {
|
|
8509
|
+
if (input.slice(position, position + 2) !== '#(')
|
|
8510
|
+
return NO_MATCH;
|
|
8511
|
+
return [1, ['P_FnShorthand']];
|
|
8512
|
+
};
|
|
8513
|
+
var tokenizeP_ReservedSymbol = function (input, position) {
|
|
8360
8514
|
var e_1, _a;
|
|
8361
8515
|
try {
|
|
8362
|
-
for (var _b = __values(Object.entries(
|
|
8516
|
+
for (var _b = __values(Object.entries(polishReservedNamesRecord)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
8363
8517
|
var _d = __read(_c.value, 2), reservedName = _d[0], forbidden = _d[1].forbidden;
|
|
8364
|
-
var
|
|
8365
|
-
var nextChar = input[position +
|
|
8366
|
-
if (nextChar &&
|
|
8518
|
+
var length_3 = reservedName.length;
|
|
8519
|
+
var nextChar = input[position + length_3];
|
|
8520
|
+
if (nextChar && P_symbolRegExp.test(nextChar)) {
|
|
8367
8521
|
continue;
|
|
8368
|
-
|
|
8369
|
-
|
|
8522
|
+
}
|
|
8523
|
+
var symbol = input.substring(position, position + length_3);
|
|
8524
|
+
if (symbol === reservedName) {
|
|
8370
8525
|
if (forbidden)
|
|
8371
|
-
throw new LitsError("".concat(
|
|
8372
|
-
return [
|
|
8526
|
+
throw new LitsError("".concat(symbol, " is forbidden!"), undefined);
|
|
8527
|
+
return [length_3, ['P_ReservedSymbol', reservedName]];
|
|
8373
8528
|
}
|
|
8374
8529
|
}
|
|
8375
8530
|
}
|
|
@@ -8382,93 +8537,76 @@ var tokenizeA_ReservedSymbolToken = function (input, position) {
|
|
|
8382
8537
|
}
|
|
8383
8538
|
return NO_MATCH;
|
|
8384
8539
|
};
|
|
8385
|
-
var
|
|
8386
|
-
|
|
8387
|
-
var value = input[position];
|
|
8388
|
-
if (!value) {
|
|
8540
|
+
var tokenizeP_StringShorthand = function (input, position) {
|
|
8541
|
+
if (input[position] !== ':')
|
|
8389
8542
|
return NO_MATCH;
|
|
8543
|
+
var symbolDescription = tokenizeP_Symbol(input, position + 1);
|
|
8544
|
+
if (isNoMatch(symbolDescription)) {
|
|
8545
|
+
return symbolDescription;
|
|
8390
8546
|
}
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
|
|
8547
|
+
var symbolToken = asP_SymbolToken(symbolDescription[1]);
|
|
8548
|
+
return [symbolDescription[0] + 1, ['P_StringShorthand', ":".concat(symbolToken[1])]];
|
|
8549
|
+
};
|
|
8550
|
+
var tokenizeP_Modifier = function (input, position) {
|
|
8551
|
+
var e_2, _a;
|
|
8552
|
+
try {
|
|
8553
|
+
for (var modifierNames_1 = __values(modifierNames), modifierNames_1_1 = modifierNames_1.next(); !modifierNames_1_1.done; modifierNames_1_1 = modifierNames_1.next()) {
|
|
8554
|
+
var modifierName = modifierNames_1_1.value;
|
|
8555
|
+
var length_4 = modifierName.length;
|
|
8556
|
+
var charAfterModifier = input[position + length_4];
|
|
8557
|
+
if (input.substring(position, position + length_4) === modifierName && (!charAfterModifier || !P_symbolRegExp.test(charAfterModifier))) {
|
|
8558
|
+
var value = modifierName;
|
|
8559
|
+
return [length_4, ['P_Modifier', value]];
|
|
8560
|
+
}
|
|
8398
8561
|
}
|
|
8399
|
-
return [position - initialPosition, ['A_Symbol', value]];
|
|
8400
8562
|
}
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
return NO_MATCH;
|
|
8406
|
-
}
|
|
8407
|
-
position += count;
|
|
8408
|
-
if (input[position] !== '\'') {
|
|
8409
|
-
return NO_MATCH;
|
|
8563
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
8564
|
+
finally {
|
|
8565
|
+
try {
|
|
8566
|
+
if (modifierNames_1_1 && !modifierNames_1_1.done && (_a = modifierNames_1.return)) _a.call(modifierNames_1);
|
|
8410
8567
|
}
|
|
8411
|
-
|
|
8412
|
-
var pfValue = pfSymbolToken[1];
|
|
8413
|
-
return [position - initialPosition, ['A_Symbol', pfValue]];
|
|
8414
|
-
}
|
|
8415
|
-
return NO_MATCH;
|
|
8416
|
-
};
|
|
8417
|
-
var tokenizeA_Operator = function (input, position) {
|
|
8418
|
-
var _a;
|
|
8419
|
-
var threeChars = input.slice(position, position + 3);
|
|
8420
|
-
if (position + 2 < input.length && isAlgebraicOperator(threeChars)) {
|
|
8421
|
-
return [3, ['A_Operator', threeChars]];
|
|
8422
|
-
}
|
|
8423
|
-
var twoChars = input.slice(position, position + 2);
|
|
8424
|
-
if (position + 1 < input.length && isAlgebraicOperator(twoChars)) {
|
|
8425
|
-
return [2, ['A_Operator', twoChars]];
|
|
8426
|
-
}
|
|
8427
|
-
var oneChar = (_a = input[position]) !== null && _a !== void 0 ? _a : '';
|
|
8428
|
-
if (isAlgebraicOperator(oneChar)) {
|
|
8429
|
-
return [1, ['A_Operator', oneChar]];
|
|
8568
|
+
finally { if (e_2) throw e_2.error; }
|
|
8430
8569
|
}
|
|
8431
8570
|
return NO_MATCH;
|
|
8432
8571
|
};
|
|
8433
|
-
var
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
value += input[position + length_2];
|
|
8439
|
-
length_2 += 1;
|
|
8440
|
-
}
|
|
8441
|
-
if (position + length_2 + 1 >= input.length) {
|
|
8442
|
-
throw new LitsError('Comment not closed', undefined);
|
|
8443
|
-
}
|
|
8444
|
-
value += '*/';
|
|
8445
|
-
length_2 += 2;
|
|
8446
|
-
return [length_2, ['A_MultiLineComment', value]];
|
|
8447
|
-
}
|
|
8448
|
-
return NO_MATCH;
|
|
8572
|
+
var tokenizeP_CollectionAccessor = function (input, position) {
|
|
8573
|
+
var char = input[position];
|
|
8574
|
+
if (char !== '.' && char !== '#')
|
|
8575
|
+
return NO_MATCH;
|
|
8576
|
+
return [1, ['P_CollectionAccessor', char]];
|
|
8449
8577
|
};
|
|
8450
|
-
var
|
|
8451
|
-
if (input[position]
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8578
|
+
var tokenizeP_RegexpShorthand = function (input, position) {
|
|
8579
|
+
if (input[position] !== '#')
|
|
8580
|
+
return NO_MATCH;
|
|
8581
|
+
var _a = __read(tokenizeString(input, position + 1), 2), stringLength = _a[0], token = _a[1];
|
|
8582
|
+
if (!token)
|
|
8583
|
+
return NO_MATCH;
|
|
8584
|
+
position += stringLength + 1;
|
|
8585
|
+
var length = stringLength + 1;
|
|
8586
|
+
var options = '';
|
|
8587
|
+
while (input[position] === 'g' || input[position] === 'i') {
|
|
8588
|
+
if (options.includes(input[position])) {
|
|
8589
|
+
throw new LitsError("Duplicated regexp option \"".concat(input[position], "\" at position ").concat(position, "."), undefined);
|
|
8457
8590
|
}
|
|
8458
|
-
|
|
8591
|
+
options += input[position];
|
|
8592
|
+
length += 1;
|
|
8593
|
+
position += 1;
|
|
8459
8594
|
}
|
|
8460
|
-
return
|
|
8595
|
+
return [length, ['P_RegexpShorthand', "#".concat(token[1]).concat(options)]];
|
|
8461
8596
|
};
|
|
8462
8597
|
// All tokenizers, order matters!
|
|
8463
|
-
var
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
tokenizeA_SingleLineComment
|
|
8598
|
+
var polishTokenizers = __spreadArray(__spreadArray([
|
|
8599
|
+
tokenizeP_Whitespace,
|
|
8600
|
+
tokenizeP_Comment
|
|
8467
8601
|
], __read(commonTokenizers), false), [
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
|
|
8471
|
-
|
|
8602
|
+
tokenizeP_StringShorthand,
|
|
8603
|
+
tokenizeP_Number,
|
|
8604
|
+
tokenizeP_ReservedSymbol,
|
|
8605
|
+
tokenizeP_Symbol,
|
|
8606
|
+
tokenizeP_Modifier,
|
|
8607
|
+
tokenizeP_RegexpShorthand,
|
|
8608
|
+
tokenizeP_FnShorthand,
|
|
8609
|
+
tokenizeP_CollectionAccessor,
|
|
8472
8610
|
], false);
|
|
8473
8611
|
|
|
8474
8612
|
var applyCollectionAccessors = function (tokenStream) {
|