@mojir/lits 2.1.5 → 2.1.7
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 +575 -489
- package/dist/cli/reference/api.d.ts +4 -4
- package/dist/cli/reference/index.d.ts +3 -3
- package/dist/cli/src/parser/Parser.d.ts +3 -1
- package/dist/cli/src/parser/types.d.ts +1 -0
- package/dist/cli/src/tokenizer/operators.d.ts +2 -2
- package/dist/cli/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/cli/src/tokenizer/token.d.ts +51 -51
- package/dist/index.esm.js +574 -488
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +574 -488
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +574 -488
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +4 -4
- package/dist/reference/index.d.ts +3 -3
- package/dist/src/parser/Parser.d.ts +3 -1
- package/dist/src/parser/types.d.ts +1 -0
- package/dist/src/tokenizer/operators.d.ts +2 -2
- package/dist/src/tokenizer/reservedNames.d.ts +2 -0
- package/dist/src/tokenizer/token.d.ts +51 -51
- package/dist/testFramework.esm.js +415 -326
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +415 -326
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/lits.iife.js
CHANGED
|
@@ -827,6 +827,32 @@ var Lits = (function (exports) {
|
|
|
827
827
|
throw getAssertionError('array of strings', value, sourceCodeInfo);
|
|
828
828
|
}
|
|
829
829
|
|
|
830
|
+
function mapObjects(_a) {
|
|
831
|
+
var colls = _a.colls, contextStack = _a.contextStack, executeFunction = _a.executeFunction, fn = _a.fn, sourceCodeInfo = _a.sourceCodeInfo;
|
|
832
|
+
assertObj(colls[0], sourceCodeInfo);
|
|
833
|
+
var keys = Object.keys(colls[0]);
|
|
834
|
+
var params = {};
|
|
835
|
+
colls.forEach(function (obj) {
|
|
836
|
+
assertObj(obj, sourceCodeInfo);
|
|
837
|
+
var objKeys = Object.keys(obj);
|
|
838
|
+
if (objKeys.length !== keys.length) {
|
|
839
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
840
|
+
}
|
|
841
|
+
if (!objKeys.every(function (key) { return keys.includes(key); })) {
|
|
842
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
843
|
+
}
|
|
844
|
+
Object.entries(obj).forEach(function (_a) {
|
|
845
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
846
|
+
if (!params[key])
|
|
847
|
+
params[key] = [];
|
|
848
|
+
params[key].push(value);
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
return keys.reduce(function (result, key) {
|
|
852
|
+
result[key] = executeFunction(fn, params[key], contextStack, sourceCodeInfo);
|
|
853
|
+
return result;
|
|
854
|
+
}, {});
|
|
855
|
+
}
|
|
830
856
|
function cloneAndGetMeta(originalColl, keys, sourceCodeInfo) {
|
|
831
857
|
var coll = cloneColl(originalColl);
|
|
832
858
|
var butLastKeys = keys.slice(0, keys.length - 1);
|
|
@@ -919,6 +945,188 @@ var Lits = (function (exports) {
|
|
|
919
945
|
return copy;
|
|
920
946
|
}
|
|
921
947
|
var collectionNormalExpression = {
|
|
948
|
+
'filter': {
|
|
949
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
950
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
951
|
+
var executeFunction = _b.executeFunction;
|
|
952
|
+
assertColl(coll, sourceCodeInfo);
|
|
953
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
954
|
+
if (Array.isArray(coll)) {
|
|
955
|
+
var result = coll.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
956
|
+
return result;
|
|
957
|
+
}
|
|
958
|
+
if (isString(coll)) {
|
|
959
|
+
return coll
|
|
960
|
+
.split('')
|
|
961
|
+
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
962
|
+
.join('');
|
|
963
|
+
}
|
|
964
|
+
return Object.entries(coll)
|
|
965
|
+
.filter(function (_a) {
|
|
966
|
+
var _b = __read(_a, 2), value = _b[1];
|
|
967
|
+
return executeFunction(fn, [value], contextStack, sourceCodeInfo);
|
|
968
|
+
})
|
|
969
|
+
.reduce(function (result, _a) {
|
|
970
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
971
|
+
result[key] = value;
|
|
972
|
+
return result;
|
|
973
|
+
}, {});
|
|
974
|
+
},
|
|
975
|
+
paramCount: 2,
|
|
976
|
+
},
|
|
977
|
+
'map': {
|
|
978
|
+
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
979
|
+
var executeFunction = _a.executeFunction;
|
|
980
|
+
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
981
|
+
if (isObj(params[0])) {
|
|
982
|
+
return mapObjects({
|
|
983
|
+
colls: params.slice(0, -1),
|
|
984
|
+
fn: fn,
|
|
985
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
986
|
+
contextStack: contextStack,
|
|
987
|
+
executeFunction: executeFunction,
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
var seqs = params.slice(0, -1);
|
|
991
|
+
assertSeq(seqs[0], sourceCodeInfo);
|
|
992
|
+
var isStr = typeof seqs[0] === 'string';
|
|
993
|
+
var len = seqs[0].length;
|
|
994
|
+
seqs.slice(1).forEach(function (seq) {
|
|
995
|
+
if (isStr) {
|
|
996
|
+
assertString(seq, sourceCodeInfo);
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
assertArray(seq, sourceCodeInfo);
|
|
1000
|
+
}
|
|
1001
|
+
len = Math.min(len, seq.length);
|
|
1002
|
+
});
|
|
1003
|
+
var paramArray = [];
|
|
1004
|
+
var _loop_1 = function (i) {
|
|
1005
|
+
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1006
|
+
};
|
|
1007
|
+
for (var i = 0; i < len; i++) {
|
|
1008
|
+
_loop_1(i);
|
|
1009
|
+
}
|
|
1010
|
+
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1011
|
+
if (!isStr) {
|
|
1012
|
+
return mapped;
|
|
1013
|
+
}
|
|
1014
|
+
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1015
|
+
return mapped.join('');
|
|
1016
|
+
},
|
|
1017
|
+
paramCount: { min: 2 },
|
|
1018
|
+
},
|
|
1019
|
+
'reduce': {
|
|
1020
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1021
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1022
|
+
var executeFunction = _b.executeFunction;
|
|
1023
|
+
assertColl(coll, sourceCodeInfo);
|
|
1024
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1025
|
+
assertAny(initial, sourceCodeInfo);
|
|
1026
|
+
if (typeof coll === 'string') {
|
|
1027
|
+
assertString(initial, sourceCodeInfo);
|
|
1028
|
+
if (coll.length === 0)
|
|
1029
|
+
return initial;
|
|
1030
|
+
return coll.split('').reduce(function (result, elem) {
|
|
1031
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1032
|
+
}, initial);
|
|
1033
|
+
}
|
|
1034
|
+
else if (Array.isArray(coll)) {
|
|
1035
|
+
if (coll.length === 0)
|
|
1036
|
+
return initial;
|
|
1037
|
+
return coll.reduce(function (result, elem) {
|
|
1038
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1039
|
+
}, initial);
|
|
1040
|
+
}
|
|
1041
|
+
else {
|
|
1042
|
+
if (Object.keys(coll).length === 0)
|
|
1043
|
+
return initial;
|
|
1044
|
+
return Object.entries(coll).reduce(function (result, _a) {
|
|
1045
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1046
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1047
|
+
}, initial);
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1050
|
+
paramCount: 3,
|
|
1051
|
+
},
|
|
1052
|
+
'reduce-right': {
|
|
1053
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1054
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1055
|
+
var executeFunction = _b.executeFunction;
|
|
1056
|
+
assertColl(coll, sourceCodeInfo);
|
|
1057
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1058
|
+
assertAny(initial, sourceCodeInfo);
|
|
1059
|
+
if (typeof coll === 'string') {
|
|
1060
|
+
if (coll.length === 0)
|
|
1061
|
+
return initial;
|
|
1062
|
+
return coll.split('').reduceRight(function (result, elem) {
|
|
1063
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1064
|
+
}, initial);
|
|
1065
|
+
}
|
|
1066
|
+
else if (Array.isArray(coll)) {
|
|
1067
|
+
if (coll.length === 0)
|
|
1068
|
+
return initial;
|
|
1069
|
+
return coll.reduceRight(function (result, elem) {
|
|
1070
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1071
|
+
}, initial);
|
|
1072
|
+
}
|
|
1073
|
+
else {
|
|
1074
|
+
if (Object.keys(coll).length === 0)
|
|
1075
|
+
return initial;
|
|
1076
|
+
return Object.entries(coll).reduceRight(function (result, _a) {
|
|
1077
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1078
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1079
|
+
}, initial);
|
|
1080
|
+
}
|
|
1081
|
+
},
|
|
1082
|
+
paramCount: 3,
|
|
1083
|
+
},
|
|
1084
|
+
'reductions': {
|
|
1085
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1086
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1087
|
+
var executeFunction = _b.executeFunction;
|
|
1088
|
+
assertColl(coll, sourceCodeInfo);
|
|
1089
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1090
|
+
assertAny(initial, sourceCodeInfo);
|
|
1091
|
+
assertAny(initial, sourceCodeInfo);
|
|
1092
|
+
if (typeof coll === 'string') {
|
|
1093
|
+
assertString(initial, sourceCodeInfo);
|
|
1094
|
+
if (coll.length === 0)
|
|
1095
|
+
return [initial];
|
|
1096
|
+
var resultArray_1 = [initial];
|
|
1097
|
+
coll.split('').reduce(function (result, elem) {
|
|
1098
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1099
|
+
resultArray_1.push(newVal);
|
|
1100
|
+
return newVal;
|
|
1101
|
+
}, initial);
|
|
1102
|
+
return resultArray_1;
|
|
1103
|
+
}
|
|
1104
|
+
else if (Array.isArray(coll)) {
|
|
1105
|
+
if (coll.length === 0)
|
|
1106
|
+
return [initial];
|
|
1107
|
+
var resultArray_2 = [initial];
|
|
1108
|
+
coll.reduce(function (result, elem) {
|
|
1109
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1110
|
+
resultArray_2.push(newVal);
|
|
1111
|
+
return newVal;
|
|
1112
|
+
}, initial);
|
|
1113
|
+
return resultArray_2;
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
if (Object.keys(coll).length === 0)
|
|
1117
|
+
return [initial];
|
|
1118
|
+
var resultArray_3 = [initial];
|
|
1119
|
+
Object.entries(coll).reduce(function (result, _a) {
|
|
1120
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1121
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1122
|
+
resultArray_3.push(newVal);
|
|
1123
|
+
return newVal;
|
|
1124
|
+
}, initial);
|
|
1125
|
+
return resultArray_3;
|
|
1126
|
+
}
|
|
1127
|
+
},
|
|
1128
|
+
paramCount: 3,
|
|
1129
|
+
},
|
|
922
1130
|
'get': {
|
|
923
1131
|
evaluate: function (params, sourceCodeInfo) {
|
|
924
1132
|
var _a = __read(params, 2), coll = _a[0], key = _a[1];
|
|
@@ -1222,13 +1430,15 @@ var Lits = (function (exports) {
|
|
|
1222
1430
|
paramCount: 2,
|
|
1223
1431
|
},
|
|
1224
1432
|
flatten: {
|
|
1225
|
-
evaluate: function (_a) {
|
|
1226
|
-
var _b = __read(_a,
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1433
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
1434
|
+
var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
|
|
1435
|
+
assertArray(seq, sourceCodeInfo);
|
|
1436
|
+
var actualDepth = depth === undefined || depth === Number.POSITIVE_INFINITY
|
|
1437
|
+
? Number.POSITIVE_INFINITY
|
|
1438
|
+
: asNumber(depth, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
1439
|
+
return seq.flat(actualDepth);
|
|
1230
1440
|
},
|
|
1231
|
-
paramCount: 1,
|
|
1441
|
+
paramCount: { min: 1, max: 2 },
|
|
1232
1442
|
},
|
|
1233
1443
|
mapcat: {
|
|
1234
1444
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -1261,23 +1471,6 @@ var Lits = (function (exports) {
|
|
|
1261
1471
|
},
|
|
1262
1472
|
paramCount: { min: 2, max: 3 },
|
|
1263
1473
|
},
|
|
1264
|
-
'filter': {
|
|
1265
|
-
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1266
|
-
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
1267
|
-
var executeFunction = _b.executeFunction;
|
|
1268
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1269
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1270
|
-
if (Array.isArray(seq)) {
|
|
1271
|
-
var result = seq.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1272
|
-
return result;
|
|
1273
|
-
}
|
|
1274
|
-
return seq
|
|
1275
|
-
.split('')
|
|
1276
|
-
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
1277
|
-
.join('');
|
|
1278
|
-
},
|
|
1279
|
-
paramCount: 2,
|
|
1280
|
-
},
|
|
1281
1474
|
'first': {
|
|
1282
1475
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1283
1476
|
var _b = __read(_a, 1), array = _b[0];
|
|
@@ -1300,39 +1493,6 @@ var Lits = (function (exports) {
|
|
|
1300
1493
|
},
|
|
1301
1494
|
paramCount: 1,
|
|
1302
1495
|
},
|
|
1303
|
-
'map': {
|
|
1304
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1305
|
-
var executeFunction = _a.executeFunction;
|
|
1306
|
-
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
1307
|
-
var seqs = params.slice(0, -1);
|
|
1308
|
-
assertSeq(seqs[0], sourceCodeInfo);
|
|
1309
|
-
var isString = typeof seqs[0] === 'string';
|
|
1310
|
-
var len = seqs[0].length;
|
|
1311
|
-
seqs.slice(1).forEach(function (seq) {
|
|
1312
|
-
if (isString) {
|
|
1313
|
-
assertString(seq, sourceCodeInfo);
|
|
1314
|
-
}
|
|
1315
|
-
else {
|
|
1316
|
-
assertArray(seq, sourceCodeInfo);
|
|
1317
|
-
}
|
|
1318
|
-
len = Math.min(len, seq.length);
|
|
1319
|
-
});
|
|
1320
|
-
var paramArray = [];
|
|
1321
|
-
var _loop_1 = function (i) {
|
|
1322
|
-
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1323
|
-
};
|
|
1324
|
-
for (var i = 0; i < len; i++) {
|
|
1325
|
-
_loop_1(i);
|
|
1326
|
-
}
|
|
1327
|
-
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1328
|
-
if (!isString) {
|
|
1329
|
-
return mapped;
|
|
1330
|
-
}
|
|
1331
|
-
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1332
|
-
return mapped.join('');
|
|
1333
|
-
},
|
|
1334
|
-
paramCount: { min: 2 },
|
|
1335
|
-
},
|
|
1336
1496
|
'pop': {
|
|
1337
1497
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1338
1498
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -1415,160 +1575,6 @@ var Lits = (function (exports) {
|
|
|
1415
1575
|
},
|
|
1416
1576
|
paramCount: { min: 2 },
|
|
1417
1577
|
},
|
|
1418
|
-
'reductions': {
|
|
1419
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1420
|
-
var executeFunction = _a.executeFunction;
|
|
1421
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1422
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1423
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1424
|
-
if (params.length === 2) {
|
|
1425
|
-
if (seq.length === 0)
|
|
1426
|
-
return [executeFunction(fn, [], contextStack, sourceCodeInfo)];
|
|
1427
|
-
else if (seq.length === 1)
|
|
1428
|
-
return [toAny(seq[0])];
|
|
1429
|
-
if (typeof seq === 'string') {
|
|
1430
|
-
var chars = seq.split('');
|
|
1431
|
-
var resultArray_1 = [asAny(chars[0], sourceCodeInfo)];
|
|
1432
|
-
chars.slice(1).reduce(function (result, elem) {
|
|
1433
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1434
|
-
resultArray_1.push(newVal);
|
|
1435
|
-
return newVal;
|
|
1436
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1437
|
-
return resultArray_1;
|
|
1438
|
-
}
|
|
1439
|
-
else {
|
|
1440
|
-
var resultArray_2 = [toAny(seq[0])];
|
|
1441
|
-
seq.slice(1).reduce(function (result, elem) {
|
|
1442
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1443
|
-
resultArray_2.push(newVal);
|
|
1444
|
-
return newVal;
|
|
1445
|
-
}, toAny(seq[0]));
|
|
1446
|
-
return resultArray_2;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
else {
|
|
1450
|
-
var val = params[2];
|
|
1451
|
-
assertAny(val, sourceCodeInfo);
|
|
1452
|
-
if (typeof seq === 'string') {
|
|
1453
|
-
assertString(val, sourceCodeInfo);
|
|
1454
|
-
if (seq.length === 0)
|
|
1455
|
-
return [val];
|
|
1456
|
-
var resultArray_3 = [val];
|
|
1457
|
-
seq.split('').reduce(function (result, elem) {
|
|
1458
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1459
|
-
resultArray_3.push(newVal);
|
|
1460
|
-
return newVal;
|
|
1461
|
-
}, val);
|
|
1462
|
-
return resultArray_3;
|
|
1463
|
-
}
|
|
1464
|
-
else {
|
|
1465
|
-
if (seq.length === 0)
|
|
1466
|
-
return [val];
|
|
1467
|
-
var resultArray_4 = [val];
|
|
1468
|
-
seq.reduce(function (result, elem) {
|
|
1469
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1470
|
-
resultArray_4.push(newVal);
|
|
1471
|
-
return newVal;
|
|
1472
|
-
}, val);
|
|
1473
|
-
return resultArray_4;
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
},
|
|
1477
|
-
paramCount: { min: 2, max: 3 },
|
|
1478
|
-
},
|
|
1479
|
-
'reduce': {
|
|
1480
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1481
|
-
var executeFunction = _a.executeFunction;
|
|
1482
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1483
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1484
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1485
|
-
if (params.length === 2) {
|
|
1486
|
-
if (seq.length === 0)
|
|
1487
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1488
|
-
else if (seq.length === 1)
|
|
1489
|
-
return toAny(seq[0]);
|
|
1490
|
-
if (typeof seq === 'string') {
|
|
1491
|
-
var chars = seq.split('');
|
|
1492
|
-
return chars.slice(1).reduce(function (result, elem) {
|
|
1493
|
-
var val = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1494
|
-
return val;
|
|
1495
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1496
|
-
}
|
|
1497
|
-
else {
|
|
1498
|
-
return seq.slice(1).reduce(function (result, elem) {
|
|
1499
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1500
|
-
}, toAny(seq[0]));
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
else {
|
|
1504
|
-
var val = params[2];
|
|
1505
|
-
assertAny(val, sourceCodeInfo);
|
|
1506
|
-
if (typeof seq === 'string') {
|
|
1507
|
-
assertString(val, sourceCodeInfo);
|
|
1508
|
-
if (seq.length === 0)
|
|
1509
|
-
return val;
|
|
1510
|
-
return seq.split('').reduce(function (result, elem) {
|
|
1511
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1512
|
-
}, val);
|
|
1513
|
-
}
|
|
1514
|
-
else {
|
|
1515
|
-
if (seq.length === 0)
|
|
1516
|
-
return val;
|
|
1517
|
-
return seq.reduce(function (result, elem) {
|
|
1518
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1519
|
-
}, val);
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
},
|
|
1523
|
-
paramCount: { min: 2, max: 3 },
|
|
1524
|
-
},
|
|
1525
|
-
'reduce-right': {
|
|
1526
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1527
|
-
var executeFunction = _a.executeFunction;
|
|
1528
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1529
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1530
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1531
|
-
if (params.length === 2) {
|
|
1532
|
-
if (seq.length === 0)
|
|
1533
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1534
|
-
else if (seq.length === 1)
|
|
1535
|
-
return toAny(seq[0]);
|
|
1536
|
-
if (typeof seq === 'string') {
|
|
1537
|
-
var chars = seq.split('');
|
|
1538
|
-
return chars.slice(0, chars.length - 1).reduceRight(function (result, elem) {
|
|
1539
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1540
|
-
assertString(newVal, sourceCodeInfo);
|
|
1541
|
-
return newVal;
|
|
1542
|
-
}, chars[chars.length - 1]);
|
|
1543
|
-
}
|
|
1544
|
-
else {
|
|
1545
|
-
return seq.slice(0, seq.length - 1).reduceRight(function (result, elem) {
|
|
1546
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1547
|
-
}, asAny(seq[seq.length - 1], sourceCodeInfo));
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
else {
|
|
1551
|
-
var val = params[2];
|
|
1552
|
-
assertAny(val, sourceCodeInfo);
|
|
1553
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1554
|
-
if (typeof seq === 'string') {
|
|
1555
|
-
if (seq.length === 0)
|
|
1556
|
-
return val;
|
|
1557
|
-
return seq.split('').reduceRight(function (result, elem) {
|
|
1558
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1559
|
-
}, val);
|
|
1560
|
-
}
|
|
1561
|
-
else {
|
|
1562
|
-
if (seq.length === 0)
|
|
1563
|
-
return val;
|
|
1564
|
-
return seq.reduceRight(function (result, elem) {
|
|
1565
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1566
|
-
}, val);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
},
|
|
1570
|
-
paramCount: { min: 2, max: 3 },
|
|
1571
|
-
},
|
|
1572
1578
|
'rest': {
|
|
1573
1579
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1574
1580
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -1887,7 +1893,7 @@ var Lits = (function (exports) {
|
|
|
1887
1893
|
assertSeq(input, sourceCodeInfo);
|
|
1888
1894
|
if (Array.isArray(input)) {
|
|
1889
1895
|
var result = [];
|
|
1890
|
-
var
|
|
1896
|
+
var _loop_1 = function (item) {
|
|
1891
1897
|
assertAny(item, sourceCodeInfo);
|
|
1892
1898
|
if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
|
|
1893
1899
|
result.push(item);
|
|
@@ -1896,7 +1902,7 @@ var Lits = (function (exports) {
|
|
|
1896
1902
|
try {
|
|
1897
1903
|
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
1898
1904
|
var item = input_1_1.value;
|
|
1899
|
-
|
|
1905
|
+
_loop_1(item);
|
|
1900
1906
|
}
|
|
1901
1907
|
}
|
|
1902
1908
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -3882,6 +3888,13 @@ var Lits = (function (exports) {
|
|
|
3882
3888
|
assertString(sourceArg, sourceCodeInfo);
|
|
3883
3889
|
var source = sourceArg || '(?:)';
|
|
3884
3890
|
var flags = typeof flagsArg === 'string' ? flagsArg : '';
|
|
3891
|
+
try {
|
|
3892
|
+
// eslint-disable-next-line no-new
|
|
3893
|
+
new RegExp(source, flags); // Throws if invalid regexp
|
|
3894
|
+
}
|
|
3895
|
+
catch (e) {
|
|
3896
|
+
throw new LitsError("Invalid regular expression: ".concat(source, " ").concat(flags), sourceCodeInfo);
|
|
3897
|
+
}
|
|
3885
3898
|
return _b = {},
|
|
3886
3899
|
_b[REGEXP_SYMBOL] = true,
|
|
3887
3900
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
@@ -4200,6 +4213,15 @@ var Lits = (function (exports) {
|
|
|
4200
4213
|
}
|
|
4201
4214
|
|
|
4202
4215
|
var functionalNormalExpression = {
|
|
4216
|
+
'|>': {
|
|
4217
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4218
|
+
var _c = __read(_a, 2), value = _c[0], func = _c[1];
|
|
4219
|
+
var executeFunction = _b.executeFunction;
|
|
4220
|
+
assertFunctionLike(func, sourceCodeInfo);
|
|
4221
|
+
return executeFunction(func, [value], contextStack, sourceCodeInfo);
|
|
4222
|
+
},
|
|
4223
|
+
paramCount: 2,
|
|
4224
|
+
},
|
|
4203
4225
|
'apply': {
|
|
4204
4226
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4205
4227
|
var _c = __read(_a), func = _c[0], params = _c.slice(1);
|
|
@@ -4220,20 +4242,6 @@ var Lits = (function (exports) {
|
|
|
4220
4242
|
},
|
|
4221
4243
|
paramCount: 1,
|
|
4222
4244
|
},
|
|
4223
|
-
'partial': {
|
|
4224
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
4225
|
-
var _b;
|
|
4226
|
-
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
4227
|
-
return _b = {},
|
|
4228
|
-
_b[FUNCTION_SYMBOL] = true,
|
|
4229
|
-
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4230
|
-
_b.functionType = 'Partial',
|
|
4231
|
-
_b.function = asFunctionLike(fn, sourceCodeInfo),
|
|
4232
|
-
_b.params = params,
|
|
4233
|
-
_b;
|
|
4234
|
-
},
|
|
4235
|
-
paramCount: { min: 1 },
|
|
4236
|
-
},
|
|
4237
4245
|
'comp': {
|
|
4238
4246
|
evaluate: function (params, sourceCodeInfo) {
|
|
4239
4247
|
var _a;
|
|
@@ -6993,10 +7001,10 @@ var Lits = (function (exports) {
|
|
|
6993
7001
|
assertVector(vectorA, sourceCodeInfo);
|
|
6994
7002
|
assertVector(vectorB, sourceCodeInfo);
|
|
6995
7003
|
if (vectorA.length < 2) {
|
|
6996
|
-
throw new
|
|
7004
|
+
throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
|
|
6997
7005
|
}
|
|
6998
7006
|
if (vectorA.length !== vectorB.length) {
|
|
6999
|
-
throw new
|
|
7007
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
7000
7008
|
}
|
|
7001
7009
|
assertNumber(lag, sourceCodeInfo, {
|
|
7002
7010
|
integer: true,
|
|
@@ -8248,7 +8256,7 @@ var Lits = (function (exports) {
|
|
|
8248
8256
|
if (n === 0)
|
|
8249
8257
|
return 1;
|
|
8250
8258
|
if (n > partitionNumbers.length) {
|
|
8251
|
-
throw new
|
|
8259
|
+
throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
|
|
8252
8260
|
}
|
|
8253
8261
|
return partitionNumbers[n - 1];
|
|
8254
8262
|
},
|
|
@@ -10387,7 +10395,12 @@ var Lits = (function (exports) {
|
|
|
10387
10395
|
var _b = __read(_a, 2), a = _b[0], m = _b[1];
|
|
10388
10396
|
assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
|
|
10389
10397
|
assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
|
|
10390
|
-
|
|
10398
|
+
try {
|
|
10399
|
+
return modInverse(a, m);
|
|
10400
|
+
}
|
|
10401
|
+
catch (error) {
|
|
10402
|
+
throw new LitsError(error, sourceCodeInfo);
|
|
10403
|
+
}
|
|
10391
10404
|
},
|
|
10392
10405
|
paramCount: 2,
|
|
10393
10406
|
},
|
|
@@ -10406,7 +10419,7 @@ var Lits = (function (exports) {
|
|
|
10406
10419
|
assertVector(remainders, sourceCodeInfo);
|
|
10407
10420
|
assertVector(moduli, sourceCodeInfo);
|
|
10408
10421
|
if (remainders.length !== moduli.length) {
|
|
10409
|
-
throw new
|
|
10422
|
+
throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
|
|
10410
10423
|
}
|
|
10411
10424
|
try {
|
|
10412
10425
|
return chineseRemainder(remainders, moduli);
|
|
@@ -11200,6 +11213,7 @@ var Lits = (function (exports) {
|
|
|
11200
11213
|
function: null,
|
|
11201
11214
|
export: null,
|
|
11202
11215
|
as: null,
|
|
11216
|
+
_: null,
|
|
11203
11217
|
};
|
|
11204
11218
|
var phi = (1 + Math.sqrt(5)) / 2;
|
|
11205
11219
|
var numberReservedSymbolRecord = {
|
|
@@ -11914,7 +11928,11 @@ var Lits = (function (exports) {
|
|
|
11914
11928
|
}
|
|
11915
11929
|
else {
|
|
11916
11930
|
var key = evaluateNode(keyNode, contextStack);
|
|
11917
|
-
var
|
|
11931
|
+
var valueNode = params[i + 1];
|
|
11932
|
+
if (valueNode === undefined) {
|
|
11933
|
+
throw new LitsError('Missing value for key', keyNode[2]);
|
|
11934
|
+
}
|
|
11935
|
+
var value = evaluateNode(valueNode, contextStack);
|
|
11918
11936
|
assertString(key, keyNode[2]);
|
|
11919
11937
|
result[key] = value;
|
|
11920
11938
|
}
|
|
@@ -12164,8 +12182,27 @@ var Lits = (function (exports) {
|
|
|
12164
12182
|
}
|
|
12165
12183
|
},
|
|
12166
12184
|
Partial: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12185
|
+
var e_2, _b;
|
|
12167
12186
|
var executeFunction = _a.executeFunction;
|
|
12168
|
-
|
|
12187
|
+
var actualParams = __spreadArray([], __read(fn.params), false);
|
|
12188
|
+
if (params.length !== fn.placeholders.length) {
|
|
12189
|
+
throw new LitsError("(partial) expects ".concat(fn.placeholders.length, " arguments, got ").concat(params.length, "."), sourceCodeInfo);
|
|
12190
|
+
}
|
|
12191
|
+
var paramsCopy = __spreadArray([], __read(params), false);
|
|
12192
|
+
try {
|
|
12193
|
+
for (var _c = __values(fn.placeholders), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
12194
|
+
var placeholderIndex = _d.value;
|
|
12195
|
+
actualParams.splice(placeholderIndex, 0, paramsCopy.shift());
|
|
12196
|
+
}
|
|
12197
|
+
}
|
|
12198
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
12199
|
+
finally {
|
|
12200
|
+
try {
|
|
12201
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
12202
|
+
}
|
|
12203
|
+
finally { if (e_2) throw e_2.error; }
|
|
12204
|
+
}
|
|
12205
|
+
return executeFunction(fn.function, actualParams, contextStack, sourceCodeInfo);
|
|
12169
12206
|
},
|
|
12170
12207
|
Comp: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12171
12208
|
var executeFunction = _a.executeFunction;
|
|
@@ -12191,66 +12228,66 @@ var Lits = (function (exports) {
|
|
|
12191
12228
|
return !executeFunction(fn.function, params, contextStack, sourceCodeInfo);
|
|
12192
12229
|
},
|
|
12193
12230
|
EveryPred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12194
|
-
var
|
|
12231
|
+
var e_3, _b, e_4, _c;
|
|
12195
12232
|
var executeFunction = _a.executeFunction;
|
|
12196
12233
|
try {
|
|
12197
12234
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12198
12235
|
var f = _e.value;
|
|
12199
12236
|
try {
|
|
12200
|
-
for (var params_1 = (
|
|
12237
|
+
for (var params_1 = (e_4 = void 0, __values(params)), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
12201
12238
|
var param = params_1_1.value;
|
|
12202
12239
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12203
12240
|
if (!result)
|
|
12204
12241
|
return false;
|
|
12205
12242
|
}
|
|
12206
12243
|
}
|
|
12207
|
-
catch (
|
|
12244
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
12208
12245
|
finally {
|
|
12209
12246
|
try {
|
|
12210
12247
|
if (params_1_1 && !params_1_1.done && (_c = params_1.return)) _c.call(params_1);
|
|
12211
12248
|
}
|
|
12212
|
-
finally { if (
|
|
12249
|
+
finally { if (e_4) throw e_4.error; }
|
|
12213
12250
|
}
|
|
12214
12251
|
}
|
|
12215
12252
|
}
|
|
12216
|
-
catch (
|
|
12253
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
12217
12254
|
finally {
|
|
12218
12255
|
try {
|
|
12219
12256
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12220
12257
|
}
|
|
12221
|
-
finally { if (
|
|
12258
|
+
finally { if (e_3) throw e_3.error; }
|
|
12222
12259
|
}
|
|
12223
12260
|
return true;
|
|
12224
12261
|
},
|
|
12225
12262
|
SomePred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12226
|
-
var
|
|
12263
|
+
var e_5, _b, e_6, _c;
|
|
12227
12264
|
var executeFunction = _a.executeFunction;
|
|
12228
12265
|
try {
|
|
12229
12266
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12230
12267
|
var f = _e.value;
|
|
12231
12268
|
try {
|
|
12232
|
-
for (var params_2 = (
|
|
12269
|
+
for (var params_2 = (e_6 = void 0, __values(params)), params_2_1 = params_2.next(); !params_2_1.done; params_2_1 = params_2.next()) {
|
|
12233
12270
|
var param = params_2_1.value;
|
|
12234
12271
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12235
12272
|
if (result)
|
|
12236
12273
|
return true;
|
|
12237
12274
|
}
|
|
12238
12275
|
}
|
|
12239
|
-
catch (
|
|
12276
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
12240
12277
|
finally {
|
|
12241
12278
|
try {
|
|
12242
12279
|
if (params_2_1 && !params_2_1.done && (_c = params_2.return)) _c.call(params_2);
|
|
12243
12280
|
}
|
|
12244
|
-
finally { if (
|
|
12281
|
+
finally { if (e_6) throw e_6.error; }
|
|
12245
12282
|
}
|
|
12246
12283
|
}
|
|
12247
12284
|
}
|
|
12248
|
-
catch (
|
|
12285
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
12249
12286
|
finally {
|
|
12250
12287
|
try {
|
|
12251
12288
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12252
12289
|
}
|
|
12253
|
-
finally { if (
|
|
12290
|
+
finally { if (e_5) throw e_5.error; }
|
|
12254
12291
|
}
|
|
12255
12292
|
return false;
|
|
12256
12293
|
},
|
|
@@ -12323,6 +12360,9 @@ var Lits = (function (exports) {
|
|
|
12323
12360
|
}
|
|
12324
12361
|
function evaluateReservedSymbol(node) {
|
|
12325
12362
|
var reservedName = node[1];
|
|
12363
|
+
if (!['true', 'false', 'null'].includes(reservedName)) {
|
|
12364
|
+
throw new LitsError("Reserved symbol ".concat(reservedName, " cannot be evaluated"), node[2]);
|
|
12365
|
+
}
|
|
12326
12366
|
var value = reservedSymbolRecord[reservedName];
|
|
12327
12367
|
return asNonUndefined(value, node[2]);
|
|
12328
12368
|
}
|
|
@@ -12330,7 +12370,8 @@ var Lits = (function (exports) {
|
|
|
12330
12370
|
var sourceCodeInfo = node[2];
|
|
12331
12371
|
var paramNodes = node[1][1];
|
|
12332
12372
|
var params = [];
|
|
12333
|
-
|
|
12373
|
+
var placeholders = [];
|
|
12374
|
+
paramNodes.forEach(function (paramNode, index) {
|
|
12334
12375
|
if (isSpreadNode(paramNode)) {
|
|
12335
12376
|
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
12336
12377
|
if (Array.isArray(spreadValue)) {
|
|
@@ -12340,12 +12381,27 @@ var Lits = (function (exports) {
|
|
|
12340
12381
|
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
12341
12382
|
}
|
|
12342
12383
|
}
|
|
12384
|
+
else if (paramNode[0] === NodeTypes.ReservedSymbol && paramNode[1] === '_') {
|
|
12385
|
+
placeholders.push(index);
|
|
12386
|
+
}
|
|
12343
12387
|
else {
|
|
12344
12388
|
params.push(evaluateNode(paramNode, contextStack));
|
|
12345
12389
|
}
|
|
12346
12390
|
});
|
|
12347
12391
|
if (isNormalExpressionNodeWithName(node)) {
|
|
12348
12392
|
var nameSymbol = node[1][0];
|
|
12393
|
+
if (placeholders.length > 0) {
|
|
12394
|
+
var fn = evaluateNode(nameSymbol, contextStack);
|
|
12395
|
+
var partialFunction = {
|
|
12396
|
+
'^^fn^^': true,
|
|
12397
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12398
|
+
'functionType': 'Partial',
|
|
12399
|
+
params: params,
|
|
12400
|
+
placeholders: placeholders,
|
|
12401
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12402
|
+
};
|
|
12403
|
+
return partialFunction;
|
|
12404
|
+
}
|
|
12349
12405
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
12350
12406
|
var type = nameSymbol[1];
|
|
12351
12407
|
var normalExpression = builtin.allNormalExpressions[type];
|
|
@@ -12362,6 +12418,17 @@ var Lits = (function (exports) {
|
|
|
12362
12418
|
else {
|
|
12363
12419
|
var fnNode = node[1][0];
|
|
12364
12420
|
var fn = asFunctionLike(evaluateNode(fnNode, contextStack), sourceCodeInfo);
|
|
12421
|
+
if (placeholders.length > 0) {
|
|
12422
|
+
var partialFunction = {
|
|
12423
|
+
'^^fn^^': true,
|
|
12424
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12425
|
+
'functionType': 'Partial',
|
|
12426
|
+
params: params,
|
|
12427
|
+
placeholders: placeholders,
|
|
12428
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12429
|
+
};
|
|
12430
|
+
return partialFunction;
|
|
12431
|
+
}
|
|
12365
12432
|
return executeFunction(fn, params, contextStack, sourceCodeInfo);
|
|
12366
12433
|
}
|
|
12367
12434
|
}
|
|
@@ -12667,6 +12734,7 @@ var Lits = (function (exports) {
|
|
|
12667
12734
|
'&&', // logical AND
|
|
12668
12735
|
'||', // logical OR
|
|
12669
12736
|
'??', // nullish coalescing
|
|
12737
|
+
'|>', // pipe
|
|
12670
12738
|
];
|
|
12671
12739
|
var otherOperators = [
|
|
12672
12740
|
'->', // lambda
|
|
@@ -12845,21 +12913,30 @@ var Lits = (function (exports) {
|
|
|
12845
12913
|
var char = input[i];
|
|
12846
12914
|
if (char === '_') {
|
|
12847
12915
|
if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
|
|
12848
|
-
|
|
12916
|
+
if (i === start) {
|
|
12917
|
+
return NO_MATCH;
|
|
12918
|
+
}
|
|
12919
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12849
12920
|
}
|
|
12850
12921
|
}
|
|
12851
12922
|
else if (char === '.') {
|
|
12852
|
-
if (i === start
|
|
12923
|
+
if (i === start) {
|
|
12853
12924
|
return NO_MATCH;
|
|
12854
12925
|
}
|
|
12926
|
+
if (hasDecimalPoint || hasExponent) {
|
|
12927
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12928
|
+
}
|
|
12855
12929
|
hasDecimalPoint = true;
|
|
12856
12930
|
}
|
|
12857
12931
|
else if (char === 'e' || char === 'E') {
|
|
12858
|
-
if (i === start
|
|
12932
|
+
if (i === start) {
|
|
12859
12933
|
return NO_MATCH;
|
|
12860
12934
|
}
|
|
12935
|
+
if (hasExponent) {
|
|
12936
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12937
|
+
}
|
|
12861
12938
|
if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
|
|
12862
|
-
|
|
12939
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12863
12940
|
}
|
|
12864
12941
|
if (input[i + 1] === '+' || input[i + 1] === '-') {
|
|
12865
12942
|
i += 1;
|
|
@@ -12879,7 +12956,7 @@ var Lits = (function (exports) {
|
|
|
12879
12956
|
}
|
|
12880
12957
|
var nextChar = input[i];
|
|
12881
12958
|
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
12882
|
-
|
|
12959
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12883
12960
|
}
|
|
12884
12961
|
return [length, ['Number', input.substring(position, i)]];
|
|
12885
12962
|
};
|
|
@@ -13045,10 +13122,10 @@ var Lits = (function (exports) {
|
|
|
13045
13122
|
hasDebugData: debug,
|
|
13046
13123
|
};
|
|
13047
13124
|
while (position < input.length) {
|
|
13048
|
-
var tokenDescriptor = getCurrentToken(input, position);
|
|
13049
13125
|
var sourceCodeInfo = debug
|
|
13050
13126
|
? createSourceCodeInfo(input, position, filePath)
|
|
13051
13127
|
: undefined;
|
|
13128
|
+
var tokenDescriptor = getCurrentToken(input, position);
|
|
13052
13129
|
if (!tokenDescriptor) {
|
|
13053
13130
|
throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
|
|
13054
13131
|
}
|
|
@@ -13158,9 +13235,6 @@ var Lits = (function (exports) {
|
|
|
13158
13235
|
}
|
|
13159
13236
|
function assertOperatorToken(token, operatorName) {
|
|
13160
13237
|
if (!isOperatorToken(token, operatorName)) {
|
|
13161
|
-
if (operatorName) {
|
|
13162
|
-
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
|
|
13163
|
-
}
|
|
13164
13238
|
throwUnexpectedToken('Operator', operatorName, token);
|
|
13165
13239
|
}
|
|
13166
13240
|
}
|
|
@@ -13230,8 +13304,8 @@ var Lits = (function (exports) {
|
|
|
13230
13304
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
|
|
13231
13305
|
}
|
|
13232
13306
|
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
13233
|
-
var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
|
|
13234
|
-
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual[2]);
|
|
13307
|
+
var actualOutput = actual ? "".concat(actual[0], " '").concat(actual[1], "'") : 'end of input';
|
|
13308
|
+
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual === null || actual === void 0 ? void 0 : actual[2]);
|
|
13235
13309
|
}
|
|
13236
13310
|
|
|
13237
13311
|
function minifyTokenStream(tokenStream, _a) {
|
|
@@ -13260,8 +13334,8 @@ var Lits = (function (exports) {
|
|
|
13260
13334
|
}, '');
|
|
13261
13335
|
}
|
|
13262
13336
|
|
|
13263
|
-
var exponentiationPrecedence =
|
|
13264
|
-
var binaryFunctionalOperatorPrecedence =
|
|
13337
|
+
var exponentiationPrecedence = 11;
|
|
13338
|
+
var binaryFunctionalOperatorPrecedence = 2;
|
|
13265
13339
|
var placeholderRegexp = /^\$([1-9]\d?)?$/;
|
|
13266
13340
|
function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
13267
13341
|
if (sourceCodeInfo) {
|
|
@@ -13276,38 +13350,40 @@ var Lits = (function (exports) {
|
|
|
13276
13350
|
case '*': // multiplication
|
|
13277
13351
|
case '/': // division
|
|
13278
13352
|
case '%': // remainder
|
|
13279
|
-
return
|
|
13353
|
+
return 10;
|
|
13280
13354
|
case '+': // addition
|
|
13281
13355
|
case '-': // subtraction
|
|
13282
|
-
return
|
|
13356
|
+
return 9;
|
|
13283
13357
|
case '<<': // left shift
|
|
13284
13358
|
case '>>': // signed right shift
|
|
13285
13359
|
case '>>>': // unsigned right shift
|
|
13286
|
-
return
|
|
13360
|
+
return 8;
|
|
13287
13361
|
case '++': // string concatenation
|
|
13288
|
-
return
|
|
13362
|
+
return 7;
|
|
13289
13363
|
case '<': // less than
|
|
13290
13364
|
case '<=': // less than or equal
|
|
13291
13365
|
case '≤': // less than or equal
|
|
13292
13366
|
case '>': // greater than
|
|
13293
13367
|
case '>=': // greater than or equal
|
|
13294
13368
|
case '≥': // greater than or equal
|
|
13295
|
-
return
|
|
13369
|
+
return 6;
|
|
13296
13370
|
case '=': // equal
|
|
13297
13371
|
case '!=': // not equal
|
|
13298
13372
|
case '≠': // not equal
|
|
13299
13373
|
case '~': // approximate
|
|
13300
13374
|
case '≈': // approximate
|
|
13301
|
-
return
|
|
13375
|
+
return 5;
|
|
13302
13376
|
case '&': // bitwise AND
|
|
13303
13377
|
case 'xor': // bitwise XOR
|
|
13304
13378
|
case '|': // bitwise OR
|
|
13305
|
-
return
|
|
13379
|
+
return 4;
|
|
13306
13380
|
case '&&': // logical AND
|
|
13307
13381
|
case '||': // logical OR
|
|
13308
13382
|
case '??': // nullish coalescing
|
|
13309
|
-
return
|
|
13310
|
-
|
|
13383
|
+
return 3;
|
|
13384
|
+
case '|>': // pipe
|
|
13385
|
+
return 1;
|
|
13386
|
+
// leave room for binaryFunctionalOperatorPrecedence = 2
|
|
13311
13387
|
/* v8 ignore next 2 */
|
|
13312
13388
|
default:
|
|
13313
13389
|
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
@@ -13351,6 +13427,7 @@ var Lits = (function (exports) {
|
|
|
13351
13427
|
case '|':
|
|
13352
13428
|
case '~':
|
|
13353
13429
|
case '≈':
|
|
13430
|
+
case '|>':
|
|
13354
13431
|
return createNamedNormalExpressionNode(symbolNode, [left, right], sourceCodeInfo);
|
|
13355
13432
|
case '&&':
|
|
13356
13433
|
case '||':
|
|
@@ -13376,6 +13453,11 @@ var Lits = (function (exports) {
|
|
|
13376
13453
|
Parser.prototype.peek = function () {
|
|
13377
13454
|
return this.tokenStream.tokens[this.parseState.position];
|
|
13378
13455
|
};
|
|
13456
|
+
Parser.prototype.peekSourceCodeInfo = function () {
|
|
13457
|
+
var _a;
|
|
13458
|
+
var currentToken = this.peek();
|
|
13459
|
+
return currentToken ? currentToken[2] : (_a = this.tokenStream.tokens.at(-1)) === null || _a === void 0 ? void 0 : _a[2];
|
|
13460
|
+
};
|
|
13379
13461
|
Parser.prototype.peekAhead = function (count) {
|
|
13380
13462
|
return this.tokenStream.tokens[this.parseState.position + count];
|
|
13381
13463
|
};
|
|
@@ -13391,7 +13473,7 @@ var Lits = (function (exports) {
|
|
|
13391
13473
|
}
|
|
13392
13474
|
else {
|
|
13393
13475
|
if (!this.isAtEnd()) {
|
|
13394
|
-
throw new LitsError('Expected ;', this.
|
|
13476
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13395
13477
|
}
|
|
13396
13478
|
}
|
|
13397
13479
|
}
|
|
@@ -13480,15 +13562,21 @@ var Lits = (function (exports) {
|
|
|
13480
13562
|
}
|
|
13481
13563
|
return left;
|
|
13482
13564
|
};
|
|
13565
|
+
Parser.prototype.asToken = function (token) {
|
|
13566
|
+
if (!token) {
|
|
13567
|
+
throw new LitsError('Unexpected end of input', this.peekSourceCodeInfo());
|
|
13568
|
+
}
|
|
13569
|
+
return token;
|
|
13570
|
+
};
|
|
13483
13571
|
Parser.prototype.parseOperand = function () {
|
|
13484
13572
|
var operand = this.parseOperandPart();
|
|
13485
13573
|
var token = this.peek();
|
|
13486
13574
|
while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
13487
13575
|
if (token[1] === '.') {
|
|
13488
13576
|
this.advance();
|
|
13489
|
-
var symbolToken = this.peek();
|
|
13577
|
+
var symbolToken = this.asToken(this.peek());
|
|
13490
13578
|
if (!isSymbolToken(symbolToken)) {
|
|
13491
|
-
throw new LitsError('Expected symbol', this.
|
|
13579
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13492
13580
|
}
|
|
13493
13581
|
var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
|
|
13494
13582
|
operand = createAccessorNode(operand, stringNode, token[2]);
|
|
@@ -13499,7 +13587,7 @@ var Lits = (function (exports) {
|
|
|
13499
13587
|
this.advance();
|
|
13500
13588
|
var expression = this.parseExpression();
|
|
13501
13589
|
if (!isRBracketToken(this.peek())) {
|
|
13502
|
-
throw new LitsError('Expected closing bracket', this.
|
|
13590
|
+
throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
|
|
13503
13591
|
}
|
|
13504
13592
|
operand = createAccessorNode(operand, expression, token[2]);
|
|
13505
13593
|
this.advance();
|
|
@@ -13513,7 +13601,7 @@ var Lits = (function (exports) {
|
|
|
13513
13601
|
return operand;
|
|
13514
13602
|
};
|
|
13515
13603
|
Parser.prototype.parseOperandPart = function () {
|
|
13516
|
-
var token = this.peek();
|
|
13604
|
+
var token = this.asToken(this.peek());
|
|
13517
13605
|
// Parentheses
|
|
13518
13606
|
if (isLParenToken(token)) {
|
|
13519
13607
|
var positionBefore = this.parseState.position;
|
|
@@ -13525,7 +13613,7 @@ var Lits = (function (exports) {
|
|
|
13525
13613
|
this.advance();
|
|
13526
13614
|
var expression = this.parseExpression();
|
|
13527
13615
|
if (!isRParenToken(this.peek())) {
|
|
13528
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13616
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13529
13617
|
}
|
|
13530
13618
|
this.advance();
|
|
13531
13619
|
return expression;
|
|
@@ -13585,7 +13673,7 @@ var Lits = (function (exports) {
|
|
|
13585
13673
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
13586
13674
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13587
13675
|
this.advance();
|
|
13588
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13676
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13589
13677
|
}
|
|
13590
13678
|
else {
|
|
13591
13679
|
var token = this.peek();
|
|
@@ -13601,7 +13689,7 @@ var Lits = (function (exports) {
|
|
|
13601
13689
|
this.advance();
|
|
13602
13690
|
}
|
|
13603
13691
|
else {
|
|
13604
|
-
throw new LitsError('Expected key to be a symbol or a string', this.
|
|
13692
|
+
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
13605
13693
|
}
|
|
13606
13694
|
assertOperatorToken(this.peek(), ':=');
|
|
13607
13695
|
this.advance();
|
|
@@ -13609,7 +13697,7 @@ var Lits = (function (exports) {
|
|
|
13609
13697
|
}
|
|
13610
13698
|
var nextToken = this.peek();
|
|
13611
13699
|
if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
13612
|
-
throw new LitsError('Expected comma or closing brace', this.
|
|
13700
|
+
throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
|
|
13613
13701
|
}
|
|
13614
13702
|
if (isOperatorToken(nextToken, ',')) {
|
|
13615
13703
|
this.advance();
|
|
@@ -13626,14 +13714,14 @@ var Lits = (function (exports) {
|
|
|
13626
13714
|
while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
|
|
13627
13715
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13628
13716
|
this.advance();
|
|
13629
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13717
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13630
13718
|
}
|
|
13631
13719
|
else {
|
|
13632
13720
|
params.push(this.parseExpression());
|
|
13633
13721
|
}
|
|
13634
13722
|
var nextToken = this.peek();
|
|
13635
13723
|
if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
|
|
13636
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13724
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13637
13725
|
}
|
|
13638
13726
|
if (isOperatorToken(nextToken, ',')) {
|
|
13639
13727
|
this.advance();
|
|
@@ -13644,26 +13732,27 @@ var Lits = (function (exports) {
|
|
|
13644
13732
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
|
|
13645
13733
|
};
|
|
13646
13734
|
Parser.prototype.parseFunctionCall = function (symbol) {
|
|
13735
|
+
var _a;
|
|
13647
13736
|
this.advance();
|
|
13648
13737
|
var params = [];
|
|
13649
13738
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
13650
13739
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13651
13740
|
this.advance();
|
|
13652
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13741
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13653
13742
|
}
|
|
13654
13743
|
else {
|
|
13655
13744
|
params.push(this.parseExpression());
|
|
13656
13745
|
}
|
|
13657
13746
|
var nextToken = this.peek();
|
|
13658
13747
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
13659
|
-
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
13748
|
+
throw new LitsError('Expected comma or closing parenthesis', (_a = this.peek()) === null || _a === void 0 ? void 0 : _a[2]);
|
|
13660
13749
|
}
|
|
13661
13750
|
if (isOperatorToken(nextToken, ',')) {
|
|
13662
13751
|
this.advance();
|
|
13663
13752
|
}
|
|
13664
13753
|
}
|
|
13665
13754
|
if (!isRParenToken(this.peek())) {
|
|
13666
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13755
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13667
13756
|
}
|
|
13668
13757
|
this.advance();
|
|
13669
13758
|
if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
|
|
@@ -13693,14 +13782,14 @@ var Lits = (function (exports) {
|
|
|
13693
13782
|
if (params.length !== 1) {
|
|
13694
13783
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13695
13784
|
}
|
|
13696
|
-
var
|
|
13785
|
+
var _b = __read(params, 1), param = _b[0];
|
|
13697
13786
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13698
13787
|
}
|
|
13699
13788
|
case specialExpressionTypes.throw: {
|
|
13700
13789
|
if (params.length !== 1) {
|
|
13701
13790
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13702
13791
|
}
|
|
13703
|
-
var
|
|
13792
|
+
var _c = __read(params, 1), param = _c[0];
|
|
13704
13793
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13705
13794
|
}
|
|
13706
13795
|
case specialExpressionTypes['0_fn']:
|
|
@@ -13720,7 +13809,7 @@ var Lits = (function (exports) {
|
|
|
13720
13809
|
}
|
|
13721
13810
|
};
|
|
13722
13811
|
Parser.prototype.parseLambdaFunction = function () {
|
|
13723
|
-
var firstToken = this.peek();
|
|
13812
|
+
var firstToken = this.asToken(this.peek());
|
|
13724
13813
|
if (isLParenToken(firstToken)
|
|
13725
13814
|
&& isSymbolToken(this.peekAhead(1))
|
|
13726
13815
|
&& isOperatorToken(this.peekAhead(2), '->')) {
|
|
@@ -13754,7 +13843,7 @@ var Lits = (function (exports) {
|
|
|
13754
13843
|
var functionArguments = [];
|
|
13755
13844
|
while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13756
13845
|
if (rest) {
|
|
13757
|
-
throw new LitsError('Rest argument must be last', this.
|
|
13846
|
+
throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
|
|
13758
13847
|
}
|
|
13759
13848
|
var bindingTarget = this.parseBindingTarget();
|
|
13760
13849
|
if (bindingTarget[1][1] !== undefined) {
|
|
@@ -13764,25 +13853,25 @@ var Lits = (function (exports) {
|
|
|
13764
13853
|
rest = true;
|
|
13765
13854
|
}
|
|
13766
13855
|
if (defaults && !bindingTarget[1][1]) {
|
|
13767
|
-
throw new LitsError('Default arguments must be last', this.
|
|
13856
|
+
throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
|
|
13768
13857
|
}
|
|
13769
13858
|
functionArguments.push(bindingTarget);
|
|
13770
13859
|
if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13771
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13860
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13772
13861
|
}
|
|
13773
13862
|
if (isOperatorToken(this.peek(), ',')) {
|
|
13774
13863
|
this.advance();
|
|
13775
13864
|
}
|
|
13776
13865
|
}
|
|
13777
13866
|
if (!isRParenToken(this.peek())) {
|
|
13778
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13867
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13779
13868
|
}
|
|
13780
13869
|
this.advance();
|
|
13781
13870
|
return functionArguments;
|
|
13782
13871
|
};
|
|
13783
13872
|
Parser.prototype.parseShorthandLamdaFunction = function () {
|
|
13784
13873
|
var _a;
|
|
13785
|
-
var firstToken = this.peek();
|
|
13874
|
+
var firstToken = this.asToken(this.peek());
|
|
13786
13875
|
this.advance();
|
|
13787
13876
|
var startPos = this.parseState.position;
|
|
13788
13877
|
var exprNode = this.parseExpression();
|
|
@@ -13840,7 +13929,7 @@ var Lits = (function (exports) {
|
|
|
13840
13929
|
}
|
|
13841
13930
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13842
13931
|
if (requireDefaultValue && !defaultValue) {
|
|
13843
|
-
throw new LitsError('Expected assignment', this.
|
|
13932
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13844
13933
|
}
|
|
13845
13934
|
return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
|
|
13846
13935
|
}
|
|
@@ -13852,7 +13941,7 @@ var Lits = (function (exports) {
|
|
|
13852
13941
|
this.advance();
|
|
13853
13942
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13854
13943
|
if (isOperatorToken(this.peek(), ':=')) {
|
|
13855
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13944
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13856
13945
|
}
|
|
13857
13946
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
13858
13947
|
}
|
|
@@ -13860,7 +13949,7 @@ var Lits = (function (exports) {
|
|
|
13860
13949
|
if (isLBracketToken(firstToken)) {
|
|
13861
13950
|
this.advance();
|
|
13862
13951
|
var elements = [];
|
|
13863
|
-
var token = this.peek();
|
|
13952
|
+
var token = this.asToken(this.peek());
|
|
13864
13953
|
var rest = false;
|
|
13865
13954
|
while (!isRBracketToken(token)) {
|
|
13866
13955
|
if (rest) {
|
|
@@ -13869,7 +13958,7 @@ var Lits = (function (exports) {
|
|
|
13869
13958
|
if (isOperatorToken(token, ',')) {
|
|
13870
13959
|
elements.push(null);
|
|
13871
13960
|
this.advance();
|
|
13872
|
-
token = this.peek();
|
|
13961
|
+
token = this.asToken(this.peek());
|
|
13873
13962
|
continue;
|
|
13874
13963
|
}
|
|
13875
13964
|
var target = this.parseBindingTarget();
|
|
@@ -13877,17 +13966,17 @@ var Lits = (function (exports) {
|
|
|
13877
13966
|
rest = true;
|
|
13878
13967
|
}
|
|
13879
13968
|
elements.push(target);
|
|
13880
|
-
token = this.peek();
|
|
13969
|
+
token = this.asToken(this.peek());
|
|
13881
13970
|
if (!isRBracketToken(token)) {
|
|
13882
13971
|
assertOperatorToken(token, ',');
|
|
13883
13972
|
this.advance();
|
|
13884
13973
|
}
|
|
13885
|
-
token = this.peek();
|
|
13974
|
+
token = this.asToken(this.peek());
|
|
13886
13975
|
}
|
|
13887
13976
|
this.advance();
|
|
13888
13977
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13889
13978
|
if (requireDefaultValue && !defaultValue) {
|
|
13890
|
-
throw new LitsError('Expected assignment', this.
|
|
13979
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13891
13980
|
}
|
|
13892
13981
|
return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
|
|
13893
13982
|
}
|
|
@@ -13895,7 +13984,7 @@ var Lits = (function (exports) {
|
|
|
13895
13984
|
if (isLBraceToken(firstToken)) {
|
|
13896
13985
|
this.advance();
|
|
13897
13986
|
var elements = {};
|
|
13898
|
-
var token = this.peek();
|
|
13987
|
+
var token = this.asToken(this.peek());
|
|
13899
13988
|
var rest = false;
|
|
13900
13989
|
while (!isRBraceToken(token)) {
|
|
13901
13990
|
if (rest) {
|
|
@@ -13906,7 +13995,7 @@ var Lits = (function (exports) {
|
|
|
13906
13995
|
this.advance();
|
|
13907
13996
|
}
|
|
13908
13997
|
var key = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13909
|
-
token = this.peek();
|
|
13998
|
+
token = this.asToken(this.peek());
|
|
13910
13999
|
if (isReservedSymbolToken(token, 'as')) {
|
|
13911
14000
|
if (rest) {
|
|
13912
14001
|
throw new LitsError('Rest argument can not have alias', token[2]);
|
|
@@ -13923,7 +14012,7 @@ var Lits = (function (exports) {
|
|
|
13923
14012
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
13924
14013
|
}
|
|
13925
14014
|
if (rest && isOperatorToken(this.peek(), ':=')) {
|
|
13926
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
14015
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13927
14016
|
}
|
|
13928
14017
|
elements[key[1]] = rest
|
|
13929
14018
|
? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
|
|
@@ -13936,17 +14025,17 @@ var Lits = (function (exports) {
|
|
|
13936
14025
|
assertOperatorToken(this.peek(), ',');
|
|
13937
14026
|
this.advance();
|
|
13938
14027
|
}
|
|
13939
|
-
token = this.peek();
|
|
14028
|
+
token = this.asToken(this.peek());
|
|
13940
14029
|
}
|
|
13941
14030
|
this.advance();
|
|
13942
|
-
token = this.peek();
|
|
14031
|
+
token = this.asToken(this.peek());
|
|
13943
14032
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13944
14033
|
if (requireDefaultValue && !defaultValue) {
|
|
13945
14034
|
throw new LitsError('Expected assignment', token[2]);
|
|
13946
14035
|
}
|
|
13947
14036
|
return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
|
|
13948
14037
|
}
|
|
13949
|
-
throw new LitsError('Expected symbol', this.
|
|
14038
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13950
14039
|
};
|
|
13951
14040
|
Parser.prototype.parseLet = function (token, optionalSemicolon) {
|
|
13952
14041
|
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
@@ -13969,7 +14058,7 @@ var Lits = (function (exports) {
|
|
|
13969
14058
|
this.advance();
|
|
13970
14059
|
}
|
|
13971
14060
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13972
|
-
throw new LitsError('Expected ;', this.
|
|
14061
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13973
14062
|
}
|
|
13974
14063
|
}
|
|
13975
14064
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -13993,7 +14082,7 @@ var Lits = (function (exports) {
|
|
|
13993
14082
|
token = this.peek();
|
|
13994
14083
|
}
|
|
13995
14084
|
if (bindingNodes.length === 0) {
|
|
13996
|
-
throw new LitsError('Expected binding', this.
|
|
14085
|
+
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
13997
14086
|
}
|
|
13998
14087
|
assertSymbolToken(token, 'do');
|
|
13999
14088
|
this.advance();
|
|
@@ -14004,7 +14093,7 @@ var Lits = (function (exports) {
|
|
|
14004
14093
|
this.advance();
|
|
14005
14094
|
}
|
|
14006
14095
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14007
|
-
throw new LitsError('Expected ;', this.
|
|
14096
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14008
14097
|
}
|
|
14009
14098
|
}
|
|
14010
14099
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14020,7 +14109,7 @@ var Lits = (function (exports) {
|
|
|
14020
14109
|
this.advance();
|
|
14021
14110
|
}
|
|
14022
14111
|
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14023
|
-
throw new LitsError('Expected ;', this.
|
|
14112
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14024
14113
|
}
|
|
14025
14114
|
}
|
|
14026
14115
|
var tryExpression = tryExpressions.length === 1
|
|
@@ -14042,7 +14131,7 @@ var Lits = (function (exports) {
|
|
|
14042
14131
|
this.advance();
|
|
14043
14132
|
}
|
|
14044
14133
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14045
|
-
throw new LitsError('Expected ;', this.
|
|
14134
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14046
14135
|
}
|
|
14047
14136
|
}
|
|
14048
14137
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14078,7 +14167,7 @@ var Lits = (function (exports) {
|
|
|
14078
14167
|
this.advance();
|
|
14079
14168
|
}
|
|
14080
14169
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14081
|
-
throw new LitsError('Expected ;', this.
|
|
14170
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14082
14171
|
}
|
|
14083
14172
|
}
|
|
14084
14173
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14092,13 +14181,13 @@ var Lits = (function (exports) {
|
|
|
14092
14181
|
this.advance();
|
|
14093
14182
|
var bindingNode = this.parseBinding();
|
|
14094
14183
|
var modifiers = [];
|
|
14095
|
-
var token = this.peek();
|
|
14184
|
+
var token = this.asToken(this.peek());
|
|
14096
14185
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14097
14186
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14098
14187
|
}
|
|
14099
14188
|
if (isOperatorToken(token, ',')) {
|
|
14100
14189
|
this.advance();
|
|
14101
|
-
token = this.peek();
|
|
14190
|
+
token = this.asToken(this.peek());
|
|
14102
14191
|
}
|
|
14103
14192
|
if (!isSymbolToken(token, 'let')
|
|
14104
14193
|
&& !isReservedSymbolToken(token, 'when')
|
|
@@ -14118,14 +14207,14 @@ var Lits = (function (exports) {
|
|
|
14118
14207
|
throw new LitsError('Duplicate binding', letNode[1][1][2]);
|
|
14119
14208
|
}
|
|
14120
14209
|
letBindings.push(letNode[1][1]);
|
|
14121
|
-
token = this_2.peek();
|
|
14210
|
+
token = this_2.asToken(this_2.peek());
|
|
14122
14211
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14123
14212
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14124
14213
|
}
|
|
14125
14214
|
if (isOperatorToken(token, ',')) {
|
|
14126
14215
|
this_2.advance();
|
|
14127
14216
|
}
|
|
14128
|
-
token = this_2.peek();
|
|
14217
|
+
token = this_2.asToken(this_2.peek());
|
|
14129
14218
|
};
|
|
14130
14219
|
var this_2 = this;
|
|
14131
14220
|
while (isSymbolToken(token, 'let')) {
|
|
@@ -14151,14 +14240,14 @@ var Lits = (function (exports) {
|
|
|
14151
14240
|
modifiers.push('&while');
|
|
14152
14241
|
whileNode = this.parseExpression();
|
|
14153
14242
|
}
|
|
14154
|
-
token = this.peek();
|
|
14243
|
+
token = this.asToken(this.peek());
|
|
14155
14244
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14156
14245
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14157
14246
|
}
|
|
14158
14247
|
if (isOperatorToken(token, ',')) {
|
|
14159
14248
|
this.advance();
|
|
14160
14249
|
}
|
|
14161
|
-
token = this.peek();
|
|
14250
|
+
token = this.asToken(this.peek());
|
|
14162
14251
|
}
|
|
14163
14252
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
|
|
14164
14253
|
throw new LitsError('Expected do or each', token[2]);
|
|
@@ -14195,7 +14284,7 @@ var Lits = (function (exports) {
|
|
|
14195
14284
|
this.advance();
|
|
14196
14285
|
}
|
|
14197
14286
|
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14198
|
-
throw new LitsError('Expected ;', this.
|
|
14287
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14199
14288
|
}
|
|
14200
14289
|
}
|
|
14201
14290
|
var thenExpression = thenExpressions.length === 1
|
|
@@ -14211,7 +14300,7 @@ var Lits = (function (exports) {
|
|
|
14211
14300
|
this.advance();
|
|
14212
14301
|
}
|
|
14213
14302
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14214
|
-
throw new LitsError('Expected ;', this.
|
|
14303
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14215
14304
|
}
|
|
14216
14305
|
}
|
|
14217
14306
|
elseExpression = elseExpressions.length === 1
|
|
@@ -14242,7 +14331,7 @@ var Lits = (function (exports) {
|
|
|
14242
14331
|
this.advance();
|
|
14243
14332
|
}
|
|
14244
14333
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14245
|
-
throw new LitsError('Expected ;', this.
|
|
14334
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14246
14335
|
}
|
|
14247
14336
|
}
|
|
14248
14337
|
var thenExpression = expressions.length === 1
|
|
@@ -14277,7 +14366,7 @@ var Lits = (function (exports) {
|
|
|
14277
14366
|
this.advance();
|
|
14278
14367
|
}
|
|
14279
14368
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14280
|
-
throw new LitsError('Expected ;', this.
|
|
14369
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14281
14370
|
}
|
|
14282
14371
|
}
|
|
14283
14372
|
var thenExpression = expressions.length === 1
|
|
@@ -14304,7 +14393,7 @@ var Lits = (function (exports) {
|
|
|
14304
14393
|
this.advance();
|
|
14305
14394
|
}
|
|
14306
14395
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14307
|
-
throw new LitsError('Expected ;', this.
|
|
14396
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14308
14397
|
}
|
|
14309
14398
|
}
|
|
14310
14399
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14348,7 +14437,7 @@ var Lits = (function (exports) {
|
|
|
14348
14437
|
this.advance();
|
|
14349
14438
|
}
|
|
14350
14439
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14351
|
-
throw new LitsError('Expected ;', this.
|
|
14440
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14352
14441
|
}
|
|
14353
14442
|
}
|
|
14354
14443
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14359,7 +14448,7 @@ var Lits = (function (exports) {
|
|
|
14359
14448
|
]]], token[2]);
|
|
14360
14449
|
}
|
|
14361
14450
|
else {
|
|
14362
|
-
throw new LitsError('Expected let or function', this.
|
|
14451
|
+
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|
|
14363
14452
|
}
|
|
14364
14453
|
};
|
|
14365
14454
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -14384,7 +14473,7 @@ var Lits = (function (exports) {
|
|
|
14384
14473
|
});
|
|
14385
14474
|
};
|
|
14386
14475
|
Parser.prototype.parseSymbol = function () {
|
|
14387
|
-
var token = this.peek();
|
|
14476
|
+
var token = this.asToken(this.peek());
|
|
14388
14477
|
this.advance();
|
|
14389
14478
|
if (!isSymbolToken(token)) {
|
|
14390
14479
|
throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
|
|
@@ -14406,7 +14495,7 @@ var Lits = (function (exports) {
|
|
|
14406
14495
|
return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
|
|
14407
14496
|
};
|
|
14408
14497
|
Parser.prototype.parseNumber = function () {
|
|
14409
|
-
var token = this.peek();
|
|
14498
|
+
var token = this.asToken(this.peek());
|
|
14410
14499
|
this.advance();
|
|
14411
14500
|
var value = token[1];
|
|
14412
14501
|
var negative = value[0] === '-';
|
|
@@ -14414,7 +14503,7 @@ var Lits = (function (exports) {
|
|
|
14414
14503
|
return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
|
|
14415
14504
|
};
|
|
14416
14505
|
Parser.prototype.parseString = function () {
|
|
14417
|
-
var token = this.peek();
|
|
14506
|
+
var token = this.asToken(this.peek());
|
|
14418
14507
|
this.advance();
|
|
14419
14508
|
var value = token[1].substring(1, token[1].length - 1)
|
|
14420
14509
|
.replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
|
|
@@ -14446,7 +14535,7 @@ var Lits = (function (exports) {
|
|
|
14446
14535
|
return withSourceCodeInfo([NodeTypes.String, value], token[2]);
|
|
14447
14536
|
};
|
|
14448
14537
|
Parser.prototype.parseRegexpShorthand = function () {
|
|
14449
|
-
var token = this.peek();
|
|
14538
|
+
var token = this.asToken(this.peek());
|
|
14450
14539
|
this.advance();
|
|
14451
14540
|
var endStringPosition = token[1].lastIndexOf('"');
|
|
14452
14541
|
var regexpString = token[1].substring(2, endStringPosition);
|
|
@@ -14651,6 +14740,11 @@ var Lits = (function (exports) {
|
|
|
14651
14740
|
}
|
|
14652
14741
|
var api = {
|
|
14653
14742
|
collection: [
|
|
14743
|
+
'filter',
|
|
14744
|
+
'map',
|
|
14745
|
+
'reduce',
|
|
14746
|
+
'reduce-right',
|
|
14747
|
+
'reductions',
|
|
14654
14748
|
'count',
|
|
14655
14749
|
'get',
|
|
14656
14750
|
'get-in',
|
|
@@ -14680,11 +14774,6 @@ var Lits = (function (exports) {
|
|
|
14680
14774
|
'shift',
|
|
14681
14775
|
'slice',
|
|
14682
14776
|
'splice',
|
|
14683
|
-
'reductions',
|
|
14684
|
-
'reduce',
|
|
14685
|
-
'reduce-right',
|
|
14686
|
-
'map',
|
|
14687
|
-
'filter',
|
|
14688
14777
|
'position',
|
|
14689
14778
|
'index-of',
|
|
14690
14779
|
'last-index-of',
|
|
@@ -14757,9 +14846,9 @@ var Lits = (function (exports) {
|
|
|
14757
14846
|
'atanh',
|
|
14758
14847
|
],
|
|
14759
14848
|
functional: [
|
|
14849
|
+
'|>',
|
|
14760
14850
|
'apply',
|
|
14761
14851
|
'identity',
|
|
14762
|
-
'partial',
|
|
14763
14852
|
'comp',
|
|
14764
14853
|
'constantly',
|
|
14765
14854
|
'juxt',
|
|
@@ -15208,7 +15297,6 @@ var Lits = (function (exports) {
|
|
|
15208
15297
|
examples: [
|
|
15209
15298
|
'flatten([1, 2, [3, 4], 5])',
|
|
15210
15299
|
"\nlet foo := \"bar\";\nflatten([\n 1,\n \" 2 A \",\n [foo, [4, [\"ABC\"]]],\n 6,\n])",
|
|
15211
|
-
'flatten(12)',
|
|
15212
15300
|
],
|
|
15213
15301
|
noOperatorDocumentation: true,
|
|
15214
15302
|
},
|
|
@@ -15875,6 +15963,142 @@ var Lits = (function (exports) {
|
|
|
15875
15963
|
};
|
|
15876
15964
|
|
|
15877
15965
|
var collectionReference = {
|
|
15966
|
+
'filter': {
|
|
15967
|
+
title: 'filter',
|
|
15968
|
+
category: 'Collection',
|
|
15969
|
+
linkName: 'filter',
|
|
15970
|
+
returns: {
|
|
15971
|
+
type: 'collection',
|
|
15972
|
+
},
|
|
15973
|
+
args: __assign(__assign({}, getOperatorArgs('collection', 'function')), { coll: {
|
|
15974
|
+
type: 'collection',
|
|
15975
|
+
}, fun: {
|
|
15976
|
+
type: 'function',
|
|
15977
|
+
} }),
|
|
15978
|
+
variants: [
|
|
15979
|
+
{ argumentNames: ['coll', 'fun'] },
|
|
15980
|
+
],
|
|
15981
|
+
description: 'Creates a new collection with all elements that pass the test implemented by $fun.',
|
|
15982
|
+
examples: [
|
|
15983
|
+
"\nfilter(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)",
|
|
15984
|
+
"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)",
|
|
15985
|
+
"\nfilter(\n { a := 1, b := 2 },\n odd?\n)",
|
|
15986
|
+
],
|
|
15987
|
+
},
|
|
15988
|
+
'map': {
|
|
15989
|
+
title: 'map',
|
|
15990
|
+
category: 'Collection',
|
|
15991
|
+
linkName: 'map',
|
|
15992
|
+
returns: {
|
|
15993
|
+
type: 'collection',
|
|
15994
|
+
},
|
|
15995
|
+
args: __assign(__assign({}, getOperatorArgs('collection', 'function')), { colls: {
|
|
15996
|
+
type: 'collection',
|
|
15997
|
+
rest: true,
|
|
15998
|
+
description: 'At least one.',
|
|
15999
|
+
}, fun: {
|
|
16000
|
+
type: 'function',
|
|
16001
|
+
} }),
|
|
16002
|
+
variants: [
|
|
16003
|
+
{ argumentNames: ['colls', 'fun'] },
|
|
16004
|
+
],
|
|
16005
|
+
description: 'Creates a new collection populated with the results of calling $fun on every element in $colls.',
|
|
16006
|
+
examples: [
|
|
16007
|
+
'[1, 2, 3] map -',
|
|
16008
|
+
'[1, 2, 3] map -> -($)',
|
|
16009
|
+
'map(["Albert", "Mojir", 42], str)',
|
|
16010
|
+
'map([1, 2, 3], inc)',
|
|
16011
|
+
'map([1, 2, 3], [1, 10, 100], *)',
|
|
16012
|
+
'map({ a := 1, b := 2 }, inc)',
|
|
16013
|
+
'map({ a := 1, b := 2 }, { a := 10, b := 20 }, +)',
|
|
16014
|
+
],
|
|
16015
|
+
},
|
|
16016
|
+
'reduce': {
|
|
16017
|
+
title: 'reduce',
|
|
16018
|
+
category: 'Collection',
|
|
16019
|
+
linkName: 'reduce',
|
|
16020
|
+
returns: {
|
|
16021
|
+
type: 'any',
|
|
16022
|
+
},
|
|
16023
|
+
args: {
|
|
16024
|
+
fun: {
|
|
16025
|
+
type: 'function',
|
|
16026
|
+
},
|
|
16027
|
+
coll: {
|
|
16028
|
+
type: 'collection',
|
|
16029
|
+
},
|
|
16030
|
+
initial: {
|
|
16031
|
+
type: 'any',
|
|
16032
|
+
},
|
|
16033
|
+
},
|
|
16034
|
+
variants: [
|
|
16035
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16036
|
+
],
|
|
16037
|
+
description: 'Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.',
|
|
16038
|
+
examples: [
|
|
16039
|
+
'reduce([1, 2, 3], +, 0)',
|
|
16040
|
+
'reduce([], +, 0)',
|
|
16041
|
+
'reduce({ a := 1, b := 2 }, +, 0)',
|
|
16042
|
+
"\nreduce(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + if even?(value) then value else 0 end,\n 0)",
|
|
16043
|
+
],
|
|
16044
|
+
},
|
|
16045
|
+
'reduce-right': {
|
|
16046
|
+
title: 'reduce-right',
|
|
16047
|
+
category: 'Collection',
|
|
16048
|
+
linkName: 'reduce-right',
|
|
16049
|
+
returns: {
|
|
16050
|
+
type: 'any',
|
|
16051
|
+
},
|
|
16052
|
+
args: {
|
|
16053
|
+
fun: {
|
|
16054
|
+
type: 'function',
|
|
16055
|
+
},
|
|
16056
|
+
coll: {
|
|
16057
|
+
type: 'collection',
|
|
16058
|
+
},
|
|
16059
|
+
initial: {
|
|
16060
|
+
type: 'any',
|
|
16061
|
+
},
|
|
16062
|
+
},
|
|
16063
|
+
variants: [
|
|
16064
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16065
|
+
],
|
|
16066
|
+
description: 'Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.',
|
|
16067
|
+
examples: [
|
|
16068
|
+
'reduce-right(["A", "B", "C"], str, "")',
|
|
16069
|
+
'reduce-right({ a := 1, b := 2 }, +, 0)',
|
|
16070
|
+
],
|
|
16071
|
+
},
|
|
16072
|
+
'reductions': {
|
|
16073
|
+
title: 'reductions',
|
|
16074
|
+
category: 'Collection',
|
|
16075
|
+
linkName: 'reductions',
|
|
16076
|
+
returns: {
|
|
16077
|
+
type: 'any',
|
|
16078
|
+
},
|
|
16079
|
+
args: {
|
|
16080
|
+
fun: {
|
|
16081
|
+
type: 'function',
|
|
16082
|
+
},
|
|
16083
|
+
coll: {
|
|
16084
|
+
type: 'collection',
|
|
16085
|
+
},
|
|
16086
|
+
initial: {
|
|
16087
|
+
type: 'any',
|
|
16088
|
+
},
|
|
16089
|
+
},
|
|
16090
|
+
variants: [
|
|
16091
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16092
|
+
],
|
|
16093
|
+
description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.',
|
|
16094
|
+
examples: [
|
|
16095
|
+
'reductions([1, 2, 3], +, 0)',
|
|
16096
|
+
'reductions([1, 2, 3], +, 10)',
|
|
16097
|
+
'reductions([], +, 0)',
|
|
16098
|
+
'reductions({ a := 1, b := 2 }, +, 0)',
|
|
16099
|
+
"\nreductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + if even?(value) then value else 0 end,\n 0\n)",
|
|
16100
|
+
],
|
|
16101
|
+
},
|
|
15878
16102
|
'count': {
|
|
15879
16103
|
title: 'count',
|
|
15880
16104
|
category: 'Collection',
|
|
@@ -16258,6 +16482,23 @@ var Lits = (function (exports) {
|
|
|
16258
16482
|
};
|
|
16259
16483
|
|
|
16260
16484
|
var functionalReference = {
|
|
16485
|
+
'|>': {
|
|
16486
|
+
title: '|>',
|
|
16487
|
+
category: 'Functional',
|
|
16488
|
+
linkName: '-or-gt',
|
|
16489
|
+
returns: {
|
|
16490
|
+
type: 'any',
|
|
16491
|
+
},
|
|
16492
|
+
args: __assign({}, getOperatorArgs('any', 'function')),
|
|
16493
|
+
variants: [
|
|
16494
|
+
{ argumentNames: ['a', 'b'] },
|
|
16495
|
+
],
|
|
16496
|
+
description: 'Takes a value $a and a function $b, and returns the result of applying $b to $a.',
|
|
16497
|
+
examples: [
|
|
16498
|
+
"\n1 |> inc |> inc",
|
|
16499
|
+
"range(10)\n |> map(_, -> $ ^ 2) // [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n |> filter(_, odd?) // [1, 9, 25, 49, 81]\n |> reduce(_, +, 0) // 165\n |> sqrt // 12.84523257866513\n |> round(_, 2)",
|
|
16500
|
+
],
|
|
16501
|
+
},
|
|
16261
16502
|
'apply': {
|
|
16262
16503
|
title: 'apply',
|
|
16263
16504
|
category: 'Functional',
|
|
@@ -16298,33 +16539,6 @@ var Lits = (function (exports) {
|
|
|
16298
16539
|
description: 'Returns $x.',
|
|
16299
16540
|
examples: ['identity(1)', 'identity("Albert")', 'identity({ a := 1 })', 'identity(null)'],
|
|
16300
16541
|
},
|
|
16301
|
-
'partial': {
|
|
16302
|
-
title: 'partial',
|
|
16303
|
-
category: 'Functional',
|
|
16304
|
-
linkName: 'partial',
|
|
16305
|
-
returns: {
|
|
16306
|
-
type: 'function',
|
|
16307
|
-
},
|
|
16308
|
-
args: {
|
|
16309
|
-
fun: {
|
|
16310
|
-
type: 'function',
|
|
16311
|
-
},
|
|
16312
|
-
args: {
|
|
16313
|
-
type: 'any',
|
|
16314
|
-
rest: true,
|
|
16315
|
-
},
|
|
16316
|
-
},
|
|
16317
|
-
variants: [
|
|
16318
|
-
{ argumentNames: ['fun', 'args'] },
|
|
16319
|
-
],
|
|
16320
|
-
description: "Takes a function $fun and a optional number arguments $args to $fun.\nIt returns a function that takes the additional additional arguments.\nWhen called, the returned function calls `(`$fun `...`$args` ...additional_arguments)`.",
|
|
16321
|
-
examples: [
|
|
16322
|
-
'partial(+, 100)',
|
|
16323
|
-
"\nlet plusMany := partial(+, 100, 1000);\nplusMany(1, 10)",
|
|
16324
|
-
"\nlet addHundred := partial(+, 100);\naddHundred(10)",
|
|
16325
|
-
],
|
|
16326
|
-
noOperatorDocumentation: true,
|
|
16327
|
-
},
|
|
16328
16542
|
'comp': {
|
|
16329
16543
|
title: 'comp',
|
|
16330
16544
|
category: 'Functional',
|
|
@@ -24636,134 +24850,6 @@ var Lits = (function (exports) {
|
|
|
24636
24850
|
'splice("Albert", 2, 2, "fo")',
|
|
24637
24851
|
],
|
|
24638
24852
|
},
|
|
24639
|
-
'reductions': {
|
|
24640
|
-
title: 'reductions',
|
|
24641
|
-
category: 'Sequence',
|
|
24642
|
-
linkName: 'reductions',
|
|
24643
|
-
returns: {
|
|
24644
|
-
type: 'any',
|
|
24645
|
-
rest: true,
|
|
24646
|
-
},
|
|
24647
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24648
|
-
type: 'function',
|
|
24649
|
-
}, seq: {
|
|
24650
|
-
type: 'sequence',
|
|
24651
|
-
rest: true,
|
|
24652
|
-
}, start: {
|
|
24653
|
-
type: 'any',
|
|
24654
|
-
} }),
|
|
24655
|
-
variants: [
|
|
24656
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24657
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24658
|
-
],
|
|
24659
|
-
description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $seq by $fun.',
|
|
24660
|
-
examples: [
|
|
24661
|
-
'[1, 2, 3] reductions +',
|
|
24662
|
-
'reductions([1, 2, 3], +)',
|
|
24663
|
-
'reductions([1, 2, 3], +, 10)',
|
|
24664
|
-
'reductions([], +, 0)',
|
|
24665
|
-
"\nreductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + if even?(value) then value else 0 end,\n 0\n)",
|
|
24666
|
-
],
|
|
24667
|
-
},
|
|
24668
|
-
'reduce': {
|
|
24669
|
-
title: 'reduce',
|
|
24670
|
-
category: 'Sequence',
|
|
24671
|
-
linkName: 'reduce',
|
|
24672
|
-
returns: {
|
|
24673
|
-
type: 'any',
|
|
24674
|
-
},
|
|
24675
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24676
|
-
type: 'function',
|
|
24677
|
-
}, seq: {
|
|
24678
|
-
type: 'sequence',
|
|
24679
|
-
}, start: {
|
|
24680
|
-
type: 'any',
|
|
24681
|
-
} }),
|
|
24682
|
-
variants: [
|
|
24683
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24684
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24685
|
-
],
|
|
24686
|
-
description: 'Runs $fun function on each element of the $seq, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $seq is a single value.',
|
|
24687
|
-
examples: [
|
|
24688
|
-
'[1, 2, 3] reduce +',
|
|
24689
|
-
'reduce([1, 2, 3], +)',
|
|
24690
|
-
'reduce([1, 2, 3], +, 0)',
|
|
24691
|
-
'reduce([], +, 0)',
|
|
24692
|
-
"\nreduce(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + if even?(value) then value else 0 end,\n 0)",
|
|
24693
|
-
],
|
|
24694
|
-
},
|
|
24695
|
-
'reduce-right': {
|
|
24696
|
-
title: 'reduce-right',
|
|
24697
|
-
category: 'Sequence',
|
|
24698
|
-
linkName: 'reduce-right',
|
|
24699
|
-
returns: {
|
|
24700
|
-
type: 'sequence',
|
|
24701
|
-
},
|
|
24702
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24703
|
-
type: 'function',
|
|
24704
|
-
}, seq: {
|
|
24705
|
-
type: 'sequence',
|
|
24706
|
-
}, start: {
|
|
24707
|
-
type: 'any',
|
|
24708
|
-
} }),
|
|
24709
|
-
variants: [
|
|
24710
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24711
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24712
|
-
],
|
|
24713
|
-
description: 'Runs $fun function on each element of the $seq (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $seq is a single value.',
|
|
24714
|
-
examples: [
|
|
24715
|
-
'range(1, 10) reduce-right *',
|
|
24716
|
-
'reduce-right(["A", "B", "C"], str, "")',
|
|
24717
|
-
],
|
|
24718
|
-
},
|
|
24719
|
-
'map': {
|
|
24720
|
-
title: 'map',
|
|
24721
|
-
category: 'Sequence',
|
|
24722
|
-
linkName: 'map',
|
|
24723
|
-
returns: {
|
|
24724
|
-
type: 'any',
|
|
24725
|
-
rest: true,
|
|
24726
|
-
},
|
|
24727
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seqs: {
|
|
24728
|
-
type: 'sequence',
|
|
24729
|
-
rest: true,
|
|
24730
|
-
description: 'At least one.',
|
|
24731
|
-
}, fun: {
|
|
24732
|
-
type: 'function',
|
|
24733
|
-
} }),
|
|
24734
|
-
variants: [
|
|
24735
|
-
{ argumentNames: ['seqs', 'fun'] },
|
|
24736
|
-
],
|
|
24737
|
-
description: 'Creates a new array populated with the results of calling $fun on every element in $seqs.',
|
|
24738
|
-
examples: [
|
|
24739
|
-
'[1, 2, 3] map -',
|
|
24740
|
-
'[1, 2, 3] map -> -($)',
|
|
24741
|
-
'map(["Albert", "Mojir", 42], str)',
|
|
24742
|
-
'map([1, 2, 3], inc)',
|
|
24743
|
-
'map([1, 2, 3], [1, 10, 100], *)',
|
|
24744
|
-
],
|
|
24745
|
-
},
|
|
24746
|
-
'filter': {
|
|
24747
|
-
title: 'filter',
|
|
24748
|
-
category: 'Sequence',
|
|
24749
|
-
linkName: 'filter',
|
|
24750
|
-
returns: {
|
|
24751
|
-
type: 'sequence',
|
|
24752
|
-
},
|
|
24753
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seq: {
|
|
24754
|
-
type: 'sequence',
|
|
24755
|
-
}, fun: {
|
|
24756
|
-
type: 'function',
|
|
24757
|
-
} }),
|
|
24758
|
-
variants: [
|
|
24759
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24760
|
-
],
|
|
24761
|
-
description: 'Creates a new array with all elements that pass the test implemented by $fun.',
|
|
24762
|
-
examples: [
|
|
24763
|
-
"\nfilter(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)",
|
|
24764
|
-
"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)",
|
|
24765
|
-
],
|
|
24766
|
-
},
|
|
24767
24853
|
'position': {
|
|
24768
24854
|
title: 'position',
|
|
24769
24855
|
category: 'Sequence',
|