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