@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/index.esm.js
CHANGED
|
@@ -824,6 +824,32 @@ function assertCharArray(value, sourceCodeInfo) {
|
|
|
824
824
|
throw getAssertionError('array of strings', value, sourceCodeInfo);
|
|
825
825
|
}
|
|
826
826
|
|
|
827
|
+
function mapObjects(_a) {
|
|
828
|
+
var colls = _a.colls, contextStack = _a.contextStack, executeFunction = _a.executeFunction, fn = _a.fn, sourceCodeInfo = _a.sourceCodeInfo;
|
|
829
|
+
assertObj(colls[0], sourceCodeInfo);
|
|
830
|
+
var keys = Object.keys(colls[0]);
|
|
831
|
+
var params = {};
|
|
832
|
+
colls.forEach(function (obj) {
|
|
833
|
+
assertObj(obj, sourceCodeInfo);
|
|
834
|
+
var objKeys = Object.keys(obj);
|
|
835
|
+
if (objKeys.length !== keys.length) {
|
|
836
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
837
|
+
}
|
|
838
|
+
if (!objKeys.every(function (key) { return keys.includes(key); })) {
|
|
839
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
840
|
+
}
|
|
841
|
+
Object.entries(obj).forEach(function (_a) {
|
|
842
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
843
|
+
if (!params[key])
|
|
844
|
+
params[key] = [];
|
|
845
|
+
params[key].push(value);
|
|
846
|
+
});
|
|
847
|
+
});
|
|
848
|
+
return keys.reduce(function (result, key) {
|
|
849
|
+
result[key] = executeFunction(fn, params[key], contextStack, sourceCodeInfo);
|
|
850
|
+
return result;
|
|
851
|
+
}, {});
|
|
852
|
+
}
|
|
827
853
|
function cloneAndGetMeta(originalColl, keys, sourceCodeInfo) {
|
|
828
854
|
var coll = cloneColl(originalColl);
|
|
829
855
|
var butLastKeys = keys.slice(0, keys.length - 1);
|
|
@@ -916,6 +942,188 @@ function assoc(coll, key, value, sourceCodeInfo) {
|
|
|
916
942
|
return copy;
|
|
917
943
|
}
|
|
918
944
|
var collectionNormalExpression = {
|
|
945
|
+
'filter': {
|
|
946
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
947
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
948
|
+
var executeFunction = _b.executeFunction;
|
|
949
|
+
assertColl(coll, sourceCodeInfo);
|
|
950
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
951
|
+
if (Array.isArray(coll)) {
|
|
952
|
+
var result = coll.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
953
|
+
return result;
|
|
954
|
+
}
|
|
955
|
+
if (isString(coll)) {
|
|
956
|
+
return coll
|
|
957
|
+
.split('')
|
|
958
|
+
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
959
|
+
.join('');
|
|
960
|
+
}
|
|
961
|
+
return Object.entries(coll)
|
|
962
|
+
.filter(function (_a) {
|
|
963
|
+
var _b = __read(_a, 2), value = _b[1];
|
|
964
|
+
return executeFunction(fn, [value], contextStack, sourceCodeInfo);
|
|
965
|
+
})
|
|
966
|
+
.reduce(function (result, _a) {
|
|
967
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
968
|
+
result[key] = value;
|
|
969
|
+
return result;
|
|
970
|
+
}, {});
|
|
971
|
+
},
|
|
972
|
+
paramCount: 2,
|
|
973
|
+
},
|
|
974
|
+
'map': {
|
|
975
|
+
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
976
|
+
var executeFunction = _a.executeFunction;
|
|
977
|
+
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
978
|
+
if (isObj(params[0])) {
|
|
979
|
+
return mapObjects({
|
|
980
|
+
colls: params.slice(0, -1),
|
|
981
|
+
fn: fn,
|
|
982
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
983
|
+
contextStack: contextStack,
|
|
984
|
+
executeFunction: executeFunction,
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
var seqs = params.slice(0, -1);
|
|
988
|
+
assertSeq(seqs[0], sourceCodeInfo);
|
|
989
|
+
var isStr = typeof seqs[0] === 'string';
|
|
990
|
+
var len = seqs[0].length;
|
|
991
|
+
seqs.slice(1).forEach(function (seq) {
|
|
992
|
+
if (isStr) {
|
|
993
|
+
assertString(seq, sourceCodeInfo);
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
assertArray(seq, sourceCodeInfo);
|
|
997
|
+
}
|
|
998
|
+
len = Math.min(len, seq.length);
|
|
999
|
+
});
|
|
1000
|
+
var paramArray = [];
|
|
1001
|
+
var _loop_1 = function (i) {
|
|
1002
|
+
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1003
|
+
};
|
|
1004
|
+
for (var i = 0; i < len; i++) {
|
|
1005
|
+
_loop_1(i);
|
|
1006
|
+
}
|
|
1007
|
+
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1008
|
+
if (!isStr) {
|
|
1009
|
+
return mapped;
|
|
1010
|
+
}
|
|
1011
|
+
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1012
|
+
return mapped.join('');
|
|
1013
|
+
},
|
|
1014
|
+
paramCount: { min: 2 },
|
|
1015
|
+
},
|
|
1016
|
+
'reduce': {
|
|
1017
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1018
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1019
|
+
var executeFunction = _b.executeFunction;
|
|
1020
|
+
assertColl(coll, sourceCodeInfo);
|
|
1021
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1022
|
+
assertAny(initial, sourceCodeInfo);
|
|
1023
|
+
if (typeof coll === 'string') {
|
|
1024
|
+
assertString(initial, sourceCodeInfo);
|
|
1025
|
+
if (coll.length === 0)
|
|
1026
|
+
return initial;
|
|
1027
|
+
return coll.split('').reduce(function (result, elem) {
|
|
1028
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1029
|
+
}, initial);
|
|
1030
|
+
}
|
|
1031
|
+
else if (Array.isArray(coll)) {
|
|
1032
|
+
if (coll.length === 0)
|
|
1033
|
+
return initial;
|
|
1034
|
+
return coll.reduce(function (result, elem) {
|
|
1035
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1036
|
+
}, initial);
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
if (Object.keys(coll).length === 0)
|
|
1040
|
+
return initial;
|
|
1041
|
+
return Object.entries(coll).reduce(function (result, _a) {
|
|
1042
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1043
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1044
|
+
}, initial);
|
|
1045
|
+
}
|
|
1046
|
+
},
|
|
1047
|
+
paramCount: 3,
|
|
1048
|
+
},
|
|
1049
|
+
'reduce-right': {
|
|
1050
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1051
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1052
|
+
var executeFunction = _b.executeFunction;
|
|
1053
|
+
assertColl(coll, sourceCodeInfo);
|
|
1054
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1055
|
+
assertAny(initial, sourceCodeInfo);
|
|
1056
|
+
if (typeof coll === 'string') {
|
|
1057
|
+
if (coll.length === 0)
|
|
1058
|
+
return initial;
|
|
1059
|
+
return coll.split('').reduceRight(function (result, elem) {
|
|
1060
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1061
|
+
}, initial);
|
|
1062
|
+
}
|
|
1063
|
+
else if (Array.isArray(coll)) {
|
|
1064
|
+
if (coll.length === 0)
|
|
1065
|
+
return initial;
|
|
1066
|
+
return coll.reduceRight(function (result, elem) {
|
|
1067
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1068
|
+
}, initial);
|
|
1069
|
+
}
|
|
1070
|
+
else {
|
|
1071
|
+
if (Object.keys(coll).length === 0)
|
|
1072
|
+
return initial;
|
|
1073
|
+
return Object.entries(coll).reduceRight(function (result, _a) {
|
|
1074
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1075
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1076
|
+
}, initial);
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
paramCount: 3,
|
|
1080
|
+
},
|
|
1081
|
+
'reductions': {
|
|
1082
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1083
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1084
|
+
var executeFunction = _b.executeFunction;
|
|
1085
|
+
assertColl(coll, sourceCodeInfo);
|
|
1086
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1087
|
+
assertAny(initial, sourceCodeInfo);
|
|
1088
|
+
assertAny(initial, sourceCodeInfo);
|
|
1089
|
+
if (typeof coll === 'string') {
|
|
1090
|
+
assertString(initial, sourceCodeInfo);
|
|
1091
|
+
if (coll.length === 0)
|
|
1092
|
+
return [initial];
|
|
1093
|
+
var resultArray_1 = [initial];
|
|
1094
|
+
coll.split('').reduce(function (result, elem) {
|
|
1095
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1096
|
+
resultArray_1.push(newVal);
|
|
1097
|
+
return newVal;
|
|
1098
|
+
}, initial);
|
|
1099
|
+
return resultArray_1;
|
|
1100
|
+
}
|
|
1101
|
+
else if (Array.isArray(coll)) {
|
|
1102
|
+
if (coll.length === 0)
|
|
1103
|
+
return [initial];
|
|
1104
|
+
var resultArray_2 = [initial];
|
|
1105
|
+
coll.reduce(function (result, elem) {
|
|
1106
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1107
|
+
resultArray_2.push(newVal);
|
|
1108
|
+
return newVal;
|
|
1109
|
+
}, initial);
|
|
1110
|
+
return resultArray_2;
|
|
1111
|
+
}
|
|
1112
|
+
else {
|
|
1113
|
+
if (Object.keys(coll).length === 0)
|
|
1114
|
+
return [initial];
|
|
1115
|
+
var resultArray_3 = [initial];
|
|
1116
|
+
Object.entries(coll).reduce(function (result, _a) {
|
|
1117
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1118
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1119
|
+
resultArray_3.push(newVal);
|
|
1120
|
+
return newVal;
|
|
1121
|
+
}, initial);
|
|
1122
|
+
return resultArray_3;
|
|
1123
|
+
}
|
|
1124
|
+
},
|
|
1125
|
+
paramCount: 3,
|
|
1126
|
+
},
|
|
919
1127
|
'get': {
|
|
920
1128
|
evaluate: function (params, sourceCodeInfo) {
|
|
921
1129
|
var _a = __read(params, 2), coll = _a[0], key = _a[1];
|
|
@@ -1219,13 +1427,15 @@ var arrayNormalExpression = {
|
|
|
1219
1427
|
paramCount: 2,
|
|
1220
1428
|
},
|
|
1221
1429
|
flatten: {
|
|
1222
|
-
evaluate: function (_a) {
|
|
1223
|
-
var _b = __read(_a,
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1430
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
1431
|
+
var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
|
|
1432
|
+
assertArray(seq, sourceCodeInfo);
|
|
1433
|
+
var actualDepth = depth === undefined || depth === Number.POSITIVE_INFINITY
|
|
1434
|
+
? Number.POSITIVE_INFINITY
|
|
1435
|
+
: asNumber(depth, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
1436
|
+
return seq.flat(actualDepth);
|
|
1227
1437
|
},
|
|
1228
|
-
paramCount: 1,
|
|
1438
|
+
paramCount: { min: 1, max: 2 },
|
|
1229
1439
|
},
|
|
1230
1440
|
mapcat: {
|
|
1231
1441
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -1258,23 +1468,6 @@ var sequenceNormalExpression = {
|
|
|
1258
1468
|
},
|
|
1259
1469
|
paramCount: { min: 2, max: 3 },
|
|
1260
1470
|
},
|
|
1261
|
-
'filter': {
|
|
1262
|
-
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1263
|
-
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
1264
|
-
var executeFunction = _b.executeFunction;
|
|
1265
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1266
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1267
|
-
if (Array.isArray(seq)) {
|
|
1268
|
-
var result = seq.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1269
|
-
return result;
|
|
1270
|
-
}
|
|
1271
|
-
return seq
|
|
1272
|
-
.split('')
|
|
1273
|
-
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
1274
|
-
.join('');
|
|
1275
|
-
},
|
|
1276
|
-
paramCount: 2,
|
|
1277
|
-
},
|
|
1278
1471
|
'first': {
|
|
1279
1472
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1280
1473
|
var _b = __read(_a, 1), array = _b[0];
|
|
@@ -1297,39 +1490,6 @@ var sequenceNormalExpression = {
|
|
|
1297
1490
|
},
|
|
1298
1491
|
paramCount: 1,
|
|
1299
1492
|
},
|
|
1300
|
-
'map': {
|
|
1301
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1302
|
-
var executeFunction = _a.executeFunction;
|
|
1303
|
-
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
1304
|
-
var seqs = params.slice(0, -1);
|
|
1305
|
-
assertSeq(seqs[0], sourceCodeInfo);
|
|
1306
|
-
var isString = typeof seqs[0] === 'string';
|
|
1307
|
-
var len = seqs[0].length;
|
|
1308
|
-
seqs.slice(1).forEach(function (seq) {
|
|
1309
|
-
if (isString) {
|
|
1310
|
-
assertString(seq, sourceCodeInfo);
|
|
1311
|
-
}
|
|
1312
|
-
else {
|
|
1313
|
-
assertArray(seq, sourceCodeInfo);
|
|
1314
|
-
}
|
|
1315
|
-
len = Math.min(len, seq.length);
|
|
1316
|
-
});
|
|
1317
|
-
var paramArray = [];
|
|
1318
|
-
var _loop_1 = function (i) {
|
|
1319
|
-
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1320
|
-
};
|
|
1321
|
-
for (var i = 0; i < len; i++) {
|
|
1322
|
-
_loop_1(i);
|
|
1323
|
-
}
|
|
1324
|
-
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1325
|
-
if (!isString) {
|
|
1326
|
-
return mapped;
|
|
1327
|
-
}
|
|
1328
|
-
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1329
|
-
return mapped.join('');
|
|
1330
|
-
},
|
|
1331
|
-
paramCount: { min: 2 },
|
|
1332
|
-
},
|
|
1333
1493
|
'pop': {
|
|
1334
1494
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1335
1495
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -1412,160 +1572,6 @@ var sequenceNormalExpression = {
|
|
|
1412
1572
|
},
|
|
1413
1573
|
paramCount: { min: 2 },
|
|
1414
1574
|
},
|
|
1415
|
-
'reductions': {
|
|
1416
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1417
|
-
var executeFunction = _a.executeFunction;
|
|
1418
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1419
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1420
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1421
|
-
if (params.length === 2) {
|
|
1422
|
-
if (seq.length === 0)
|
|
1423
|
-
return [executeFunction(fn, [], contextStack, sourceCodeInfo)];
|
|
1424
|
-
else if (seq.length === 1)
|
|
1425
|
-
return [toAny(seq[0])];
|
|
1426
|
-
if (typeof seq === 'string') {
|
|
1427
|
-
var chars = seq.split('');
|
|
1428
|
-
var resultArray_1 = [asAny(chars[0], sourceCodeInfo)];
|
|
1429
|
-
chars.slice(1).reduce(function (result, elem) {
|
|
1430
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1431
|
-
resultArray_1.push(newVal);
|
|
1432
|
-
return newVal;
|
|
1433
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1434
|
-
return resultArray_1;
|
|
1435
|
-
}
|
|
1436
|
-
else {
|
|
1437
|
-
var resultArray_2 = [toAny(seq[0])];
|
|
1438
|
-
seq.slice(1).reduce(function (result, elem) {
|
|
1439
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1440
|
-
resultArray_2.push(newVal);
|
|
1441
|
-
return newVal;
|
|
1442
|
-
}, toAny(seq[0]));
|
|
1443
|
-
return resultArray_2;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
else {
|
|
1447
|
-
var val = params[2];
|
|
1448
|
-
assertAny(val, sourceCodeInfo);
|
|
1449
|
-
if (typeof seq === 'string') {
|
|
1450
|
-
assertString(val, sourceCodeInfo);
|
|
1451
|
-
if (seq.length === 0)
|
|
1452
|
-
return [val];
|
|
1453
|
-
var resultArray_3 = [val];
|
|
1454
|
-
seq.split('').reduce(function (result, elem) {
|
|
1455
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1456
|
-
resultArray_3.push(newVal);
|
|
1457
|
-
return newVal;
|
|
1458
|
-
}, val);
|
|
1459
|
-
return resultArray_3;
|
|
1460
|
-
}
|
|
1461
|
-
else {
|
|
1462
|
-
if (seq.length === 0)
|
|
1463
|
-
return [val];
|
|
1464
|
-
var resultArray_4 = [val];
|
|
1465
|
-
seq.reduce(function (result, elem) {
|
|
1466
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1467
|
-
resultArray_4.push(newVal);
|
|
1468
|
-
return newVal;
|
|
1469
|
-
}, val);
|
|
1470
|
-
return resultArray_4;
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
},
|
|
1474
|
-
paramCount: { min: 2, max: 3 },
|
|
1475
|
-
},
|
|
1476
|
-
'reduce': {
|
|
1477
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1478
|
-
var executeFunction = _a.executeFunction;
|
|
1479
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1480
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1481
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1482
|
-
if (params.length === 2) {
|
|
1483
|
-
if (seq.length === 0)
|
|
1484
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1485
|
-
else if (seq.length === 1)
|
|
1486
|
-
return toAny(seq[0]);
|
|
1487
|
-
if (typeof seq === 'string') {
|
|
1488
|
-
var chars = seq.split('');
|
|
1489
|
-
return chars.slice(1).reduce(function (result, elem) {
|
|
1490
|
-
var val = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1491
|
-
return val;
|
|
1492
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1493
|
-
}
|
|
1494
|
-
else {
|
|
1495
|
-
return seq.slice(1).reduce(function (result, elem) {
|
|
1496
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1497
|
-
}, toAny(seq[0]));
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
else {
|
|
1501
|
-
var val = params[2];
|
|
1502
|
-
assertAny(val, sourceCodeInfo);
|
|
1503
|
-
if (typeof seq === 'string') {
|
|
1504
|
-
assertString(val, sourceCodeInfo);
|
|
1505
|
-
if (seq.length === 0)
|
|
1506
|
-
return val;
|
|
1507
|
-
return seq.split('').reduce(function (result, elem) {
|
|
1508
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1509
|
-
}, val);
|
|
1510
|
-
}
|
|
1511
|
-
else {
|
|
1512
|
-
if (seq.length === 0)
|
|
1513
|
-
return val;
|
|
1514
|
-
return seq.reduce(function (result, elem) {
|
|
1515
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1516
|
-
}, val);
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
},
|
|
1520
|
-
paramCount: { min: 2, max: 3 },
|
|
1521
|
-
},
|
|
1522
|
-
'reduce-right': {
|
|
1523
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1524
|
-
var executeFunction = _a.executeFunction;
|
|
1525
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1526
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1527
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1528
|
-
if (params.length === 2) {
|
|
1529
|
-
if (seq.length === 0)
|
|
1530
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1531
|
-
else if (seq.length === 1)
|
|
1532
|
-
return toAny(seq[0]);
|
|
1533
|
-
if (typeof seq === 'string') {
|
|
1534
|
-
var chars = seq.split('');
|
|
1535
|
-
return chars.slice(0, chars.length - 1).reduceRight(function (result, elem) {
|
|
1536
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1537
|
-
assertString(newVal, sourceCodeInfo);
|
|
1538
|
-
return newVal;
|
|
1539
|
-
}, chars[chars.length - 1]);
|
|
1540
|
-
}
|
|
1541
|
-
else {
|
|
1542
|
-
return seq.slice(0, seq.length - 1).reduceRight(function (result, elem) {
|
|
1543
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1544
|
-
}, asAny(seq[seq.length - 1], sourceCodeInfo));
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
else {
|
|
1548
|
-
var val = params[2];
|
|
1549
|
-
assertAny(val, sourceCodeInfo);
|
|
1550
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1551
|
-
if (typeof seq === 'string') {
|
|
1552
|
-
if (seq.length === 0)
|
|
1553
|
-
return val;
|
|
1554
|
-
return seq.split('').reduceRight(function (result, elem) {
|
|
1555
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1556
|
-
}, val);
|
|
1557
|
-
}
|
|
1558
|
-
else {
|
|
1559
|
-
if (seq.length === 0)
|
|
1560
|
-
return val;
|
|
1561
|
-
return seq.reduceRight(function (result, elem) {
|
|
1562
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1563
|
-
}, val);
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
},
|
|
1567
|
-
paramCount: { min: 2, max: 3 },
|
|
1568
|
-
},
|
|
1569
1575
|
'rest': {
|
|
1570
1576
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1571
1577
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -1884,7 +1890,7 @@ var sequenceNormalExpression = {
|
|
|
1884
1890
|
assertSeq(input, sourceCodeInfo);
|
|
1885
1891
|
if (Array.isArray(input)) {
|
|
1886
1892
|
var result = [];
|
|
1887
|
-
var
|
|
1893
|
+
var _loop_1 = function (item) {
|
|
1888
1894
|
assertAny(item, sourceCodeInfo);
|
|
1889
1895
|
if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
|
|
1890
1896
|
result.push(item);
|
|
@@ -1893,7 +1899,7 @@ var sequenceNormalExpression = {
|
|
|
1893
1899
|
try {
|
|
1894
1900
|
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
1895
1901
|
var item = input_1_1.value;
|
|
1896
|
-
|
|
1902
|
+
_loop_1(item);
|
|
1897
1903
|
}
|
|
1898
1904
|
}
|
|
1899
1905
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -3879,6 +3885,13 @@ var regexpNormalExpression = {
|
|
|
3879
3885
|
assertString(sourceArg, sourceCodeInfo);
|
|
3880
3886
|
var source = sourceArg || '(?:)';
|
|
3881
3887
|
var flags = typeof flagsArg === 'string' ? flagsArg : '';
|
|
3888
|
+
try {
|
|
3889
|
+
// eslint-disable-next-line no-new
|
|
3890
|
+
new RegExp(source, flags); // Throws if invalid regexp
|
|
3891
|
+
}
|
|
3892
|
+
catch (e) {
|
|
3893
|
+
throw new LitsError("Invalid regular expression: ".concat(source, " ").concat(flags), sourceCodeInfo);
|
|
3894
|
+
}
|
|
3882
3895
|
return _b = {},
|
|
3883
3896
|
_b[REGEXP_SYMBOL] = true,
|
|
3884
3897
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
@@ -4197,6 +4210,15 @@ function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
|
|
|
4197
4210
|
}
|
|
4198
4211
|
|
|
4199
4212
|
var functionalNormalExpression = {
|
|
4213
|
+
'|>': {
|
|
4214
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4215
|
+
var _c = __read(_a, 2), value = _c[0], func = _c[1];
|
|
4216
|
+
var executeFunction = _b.executeFunction;
|
|
4217
|
+
assertFunctionLike(func, sourceCodeInfo);
|
|
4218
|
+
return executeFunction(func, [value], contextStack, sourceCodeInfo);
|
|
4219
|
+
},
|
|
4220
|
+
paramCount: 2,
|
|
4221
|
+
},
|
|
4200
4222
|
'apply': {
|
|
4201
4223
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4202
4224
|
var _c = __read(_a), func = _c[0], params = _c.slice(1);
|
|
@@ -4217,20 +4239,6 @@ var functionalNormalExpression = {
|
|
|
4217
4239
|
},
|
|
4218
4240
|
paramCount: 1,
|
|
4219
4241
|
},
|
|
4220
|
-
'partial': {
|
|
4221
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
4222
|
-
var _b;
|
|
4223
|
-
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
4224
|
-
return _b = {},
|
|
4225
|
-
_b[FUNCTION_SYMBOL] = true,
|
|
4226
|
-
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4227
|
-
_b.functionType = 'Partial',
|
|
4228
|
-
_b.function = asFunctionLike(fn, sourceCodeInfo),
|
|
4229
|
-
_b.params = params,
|
|
4230
|
-
_b;
|
|
4231
|
-
},
|
|
4232
|
-
paramCount: { min: 1 },
|
|
4233
|
-
},
|
|
4234
4242
|
'comp': {
|
|
4235
4243
|
evaluate: function (params, sourceCodeInfo) {
|
|
4236
4244
|
var _a;
|
|
@@ -6990,10 +6998,10 @@ var linearAlgebraNormalExpression = {
|
|
|
6990
6998
|
assertVector(vectorA, sourceCodeInfo);
|
|
6991
6999
|
assertVector(vectorB, sourceCodeInfo);
|
|
6992
7000
|
if (vectorA.length < 2) {
|
|
6993
|
-
throw new
|
|
7001
|
+
throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
|
|
6994
7002
|
}
|
|
6995
7003
|
if (vectorA.length !== vectorB.length) {
|
|
6996
|
-
throw new
|
|
7004
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6997
7005
|
}
|
|
6998
7006
|
assertNumber(lag, sourceCodeInfo, {
|
|
6999
7007
|
integer: true,
|
|
@@ -8245,7 +8253,7 @@ var partitionsNormalExpressions = {
|
|
|
8245
8253
|
if (n === 0)
|
|
8246
8254
|
return 1;
|
|
8247
8255
|
if (n > partitionNumbers.length) {
|
|
8248
|
-
throw new
|
|
8256
|
+
throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
|
|
8249
8257
|
}
|
|
8250
8258
|
return partitionNumbers[n - 1];
|
|
8251
8259
|
},
|
|
@@ -10384,7 +10392,12 @@ var combinatoricalNormalExpression = {
|
|
|
10384
10392
|
var _b = __read(_a, 2), a = _b[0], m = _b[1];
|
|
10385
10393
|
assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
|
|
10386
10394
|
assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
|
|
10387
|
-
|
|
10395
|
+
try {
|
|
10396
|
+
return modInverse(a, m);
|
|
10397
|
+
}
|
|
10398
|
+
catch (error) {
|
|
10399
|
+
throw new LitsError(error, sourceCodeInfo);
|
|
10400
|
+
}
|
|
10388
10401
|
},
|
|
10389
10402
|
paramCount: 2,
|
|
10390
10403
|
},
|
|
@@ -10403,7 +10416,7 @@ var combinatoricalNormalExpression = {
|
|
|
10403
10416
|
assertVector(remainders, sourceCodeInfo);
|
|
10404
10417
|
assertVector(moduli, sourceCodeInfo);
|
|
10405
10418
|
if (remainders.length !== moduli.length) {
|
|
10406
|
-
throw new
|
|
10419
|
+
throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
|
|
10407
10420
|
}
|
|
10408
10421
|
try {
|
|
10409
10422
|
return chineseRemainder(remainders, moduli);
|
|
@@ -11197,6 +11210,7 @@ var nonNumberReservedSymbolRecord = {
|
|
|
11197
11210
|
function: null,
|
|
11198
11211
|
export: null,
|
|
11199
11212
|
as: null,
|
|
11213
|
+
_: null,
|
|
11200
11214
|
};
|
|
11201
11215
|
var phi = (1 + Math.sqrt(5)) / 2;
|
|
11202
11216
|
var numberReservedSymbolRecord = {
|
|
@@ -11911,7 +11925,11 @@ var objectSpecialExpression = {
|
|
|
11911
11925
|
}
|
|
11912
11926
|
else {
|
|
11913
11927
|
var key = evaluateNode(keyNode, contextStack);
|
|
11914
|
-
var
|
|
11928
|
+
var valueNode = params[i + 1];
|
|
11929
|
+
if (valueNode === undefined) {
|
|
11930
|
+
throw new LitsError('Missing value for key', keyNode[2]);
|
|
11931
|
+
}
|
|
11932
|
+
var value = evaluateNode(valueNode, contextStack);
|
|
11915
11933
|
assertString(key, keyNode[2]);
|
|
11916
11934
|
result[key] = value;
|
|
11917
11935
|
}
|
|
@@ -12161,8 +12179,27 @@ var functionExecutors = {
|
|
|
12161
12179
|
}
|
|
12162
12180
|
},
|
|
12163
12181
|
Partial: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12182
|
+
var e_2, _b;
|
|
12164
12183
|
var executeFunction = _a.executeFunction;
|
|
12165
|
-
|
|
12184
|
+
var actualParams = __spreadArray([], __read(fn.params), false);
|
|
12185
|
+
if (params.length !== fn.placeholders.length) {
|
|
12186
|
+
throw new LitsError("(partial) expects ".concat(fn.placeholders.length, " arguments, got ").concat(params.length, "."), sourceCodeInfo);
|
|
12187
|
+
}
|
|
12188
|
+
var paramsCopy = __spreadArray([], __read(params), false);
|
|
12189
|
+
try {
|
|
12190
|
+
for (var _c = __values(fn.placeholders), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
12191
|
+
var placeholderIndex = _d.value;
|
|
12192
|
+
actualParams.splice(placeholderIndex, 0, paramsCopy.shift());
|
|
12193
|
+
}
|
|
12194
|
+
}
|
|
12195
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
12196
|
+
finally {
|
|
12197
|
+
try {
|
|
12198
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
12199
|
+
}
|
|
12200
|
+
finally { if (e_2) throw e_2.error; }
|
|
12201
|
+
}
|
|
12202
|
+
return executeFunction(fn.function, actualParams, contextStack, sourceCodeInfo);
|
|
12166
12203
|
},
|
|
12167
12204
|
Comp: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12168
12205
|
var executeFunction = _a.executeFunction;
|
|
@@ -12188,66 +12225,66 @@ var functionExecutors = {
|
|
|
12188
12225
|
return !executeFunction(fn.function, params, contextStack, sourceCodeInfo);
|
|
12189
12226
|
},
|
|
12190
12227
|
EveryPred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12191
|
-
var
|
|
12228
|
+
var e_3, _b, e_4, _c;
|
|
12192
12229
|
var executeFunction = _a.executeFunction;
|
|
12193
12230
|
try {
|
|
12194
12231
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12195
12232
|
var f = _e.value;
|
|
12196
12233
|
try {
|
|
12197
|
-
for (var params_1 = (
|
|
12234
|
+
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()) {
|
|
12198
12235
|
var param = params_1_1.value;
|
|
12199
12236
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12200
12237
|
if (!result)
|
|
12201
12238
|
return false;
|
|
12202
12239
|
}
|
|
12203
12240
|
}
|
|
12204
|
-
catch (
|
|
12241
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
12205
12242
|
finally {
|
|
12206
12243
|
try {
|
|
12207
12244
|
if (params_1_1 && !params_1_1.done && (_c = params_1.return)) _c.call(params_1);
|
|
12208
12245
|
}
|
|
12209
|
-
finally { if (
|
|
12246
|
+
finally { if (e_4) throw e_4.error; }
|
|
12210
12247
|
}
|
|
12211
12248
|
}
|
|
12212
12249
|
}
|
|
12213
|
-
catch (
|
|
12250
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
12214
12251
|
finally {
|
|
12215
12252
|
try {
|
|
12216
12253
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12217
12254
|
}
|
|
12218
|
-
finally { if (
|
|
12255
|
+
finally { if (e_3) throw e_3.error; }
|
|
12219
12256
|
}
|
|
12220
12257
|
return true;
|
|
12221
12258
|
},
|
|
12222
12259
|
SomePred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12223
|
-
var
|
|
12260
|
+
var e_5, _b, e_6, _c;
|
|
12224
12261
|
var executeFunction = _a.executeFunction;
|
|
12225
12262
|
try {
|
|
12226
12263
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12227
12264
|
var f = _e.value;
|
|
12228
12265
|
try {
|
|
12229
|
-
for (var params_2 = (
|
|
12266
|
+
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()) {
|
|
12230
12267
|
var param = params_2_1.value;
|
|
12231
12268
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12232
12269
|
if (result)
|
|
12233
12270
|
return true;
|
|
12234
12271
|
}
|
|
12235
12272
|
}
|
|
12236
|
-
catch (
|
|
12273
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
12237
12274
|
finally {
|
|
12238
12275
|
try {
|
|
12239
12276
|
if (params_2_1 && !params_2_1.done && (_c = params_2.return)) _c.call(params_2);
|
|
12240
12277
|
}
|
|
12241
|
-
finally { if (
|
|
12278
|
+
finally { if (e_6) throw e_6.error; }
|
|
12242
12279
|
}
|
|
12243
12280
|
}
|
|
12244
12281
|
}
|
|
12245
|
-
catch (
|
|
12282
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
12246
12283
|
finally {
|
|
12247
12284
|
try {
|
|
12248
12285
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12249
12286
|
}
|
|
12250
|
-
finally { if (
|
|
12287
|
+
finally { if (e_5) throw e_5.error; }
|
|
12251
12288
|
}
|
|
12252
12289
|
return false;
|
|
12253
12290
|
},
|
|
@@ -12320,6 +12357,9 @@ function evaluateString(node) {
|
|
|
12320
12357
|
}
|
|
12321
12358
|
function evaluateReservedSymbol(node) {
|
|
12322
12359
|
var reservedName = node[1];
|
|
12360
|
+
if (!['true', 'false', 'null'].includes(reservedName)) {
|
|
12361
|
+
throw new LitsError("Reserved symbol ".concat(reservedName, " cannot be evaluated"), node[2]);
|
|
12362
|
+
}
|
|
12323
12363
|
var value = reservedSymbolRecord[reservedName];
|
|
12324
12364
|
return asNonUndefined(value, node[2]);
|
|
12325
12365
|
}
|
|
@@ -12327,7 +12367,8 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12327
12367
|
var sourceCodeInfo = node[2];
|
|
12328
12368
|
var paramNodes = node[1][1];
|
|
12329
12369
|
var params = [];
|
|
12330
|
-
|
|
12370
|
+
var placeholders = [];
|
|
12371
|
+
paramNodes.forEach(function (paramNode, index) {
|
|
12331
12372
|
if (isSpreadNode(paramNode)) {
|
|
12332
12373
|
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
12333
12374
|
if (Array.isArray(spreadValue)) {
|
|
@@ -12337,12 +12378,27 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12337
12378
|
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
12338
12379
|
}
|
|
12339
12380
|
}
|
|
12381
|
+
else if (paramNode[0] === NodeTypes.ReservedSymbol && paramNode[1] === '_') {
|
|
12382
|
+
placeholders.push(index);
|
|
12383
|
+
}
|
|
12340
12384
|
else {
|
|
12341
12385
|
params.push(evaluateNode(paramNode, contextStack));
|
|
12342
12386
|
}
|
|
12343
12387
|
});
|
|
12344
12388
|
if (isNormalExpressionNodeWithName(node)) {
|
|
12345
12389
|
var nameSymbol = node[1][0];
|
|
12390
|
+
if (placeholders.length > 0) {
|
|
12391
|
+
var fn = evaluateNode(nameSymbol, contextStack);
|
|
12392
|
+
var partialFunction = {
|
|
12393
|
+
'^^fn^^': true,
|
|
12394
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12395
|
+
'functionType': 'Partial',
|
|
12396
|
+
params: params,
|
|
12397
|
+
placeholders: placeholders,
|
|
12398
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12399
|
+
};
|
|
12400
|
+
return partialFunction;
|
|
12401
|
+
}
|
|
12346
12402
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
12347
12403
|
var type = nameSymbol[1];
|
|
12348
12404
|
var normalExpression = builtin.allNormalExpressions[type];
|
|
@@ -12359,6 +12415,17 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12359
12415
|
else {
|
|
12360
12416
|
var fnNode = node[1][0];
|
|
12361
12417
|
var fn = asFunctionLike(evaluateNode(fnNode, contextStack), sourceCodeInfo);
|
|
12418
|
+
if (placeholders.length > 0) {
|
|
12419
|
+
var partialFunction = {
|
|
12420
|
+
'^^fn^^': true,
|
|
12421
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12422
|
+
'functionType': 'Partial',
|
|
12423
|
+
params: params,
|
|
12424
|
+
placeholders: placeholders,
|
|
12425
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12426
|
+
};
|
|
12427
|
+
return partialFunction;
|
|
12428
|
+
}
|
|
12362
12429
|
return executeFunction(fn, params, contextStack, sourceCodeInfo);
|
|
12363
12430
|
}
|
|
12364
12431
|
}
|
|
@@ -12664,6 +12731,7 @@ var binaryOperators = [
|
|
|
12664
12731
|
'&&', // logical AND
|
|
12665
12732
|
'||', // logical OR
|
|
12666
12733
|
'??', // nullish coalescing
|
|
12734
|
+
'|>', // pipe
|
|
12667
12735
|
];
|
|
12668
12736
|
var otherOperators = [
|
|
12669
12737
|
'->', // lambda
|
|
@@ -12842,21 +12910,30 @@ var tokenizeNumber = function (input, position) {
|
|
|
12842
12910
|
var char = input[i];
|
|
12843
12911
|
if (char === '_') {
|
|
12844
12912
|
if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
|
|
12845
|
-
|
|
12913
|
+
if (i === start) {
|
|
12914
|
+
return NO_MATCH;
|
|
12915
|
+
}
|
|
12916
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12846
12917
|
}
|
|
12847
12918
|
}
|
|
12848
12919
|
else if (char === '.') {
|
|
12849
|
-
if (i === start
|
|
12920
|
+
if (i === start) {
|
|
12850
12921
|
return NO_MATCH;
|
|
12851
12922
|
}
|
|
12923
|
+
if (hasDecimalPoint || hasExponent) {
|
|
12924
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12925
|
+
}
|
|
12852
12926
|
hasDecimalPoint = true;
|
|
12853
12927
|
}
|
|
12854
12928
|
else if (char === 'e' || char === 'E') {
|
|
12855
|
-
if (i === start
|
|
12929
|
+
if (i === start) {
|
|
12856
12930
|
return NO_MATCH;
|
|
12857
12931
|
}
|
|
12932
|
+
if (hasExponent) {
|
|
12933
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12934
|
+
}
|
|
12858
12935
|
if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
|
|
12859
|
-
|
|
12936
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12860
12937
|
}
|
|
12861
12938
|
if (input[i + 1] === '+' || input[i + 1] === '-') {
|
|
12862
12939
|
i += 1;
|
|
@@ -12876,7 +12953,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
12876
12953
|
}
|
|
12877
12954
|
var nextChar = input[i];
|
|
12878
12955
|
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
12879
|
-
|
|
12956
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12880
12957
|
}
|
|
12881
12958
|
return [length, ['Number', input.substring(position, i)]];
|
|
12882
12959
|
};
|
|
@@ -13042,10 +13119,10 @@ function tokenize(input, debug, filePath) {
|
|
|
13042
13119
|
hasDebugData: debug,
|
|
13043
13120
|
};
|
|
13044
13121
|
while (position < input.length) {
|
|
13045
|
-
var tokenDescriptor = getCurrentToken(input, position);
|
|
13046
13122
|
var sourceCodeInfo = debug
|
|
13047
13123
|
? createSourceCodeInfo(input, position, filePath)
|
|
13048
13124
|
: undefined;
|
|
13125
|
+
var tokenDescriptor = getCurrentToken(input, position);
|
|
13049
13126
|
if (!tokenDescriptor) {
|
|
13050
13127
|
throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
|
|
13051
13128
|
}
|
|
@@ -13155,9 +13232,6 @@ function isOperatorToken(token, operatorName) {
|
|
|
13155
13232
|
}
|
|
13156
13233
|
function assertOperatorToken(token, operatorName) {
|
|
13157
13234
|
if (!isOperatorToken(token, operatorName)) {
|
|
13158
|
-
if (operatorName) {
|
|
13159
|
-
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
|
|
13160
|
-
}
|
|
13161
13235
|
throwUnexpectedToken('Operator', operatorName, token);
|
|
13162
13236
|
}
|
|
13163
13237
|
}
|
|
@@ -13227,8 +13301,8 @@ function isA_BinaryOperatorToken(token) {
|
|
|
13227
13301
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
|
|
13228
13302
|
}
|
|
13229
13303
|
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
13230
|
-
var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
|
|
13231
|
-
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual[2]);
|
|
13304
|
+
var actualOutput = actual ? "".concat(actual[0], " '").concat(actual[1], "'") : 'end of input';
|
|
13305
|
+
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual === null || actual === void 0 ? void 0 : actual[2]);
|
|
13232
13306
|
}
|
|
13233
13307
|
|
|
13234
13308
|
function minifyTokenStream(tokenStream, _a) {
|
|
@@ -13257,8 +13331,8 @@ function untokenize(tokenStream) {
|
|
|
13257
13331
|
}, '');
|
|
13258
13332
|
}
|
|
13259
13333
|
|
|
13260
|
-
var exponentiationPrecedence =
|
|
13261
|
-
var binaryFunctionalOperatorPrecedence =
|
|
13334
|
+
var exponentiationPrecedence = 11;
|
|
13335
|
+
var binaryFunctionalOperatorPrecedence = 2;
|
|
13262
13336
|
var placeholderRegexp = /^\$([1-9]\d?)?$/;
|
|
13263
13337
|
function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
13264
13338
|
if (sourceCodeInfo) {
|
|
@@ -13273,38 +13347,40 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13273
13347
|
case '*': // multiplication
|
|
13274
13348
|
case '/': // division
|
|
13275
13349
|
case '%': // remainder
|
|
13276
|
-
return
|
|
13350
|
+
return 10;
|
|
13277
13351
|
case '+': // addition
|
|
13278
13352
|
case '-': // subtraction
|
|
13279
|
-
return
|
|
13353
|
+
return 9;
|
|
13280
13354
|
case '<<': // left shift
|
|
13281
13355
|
case '>>': // signed right shift
|
|
13282
13356
|
case '>>>': // unsigned right shift
|
|
13283
|
-
return
|
|
13357
|
+
return 8;
|
|
13284
13358
|
case '++': // string concatenation
|
|
13285
|
-
return
|
|
13359
|
+
return 7;
|
|
13286
13360
|
case '<': // less than
|
|
13287
13361
|
case '<=': // less than or equal
|
|
13288
13362
|
case '≤': // less than or equal
|
|
13289
13363
|
case '>': // greater than
|
|
13290
13364
|
case '>=': // greater than or equal
|
|
13291
13365
|
case '≥': // greater than or equal
|
|
13292
|
-
return
|
|
13366
|
+
return 6;
|
|
13293
13367
|
case '=': // equal
|
|
13294
13368
|
case '!=': // not equal
|
|
13295
13369
|
case '≠': // not equal
|
|
13296
13370
|
case '~': // approximate
|
|
13297
13371
|
case '≈': // approximate
|
|
13298
|
-
return
|
|
13372
|
+
return 5;
|
|
13299
13373
|
case '&': // bitwise AND
|
|
13300
13374
|
case 'xor': // bitwise XOR
|
|
13301
13375
|
case '|': // bitwise OR
|
|
13302
|
-
return
|
|
13376
|
+
return 4;
|
|
13303
13377
|
case '&&': // logical AND
|
|
13304
13378
|
case '||': // logical OR
|
|
13305
13379
|
case '??': // nullish coalescing
|
|
13306
|
-
return
|
|
13307
|
-
|
|
13380
|
+
return 3;
|
|
13381
|
+
case '|>': // pipe
|
|
13382
|
+
return 1;
|
|
13383
|
+
// leave room for binaryFunctionalOperatorPrecedence = 2
|
|
13308
13384
|
/* v8 ignore next 2 */
|
|
13309
13385
|
default:
|
|
13310
13386
|
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
@@ -13348,6 +13424,7 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13348
13424
|
case '|':
|
|
13349
13425
|
case '~':
|
|
13350
13426
|
case '≈':
|
|
13427
|
+
case '|>':
|
|
13351
13428
|
return createNamedNormalExpressionNode(symbolNode, [left, right], sourceCodeInfo);
|
|
13352
13429
|
case '&&':
|
|
13353
13430
|
case '||':
|
|
@@ -13373,6 +13450,11 @@ var Parser = /** @class */ (function () {
|
|
|
13373
13450
|
Parser.prototype.peek = function () {
|
|
13374
13451
|
return this.tokenStream.tokens[this.parseState.position];
|
|
13375
13452
|
};
|
|
13453
|
+
Parser.prototype.peekSourceCodeInfo = function () {
|
|
13454
|
+
var _a;
|
|
13455
|
+
var currentToken = this.peek();
|
|
13456
|
+
return currentToken ? currentToken[2] : (_a = this.tokenStream.tokens.at(-1)) === null || _a === void 0 ? void 0 : _a[2];
|
|
13457
|
+
};
|
|
13376
13458
|
Parser.prototype.peekAhead = function (count) {
|
|
13377
13459
|
return this.tokenStream.tokens[this.parseState.position + count];
|
|
13378
13460
|
};
|
|
@@ -13388,7 +13470,7 @@ var Parser = /** @class */ (function () {
|
|
|
13388
13470
|
}
|
|
13389
13471
|
else {
|
|
13390
13472
|
if (!this.isAtEnd()) {
|
|
13391
|
-
throw new LitsError('Expected ;', this.
|
|
13473
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13392
13474
|
}
|
|
13393
13475
|
}
|
|
13394
13476
|
}
|
|
@@ -13477,15 +13559,21 @@ var Parser = /** @class */ (function () {
|
|
|
13477
13559
|
}
|
|
13478
13560
|
return left;
|
|
13479
13561
|
};
|
|
13562
|
+
Parser.prototype.asToken = function (token) {
|
|
13563
|
+
if (!token) {
|
|
13564
|
+
throw new LitsError('Unexpected end of input', this.peekSourceCodeInfo());
|
|
13565
|
+
}
|
|
13566
|
+
return token;
|
|
13567
|
+
};
|
|
13480
13568
|
Parser.prototype.parseOperand = function () {
|
|
13481
13569
|
var operand = this.parseOperandPart();
|
|
13482
13570
|
var token = this.peek();
|
|
13483
13571
|
while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
13484
13572
|
if (token[1] === '.') {
|
|
13485
13573
|
this.advance();
|
|
13486
|
-
var symbolToken = this.peek();
|
|
13574
|
+
var symbolToken = this.asToken(this.peek());
|
|
13487
13575
|
if (!isSymbolToken(symbolToken)) {
|
|
13488
|
-
throw new LitsError('Expected symbol', this.
|
|
13576
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13489
13577
|
}
|
|
13490
13578
|
var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
|
|
13491
13579
|
operand = createAccessorNode(operand, stringNode, token[2]);
|
|
@@ -13496,7 +13584,7 @@ var Parser = /** @class */ (function () {
|
|
|
13496
13584
|
this.advance();
|
|
13497
13585
|
var expression = this.parseExpression();
|
|
13498
13586
|
if (!isRBracketToken(this.peek())) {
|
|
13499
|
-
throw new LitsError('Expected closing bracket', this.
|
|
13587
|
+
throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
|
|
13500
13588
|
}
|
|
13501
13589
|
operand = createAccessorNode(operand, expression, token[2]);
|
|
13502
13590
|
this.advance();
|
|
@@ -13510,7 +13598,7 @@ var Parser = /** @class */ (function () {
|
|
|
13510
13598
|
return operand;
|
|
13511
13599
|
};
|
|
13512
13600
|
Parser.prototype.parseOperandPart = function () {
|
|
13513
|
-
var token = this.peek();
|
|
13601
|
+
var token = this.asToken(this.peek());
|
|
13514
13602
|
// Parentheses
|
|
13515
13603
|
if (isLParenToken(token)) {
|
|
13516
13604
|
var positionBefore = this.parseState.position;
|
|
@@ -13522,7 +13610,7 @@ var Parser = /** @class */ (function () {
|
|
|
13522
13610
|
this.advance();
|
|
13523
13611
|
var expression = this.parseExpression();
|
|
13524
13612
|
if (!isRParenToken(this.peek())) {
|
|
13525
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13613
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13526
13614
|
}
|
|
13527
13615
|
this.advance();
|
|
13528
13616
|
return expression;
|
|
@@ -13582,7 +13670,7 @@ var Parser = /** @class */ (function () {
|
|
|
13582
13670
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
13583
13671
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13584
13672
|
this.advance();
|
|
13585
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13673
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13586
13674
|
}
|
|
13587
13675
|
else {
|
|
13588
13676
|
var token = this.peek();
|
|
@@ -13598,7 +13686,7 @@ var Parser = /** @class */ (function () {
|
|
|
13598
13686
|
this.advance();
|
|
13599
13687
|
}
|
|
13600
13688
|
else {
|
|
13601
|
-
throw new LitsError('Expected key to be a symbol or a string', this.
|
|
13689
|
+
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
13602
13690
|
}
|
|
13603
13691
|
assertOperatorToken(this.peek(), ':=');
|
|
13604
13692
|
this.advance();
|
|
@@ -13606,7 +13694,7 @@ var Parser = /** @class */ (function () {
|
|
|
13606
13694
|
}
|
|
13607
13695
|
var nextToken = this.peek();
|
|
13608
13696
|
if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
13609
|
-
throw new LitsError('Expected comma or closing brace', this.
|
|
13697
|
+
throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
|
|
13610
13698
|
}
|
|
13611
13699
|
if (isOperatorToken(nextToken, ',')) {
|
|
13612
13700
|
this.advance();
|
|
@@ -13623,14 +13711,14 @@ var Parser = /** @class */ (function () {
|
|
|
13623
13711
|
while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
|
|
13624
13712
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13625
13713
|
this.advance();
|
|
13626
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13714
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13627
13715
|
}
|
|
13628
13716
|
else {
|
|
13629
13717
|
params.push(this.parseExpression());
|
|
13630
13718
|
}
|
|
13631
13719
|
var nextToken = this.peek();
|
|
13632
13720
|
if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
|
|
13633
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13721
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13634
13722
|
}
|
|
13635
13723
|
if (isOperatorToken(nextToken, ',')) {
|
|
13636
13724
|
this.advance();
|
|
@@ -13641,26 +13729,27 @@ var Parser = /** @class */ (function () {
|
|
|
13641
13729
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
|
|
13642
13730
|
};
|
|
13643
13731
|
Parser.prototype.parseFunctionCall = function (symbol) {
|
|
13732
|
+
var _a;
|
|
13644
13733
|
this.advance();
|
|
13645
13734
|
var params = [];
|
|
13646
13735
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
13647
13736
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13648
13737
|
this.advance();
|
|
13649
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13738
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13650
13739
|
}
|
|
13651
13740
|
else {
|
|
13652
13741
|
params.push(this.parseExpression());
|
|
13653
13742
|
}
|
|
13654
13743
|
var nextToken = this.peek();
|
|
13655
13744
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
13656
|
-
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
13745
|
+
throw new LitsError('Expected comma or closing parenthesis', (_a = this.peek()) === null || _a === void 0 ? void 0 : _a[2]);
|
|
13657
13746
|
}
|
|
13658
13747
|
if (isOperatorToken(nextToken, ',')) {
|
|
13659
13748
|
this.advance();
|
|
13660
13749
|
}
|
|
13661
13750
|
}
|
|
13662
13751
|
if (!isRParenToken(this.peek())) {
|
|
13663
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13752
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13664
13753
|
}
|
|
13665
13754
|
this.advance();
|
|
13666
13755
|
if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
|
|
@@ -13690,14 +13779,14 @@ var Parser = /** @class */ (function () {
|
|
|
13690
13779
|
if (params.length !== 1) {
|
|
13691
13780
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13692
13781
|
}
|
|
13693
|
-
var
|
|
13782
|
+
var _b = __read(params, 1), param = _b[0];
|
|
13694
13783
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13695
13784
|
}
|
|
13696
13785
|
case specialExpressionTypes.throw: {
|
|
13697
13786
|
if (params.length !== 1) {
|
|
13698
13787
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13699
13788
|
}
|
|
13700
|
-
var
|
|
13789
|
+
var _c = __read(params, 1), param = _c[0];
|
|
13701
13790
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13702
13791
|
}
|
|
13703
13792
|
case specialExpressionTypes['0_fn']:
|
|
@@ -13717,7 +13806,7 @@ var Parser = /** @class */ (function () {
|
|
|
13717
13806
|
}
|
|
13718
13807
|
};
|
|
13719
13808
|
Parser.prototype.parseLambdaFunction = function () {
|
|
13720
|
-
var firstToken = this.peek();
|
|
13809
|
+
var firstToken = this.asToken(this.peek());
|
|
13721
13810
|
if (isLParenToken(firstToken)
|
|
13722
13811
|
&& isSymbolToken(this.peekAhead(1))
|
|
13723
13812
|
&& isOperatorToken(this.peekAhead(2), '->')) {
|
|
@@ -13751,7 +13840,7 @@ var Parser = /** @class */ (function () {
|
|
|
13751
13840
|
var functionArguments = [];
|
|
13752
13841
|
while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13753
13842
|
if (rest) {
|
|
13754
|
-
throw new LitsError('Rest argument must be last', this.
|
|
13843
|
+
throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
|
|
13755
13844
|
}
|
|
13756
13845
|
var bindingTarget = this.parseBindingTarget();
|
|
13757
13846
|
if (bindingTarget[1][1] !== undefined) {
|
|
@@ -13761,25 +13850,25 @@ var Parser = /** @class */ (function () {
|
|
|
13761
13850
|
rest = true;
|
|
13762
13851
|
}
|
|
13763
13852
|
if (defaults && !bindingTarget[1][1]) {
|
|
13764
|
-
throw new LitsError('Default arguments must be last', this.
|
|
13853
|
+
throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
|
|
13765
13854
|
}
|
|
13766
13855
|
functionArguments.push(bindingTarget);
|
|
13767
13856
|
if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13768
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13857
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13769
13858
|
}
|
|
13770
13859
|
if (isOperatorToken(this.peek(), ',')) {
|
|
13771
13860
|
this.advance();
|
|
13772
13861
|
}
|
|
13773
13862
|
}
|
|
13774
13863
|
if (!isRParenToken(this.peek())) {
|
|
13775
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13864
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13776
13865
|
}
|
|
13777
13866
|
this.advance();
|
|
13778
13867
|
return functionArguments;
|
|
13779
13868
|
};
|
|
13780
13869
|
Parser.prototype.parseShorthandLamdaFunction = function () {
|
|
13781
13870
|
var _a;
|
|
13782
|
-
var firstToken = this.peek();
|
|
13871
|
+
var firstToken = this.asToken(this.peek());
|
|
13783
13872
|
this.advance();
|
|
13784
13873
|
var startPos = this.parseState.position;
|
|
13785
13874
|
var exprNode = this.parseExpression();
|
|
@@ -13837,7 +13926,7 @@ var Parser = /** @class */ (function () {
|
|
|
13837
13926
|
}
|
|
13838
13927
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13839
13928
|
if (requireDefaultValue && !defaultValue) {
|
|
13840
|
-
throw new LitsError('Expected assignment', this.
|
|
13929
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13841
13930
|
}
|
|
13842
13931
|
return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
|
|
13843
13932
|
}
|
|
@@ -13849,7 +13938,7 @@ var Parser = /** @class */ (function () {
|
|
|
13849
13938
|
this.advance();
|
|
13850
13939
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13851
13940
|
if (isOperatorToken(this.peek(), ':=')) {
|
|
13852
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13941
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13853
13942
|
}
|
|
13854
13943
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
13855
13944
|
}
|
|
@@ -13857,7 +13946,7 @@ var Parser = /** @class */ (function () {
|
|
|
13857
13946
|
if (isLBracketToken(firstToken)) {
|
|
13858
13947
|
this.advance();
|
|
13859
13948
|
var elements = [];
|
|
13860
|
-
var token = this.peek();
|
|
13949
|
+
var token = this.asToken(this.peek());
|
|
13861
13950
|
var rest = false;
|
|
13862
13951
|
while (!isRBracketToken(token)) {
|
|
13863
13952
|
if (rest) {
|
|
@@ -13866,7 +13955,7 @@ var Parser = /** @class */ (function () {
|
|
|
13866
13955
|
if (isOperatorToken(token, ',')) {
|
|
13867
13956
|
elements.push(null);
|
|
13868
13957
|
this.advance();
|
|
13869
|
-
token = this.peek();
|
|
13958
|
+
token = this.asToken(this.peek());
|
|
13870
13959
|
continue;
|
|
13871
13960
|
}
|
|
13872
13961
|
var target = this.parseBindingTarget();
|
|
@@ -13874,17 +13963,17 @@ var Parser = /** @class */ (function () {
|
|
|
13874
13963
|
rest = true;
|
|
13875
13964
|
}
|
|
13876
13965
|
elements.push(target);
|
|
13877
|
-
token = this.peek();
|
|
13966
|
+
token = this.asToken(this.peek());
|
|
13878
13967
|
if (!isRBracketToken(token)) {
|
|
13879
13968
|
assertOperatorToken(token, ',');
|
|
13880
13969
|
this.advance();
|
|
13881
13970
|
}
|
|
13882
|
-
token = this.peek();
|
|
13971
|
+
token = this.asToken(this.peek());
|
|
13883
13972
|
}
|
|
13884
13973
|
this.advance();
|
|
13885
13974
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13886
13975
|
if (requireDefaultValue && !defaultValue) {
|
|
13887
|
-
throw new LitsError('Expected assignment', this.
|
|
13976
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13888
13977
|
}
|
|
13889
13978
|
return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
|
|
13890
13979
|
}
|
|
@@ -13892,7 +13981,7 @@ var Parser = /** @class */ (function () {
|
|
|
13892
13981
|
if (isLBraceToken(firstToken)) {
|
|
13893
13982
|
this.advance();
|
|
13894
13983
|
var elements = {};
|
|
13895
|
-
var token = this.peek();
|
|
13984
|
+
var token = this.asToken(this.peek());
|
|
13896
13985
|
var rest = false;
|
|
13897
13986
|
while (!isRBraceToken(token)) {
|
|
13898
13987
|
if (rest) {
|
|
@@ -13903,7 +13992,7 @@ var Parser = /** @class */ (function () {
|
|
|
13903
13992
|
this.advance();
|
|
13904
13993
|
}
|
|
13905
13994
|
var key = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13906
|
-
token = this.peek();
|
|
13995
|
+
token = this.asToken(this.peek());
|
|
13907
13996
|
if (isReservedSymbolToken(token, 'as')) {
|
|
13908
13997
|
if (rest) {
|
|
13909
13998
|
throw new LitsError('Rest argument can not have alias', token[2]);
|
|
@@ -13920,7 +14009,7 @@ var Parser = /** @class */ (function () {
|
|
|
13920
14009
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
13921
14010
|
}
|
|
13922
14011
|
if (rest && isOperatorToken(this.peek(), ':=')) {
|
|
13923
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
14012
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13924
14013
|
}
|
|
13925
14014
|
elements[key[1]] = rest
|
|
13926
14015
|
? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
|
|
@@ -13933,17 +14022,17 @@ var Parser = /** @class */ (function () {
|
|
|
13933
14022
|
assertOperatorToken(this.peek(), ',');
|
|
13934
14023
|
this.advance();
|
|
13935
14024
|
}
|
|
13936
|
-
token = this.peek();
|
|
14025
|
+
token = this.asToken(this.peek());
|
|
13937
14026
|
}
|
|
13938
14027
|
this.advance();
|
|
13939
|
-
token = this.peek();
|
|
14028
|
+
token = this.asToken(this.peek());
|
|
13940
14029
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13941
14030
|
if (requireDefaultValue && !defaultValue) {
|
|
13942
14031
|
throw new LitsError('Expected assignment', token[2]);
|
|
13943
14032
|
}
|
|
13944
14033
|
return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
|
|
13945
14034
|
}
|
|
13946
|
-
throw new LitsError('Expected symbol', this.
|
|
14035
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13947
14036
|
};
|
|
13948
14037
|
Parser.prototype.parseLet = function (token, optionalSemicolon) {
|
|
13949
14038
|
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
@@ -13966,7 +14055,7 @@ var Parser = /** @class */ (function () {
|
|
|
13966
14055
|
this.advance();
|
|
13967
14056
|
}
|
|
13968
14057
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13969
|
-
throw new LitsError('Expected ;', this.
|
|
14058
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13970
14059
|
}
|
|
13971
14060
|
}
|
|
13972
14061
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -13990,7 +14079,7 @@ var Parser = /** @class */ (function () {
|
|
|
13990
14079
|
token = this.peek();
|
|
13991
14080
|
}
|
|
13992
14081
|
if (bindingNodes.length === 0) {
|
|
13993
|
-
throw new LitsError('Expected binding', this.
|
|
14082
|
+
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
13994
14083
|
}
|
|
13995
14084
|
assertSymbolToken(token, 'do');
|
|
13996
14085
|
this.advance();
|
|
@@ -14001,7 +14090,7 @@ var Parser = /** @class */ (function () {
|
|
|
14001
14090
|
this.advance();
|
|
14002
14091
|
}
|
|
14003
14092
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14004
|
-
throw new LitsError('Expected ;', this.
|
|
14093
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14005
14094
|
}
|
|
14006
14095
|
}
|
|
14007
14096
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14017,7 +14106,7 @@ var Parser = /** @class */ (function () {
|
|
|
14017
14106
|
this.advance();
|
|
14018
14107
|
}
|
|
14019
14108
|
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14020
|
-
throw new LitsError('Expected ;', this.
|
|
14109
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14021
14110
|
}
|
|
14022
14111
|
}
|
|
14023
14112
|
var tryExpression = tryExpressions.length === 1
|
|
@@ -14039,7 +14128,7 @@ var Parser = /** @class */ (function () {
|
|
|
14039
14128
|
this.advance();
|
|
14040
14129
|
}
|
|
14041
14130
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14042
|
-
throw new LitsError('Expected ;', this.
|
|
14131
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14043
14132
|
}
|
|
14044
14133
|
}
|
|
14045
14134
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14075,7 +14164,7 @@ var Parser = /** @class */ (function () {
|
|
|
14075
14164
|
this.advance();
|
|
14076
14165
|
}
|
|
14077
14166
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14078
|
-
throw new LitsError('Expected ;', this.
|
|
14167
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14079
14168
|
}
|
|
14080
14169
|
}
|
|
14081
14170
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14089,13 +14178,13 @@ var Parser = /** @class */ (function () {
|
|
|
14089
14178
|
this.advance();
|
|
14090
14179
|
var bindingNode = this.parseBinding();
|
|
14091
14180
|
var modifiers = [];
|
|
14092
|
-
var token = this.peek();
|
|
14181
|
+
var token = this.asToken(this.peek());
|
|
14093
14182
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14094
14183
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14095
14184
|
}
|
|
14096
14185
|
if (isOperatorToken(token, ',')) {
|
|
14097
14186
|
this.advance();
|
|
14098
|
-
token = this.peek();
|
|
14187
|
+
token = this.asToken(this.peek());
|
|
14099
14188
|
}
|
|
14100
14189
|
if (!isSymbolToken(token, 'let')
|
|
14101
14190
|
&& !isReservedSymbolToken(token, 'when')
|
|
@@ -14115,14 +14204,14 @@ var Parser = /** @class */ (function () {
|
|
|
14115
14204
|
throw new LitsError('Duplicate binding', letNode[1][1][2]);
|
|
14116
14205
|
}
|
|
14117
14206
|
letBindings.push(letNode[1][1]);
|
|
14118
|
-
token = this_2.peek();
|
|
14207
|
+
token = this_2.asToken(this_2.peek());
|
|
14119
14208
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14120
14209
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14121
14210
|
}
|
|
14122
14211
|
if (isOperatorToken(token, ',')) {
|
|
14123
14212
|
this_2.advance();
|
|
14124
14213
|
}
|
|
14125
|
-
token = this_2.peek();
|
|
14214
|
+
token = this_2.asToken(this_2.peek());
|
|
14126
14215
|
};
|
|
14127
14216
|
var this_2 = this;
|
|
14128
14217
|
while (isSymbolToken(token, 'let')) {
|
|
@@ -14148,14 +14237,14 @@ var Parser = /** @class */ (function () {
|
|
|
14148
14237
|
modifiers.push('&while');
|
|
14149
14238
|
whileNode = this.parseExpression();
|
|
14150
14239
|
}
|
|
14151
|
-
token = this.peek();
|
|
14240
|
+
token = this.asToken(this.peek());
|
|
14152
14241
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14153
14242
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14154
14243
|
}
|
|
14155
14244
|
if (isOperatorToken(token, ',')) {
|
|
14156
14245
|
this.advance();
|
|
14157
14246
|
}
|
|
14158
|
-
token = this.peek();
|
|
14247
|
+
token = this.asToken(this.peek());
|
|
14159
14248
|
}
|
|
14160
14249
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
|
|
14161
14250
|
throw new LitsError('Expected do or each', token[2]);
|
|
@@ -14192,7 +14281,7 @@ var Parser = /** @class */ (function () {
|
|
|
14192
14281
|
this.advance();
|
|
14193
14282
|
}
|
|
14194
14283
|
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14195
|
-
throw new LitsError('Expected ;', this.
|
|
14284
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14196
14285
|
}
|
|
14197
14286
|
}
|
|
14198
14287
|
var thenExpression = thenExpressions.length === 1
|
|
@@ -14208,7 +14297,7 @@ var Parser = /** @class */ (function () {
|
|
|
14208
14297
|
this.advance();
|
|
14209
14298
|
}
|
|
14210
14299
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14211
|
-
throw new LitsError('Expected ;', this.
|
|
14300
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14212
14301
|
}
|
|
14213
14302
|
}
|
|
14214
14303
|
elseExpression = elseExpressions.length === 1
|
|
@@ -14239,7 +14328,7 @@ var Parser = /** @class */ (function () {
|
|
|
14239
14328
|
this.advance();
|
|
14240
14329
|
}
|
|
14241
14330
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14242
|
-
throw new LitsError('Expected ;', this.
|
|
14331
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14243
14332
|
}
|
|
14244
14333
|
}
|
|
14245
14334
|
var thenExpression = expressions.length === 1
|
|
@@ -14274,7 +14363,7 @@ var Parser = /** @class */ (function () {
|
|
|
14274
14363
|
this.advance();
|
|
14275
14364
|
}
|
|
14276
14365
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14277
|
-
throw new LitsError('Expected ;', this.
|
|
14366
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14278
14367
|
}
|
|
14279
14368
|
}
|
|
14280
14369
|
var thenExpression = expressions.length === 1
|
|
@@ -14301,7 +14390,7 @@ var Parser = /** @class */ (function () {
|
|
|
14301
14390
|
this.advance();
|
|
14302
14391
|
}
|
|
14303
14392
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14304
|
-
throw new LitsError('Expected ;', this.
|
|
14393
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14305
14394
|
}
|
|
14306
14395
|
}
|
|
14307
14396
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14345,7 +14434,7 @@ var Parser = /** @class */ (function () {
|
|
|
14345
14434
|
this.advance();
|
|
14346
14435
|
}
|
|
14347
14436
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14348
|
-
throw new LitsError('Expected ;', this.
|
|
14437
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14349
14438
|
}
|
|
14350
14439
|
}
|
|
14351
14440
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14356,7 +14445,7 @@ var Parser = /** @class */ (function () {
|
|
|
14356
14445
|
]]], token[2]);
|
|
14357
14446
|
}
|
|
14358
14447
|
else {
|
|
14359
|
-
throw new LitsError('Expected let or function', this.
|
|
14448
|
+
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|
|
14360
14449
|
}
|
|
14361
14450
|
};
|
|
14362
14451
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -14381,7 +14470,7 @@ var Parser = /** @class */ (function () {
|
|
|
14381
14470
|
});
|
|
14382
14471
|
};
|
|
14383
14472
|
Parser.prototype.parseSymbol = function () {
|
|
14384
|
-
var token = this.peek();
|
|
14473
|
+
var token = this.asToken(this.peek());
|
|
14385
14474
|
this.advance();
|
|
14386
14475
|
if (!isSymbolToken(token)) {
|
|
14387
14476
|
throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
|
|
@@ -14403,7 +14492,7 @@ var Parser = /** @class */ (function () {
|
|
|
14403
14492
|
return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
|
|
14404
14493
|
};
|
|
14405
14494
|
Parser.prototype.parseNumber = function () {
|
|
14406
|
-
var token = this.peek();
|
|
14495
|
+
var token = this.asToken(this.peek());
|
|
14407
14496
|
this.advance();
|
|
14408
14497
|
var value = token[1];
|
|
14409
14498
|
var negative = value[0] === '-';
|
|
@@ -14411,7 +14500,7 @@ var Parser = /** @class */ (function () {
|
|
|
14411
14500
|
return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
|
|
14412
14501
|
};
|
|
14413
14502
|
Parser.prototype.parseString = function () {
|
|
14414
|
-
var token = this.peek();
|
|
14503
|
+
var token = this.asToken(this.peek());
|
|
14415
14504
|
this.advance();
|
|
14416
14505
|
var value = token[1].substring(1, token[1].length - 1)
|
|
14417
14506
|
.replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
|
|
@@ -14443,7 +14532,7 @@ var Parser = /** @class */ (function () {
|
|
|
14443
14532
|
return withSourceCodeInfo([NodeTypes.String, value], token[2]);
|
|
14444
14533
|
};
|
|
14445
14534
|
Parser.prototype.parseRegexpShorthand = function () {
|
|
14446
|
-
var token = this.peek();
|
|
14535
|
+
var token = this.asToken(this.peek());
|
|
14447
14536
|
this.advance();
|
|
14448
14537
|
var endStringPosition = token[1].lastIndexOf('"');
|
|
14449
14538
|
var regexpString = token[1].substring(2, endStringPosition);
|
|
@@ -14648,6 +14737,11 @@ function getVectorReductionNames(name) {
|
|
|
14648
14737
|
}
|
|
14649
14738
|
var api = {
|
|
14650
14739
|
collection: [
|
|
14740
|
+
'filter',
|
|
14741
|
+
'map',
|
|
14742
|
+
'reduce',
|
|
14743
|
+
'reduce-right',
|
|
14744
|
+
'reductions',
|
|
14651
14745
|
'count',
|
|
14652
14746
|
'get',
|
|
14653
14747
|
'get-in',
|
|
@@ -14677,11 +14771,6 @@ var api = {
|
|
|
14677
14771
|
'shift',
|
|
14678
14772
|
'slice',
|
|
14679
14773
|
'splice',
|
|
14680
|
-
'reductions',
|
|
14681
|
-
'reduce',
|
|
14682
|
-
'reduce-right',
|
|
14683
|
-
'map',
|
|
14684
|
-
'filter',
|
|
14685
14774
|
'position',
|
|
14686
14775
|
'index-of',
|
|
14687
14776
|
'last-index-of',
|
|
@@ -14754,9 +14843,9 @@ var api = {
|
|
|
14754
14843
|
'atanh',
|
|
14755
14844
|
],
|
|
14756
14845
|
functional: [
|
|
14846
|
+
'|>',
|
|
14757
14847
|
'apply',
|
|
14758
14848
|
'identity',
|
|
14759
|
-
'partial',
|
|
14760
14849
|
'comp',
|
|
14761
14850
|
'constantly',
|
|
14762
14851
|
'juxt',
|
|
@@ -15205,7 +15294,6 @@ var arrayReference = {
|
|
|
15205
15294
|
examples: [
|
|
15206
15295
|
'flatten([1, 2, [3, 4], 5])',
|
|
15207
15296
|
"\nlet foo := \"bar\";\nflatten([\n 1,\n \" 2 A \",\n [foo, [4, [\"ABC\"]]],\n 6,\n])",
|
|
15208
|
-
'flatten(12)',
|
|
15209
15297
|
],
|
|
15210
15298
|
noOperatorDocumentation: true,
|
|
15211
15299
|
},
|
|
@@ -15872,6 +15960,142 @@ var bitwiseReference = {
|
|
|
15872
15960
|
};
|
|
15873
15961
|
|
|
15874
15962
|
var collectionReference = {
|
|
15963
|
+
'filter': {
|
|
15964
|
+
title: 'filter',
|
|
15965
|
+
category: 'Collection',
|
|
15966
|
+
linkName: 'filter',
|
|
15967
|
+
returns: {
|
|
15968
|
+
type: 'collection',
|
|
15969
|
+
},
|
|
15970
|
+
args: __assign(__assign({}, getOperatorArgs('collection', 'function')), { coll: {
|
|
15971
|
+
type: 'collection',
|
|
15972
|
+
}, fun: {
|
|
15973
|
+
type: 'function',
|
|
15974
|
+
} }),
|
|
15975
|
+
variants: [
|
|
15976
|
+
{ argumentNames: ['coll', 'fun'] },
|
|
15977
|
+
],
|
|
15978
|
+
description: 'Creates a new collection with all elements that pass the test implemented by $fun.',
|
|
15979
|
+
examples: [
|
|
15980
|
+
"\nfilter(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)",
|
|
15981
|
+
"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)",
|
|
15982
|
+
"\nfilter(\n { a := 1, b := 2 },\n odd?\n)",
|
|
15983
|
+
],
|
|
15984
|
+
},
|
|
15985
|
+
'map': {
|
|
15986
|
+
title: 'map',
|
|
15987
|
+
category: 'Collection',
|
|
15988
|
+
linkName: 'map',
|
|
15989
|
+
returns: {
|
|
15990
|
+
type: 'collection',
|
|
15991
|
+
},
|
|
15992
|
+
args: __assign(__assign({}, getOperatorArgs('collection', 'function')), { colls: {
|
|
15993
|
+
type: 'collection',
|
|
15994
|
+
rest: true,
|
|
15995
|
+
description: 'At least one.',
|
|
15996
|
+
}, fun: {
|
|
15997
|
+
type: 'function',
|
|
15998
|
+
} }),
|
|
15999
|
+
variants: [
|
|
16000
|
+
{ argumentNames: ['colls', 'fun'] },
|
|
16001
|
+
],
|
|
16002
|
+
description: 'Creates a new collection populated with the results of calling $fun on every element in $colls.',
|
|
16003
|
+
examples: [
|
|
16004
|
+
'[1, 2, 3] map -',
|
|
16005
|
+
'[1, 2, 3] map -> -($)',
|
|
16006
|
+
'map(["Albert", "Mojir", 42], str)',
|
|
16007
|
+
'map([1, 2, 3], inc)',
|
|
16008
|
+
'map([1, 2, 3], [1, 10, 100], *)',
|
|
16009
|
+
'map({ a := 1, b := 2 }, inc)',
|
|
16010
|
+
'map({ a := 1, b := 2 }, { a := 10, b := 20 }, +)',
|
|
16011
|
+
],
|
|
16012
|
+
},
|
|
16013
|
+
'reduce': {
|
|
16014
|
+
title: 'reduce',
|
|
16015
|
+
category: 'Collection',
|
|
16016
|
+
linkName: 'reduce',
|
|
16017
|
+
returns: {
|
|
16018
|
+
type: 'any',
|
|
16019
|
+
},
|
|
16020
|
+
args: {
|
|
16021
|
+
fun: {
|
|
16022
|
+
type: 'function',
|
|
16023
|
+
},
|
|
16024
|
+
coll: {
|
|
16025
|
+
type: 'collection',
|
|
16026
|
+
},
|
|
16027
|
+
initial: {
|
|
16028
|
+
type: 'any',
|
|
16029
|
+
},
|
|
16030
|
+
},
|
|
16031
|
+
variants: [
|
|
16032
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16033
|
+
],
|
|
16034
|
+
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.',
|
|
16035
|
+
examples: [
|
|
16036
|
+
'reduce([1, 2, 3], +, 0)',
|
|
16037
|
+
'reduce([], +, 0)',
|
|
16038
|
+
'reduce({ a := 1, b := 2 }, +, 0)',
|
|
16039
|
+
"\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)",
|
|
16040
|
+
],
|
|
16041
|
+
},
|
|
16042
|
+
'reduce-right': {
|
|
16043
|
+
title: 'reduce-right',
|
|
16044
|
+
category: 'Collection',
|
|
16045
|
+
linkName: 'reduce-right',
|
|
16046
|
+
returns: {
|
|
16047
|
+
type: 'any',
|
|
16048
|
+
},
|
|
16049
|
+
args: {
|
|
16050
|
+
fun: {
|
|
16051
|
+
type: 'function',
|
|
16052
|
+
},
|
|
16053
|
+
coll: {
|
|
16054
|
+
type: 'collection',
|
|
16055
|
+
},
|
|
16056
|
+
initial: {
|
|
16057
|
+
type: 'any',
|
|
16058
|
+
},
|
|
16059
|
+
},
|
|
16060
|
+
variants: [
|
|
16061
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16062
|
+
],
|
|
16063
|
+
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.',
|
|
16064
|
+
examples: [
|
|
16065
|
+
'reduce-right(["A", "B", "C"], str, "")',
|
|
16066
|
+
'reduce-right({ a := 1, b := 2 }, +, 0)',
|
|
16067
|
+
],
|
|
16068
|
+
},
|
|
16069
|
+
'reductions': {
|
|
16070
|
+
title: 'reductions',
|
|
16071
|
+
category: 'Collection',
|
|
16072
|
+
linkName: 'reductions',
|
|
16073
|
+
returns: {
|
|
16074
|
+
type: 'any',
|
|
16075
|
+
},
|
|
16076
|
+
args: {
|
|
16077
|
+
fun: {
|
|
16078
|
+
type: 'function',
|
|
16079
|
+
},
|
|
16080
|
+
coll: {
|
|
16081
|
+
type: 'collection',
|
|
16082
|
+
},
|
|
16083
|
+
initial: {
|
|
16084
|
+
type: 'any',
|
|
16085
|
+
},
|
|
16086
|
+
},
|
|
16087
|
+
variants: [
|
|
16088
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16089
|
+
],
|
|
16090
|
+
description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.',
|
|
16091
|
+
examples: [
|
|
16092
|
+
'reductions([1, 2, 3], +, 0)',
|
|
16093
|
+
'reductions([1, 2, 3], +, 10)',
|
|
16094
|
+
'reductions([], +, 0)',
|
|
16095
|
+
'reductions({ a := 1, b := 2 }, +, 0)',
|
|
16096
|
+
"\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)",
|
|
16097
|
+
],
|
|
16098
|
+
},
|
|
15875
16099
|
'count': {
|
|
15876
16100
|
title: 'count',
|
|
15877
16101
|
category: 'Collection',
|
|
@@ -16255,6 +16479,23 @@ var collectionReference = {
|
|
|
16255
16479
|
};
|
|
16256
16480
|
|
|
16257
16481
|
var functionalReference = {
|
|
16482
|
+
'|>': {
|
|
16483
|
+
title: '|>',
|
|
16484
|
+
category: 'Functional',
|
|
16485
|
+
linkName: '-or-gt',
|
|
16486
|
+
returns: {
|
|
16487
|
+
type: 'any',
|
|
16488
|
+
},
|
|
16489
|
+
args: __assign({}, getOperatorArgs('any', 'function')),
|
|
16490
|
+
variants: [
|
|
16491
|
+
{ argumentNames: ['a', 'b'] },
|
|
16492
|
+
],
|
|
16493
|
+
description: 'Takes a value $a and a function $b, and returns the result of applying $b to $a.',
|
|
16494
|
+
examples: [
|
|
16495
|
+
"\n1 |> inc |> inc",
|
|
16496
|
+
"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)",
|
|
16497
|
+
],
|
|
16498
|
+
},
|
|
16258
16499
|
'apply': {
|
|
16259
16500
|
title: 'apply',
|
|
16260
16501
|
category: 'Functional',
|
|
@@ -16295,33 +16536,6 @@ var functionalReference = {
|
|
|
16295
16536
|
description: 'Returns $x.',
|
|
16296
16537
|
examples: ['identity(1)', 'identity("Albert")', 'identity({ a := 1 })', 'identity(null)'],
|
|
16297
16538
|
},
|
|
16298
|
-
'partial': {
|
|
16299
|
-
title: 'partial',
|
|
16300
|
-
category: 'Functional',
|
|
16301
|
-
linkName: 'partial',
|
|
16302
|
-
returns: {
|
|
16303
|
-
type: 'function',
|
|
16304
|
-
},
|
|
16305
|
-
args: {
|
|
16306
|
-
fun: {
|
|
16307
|
-
type: 'function',
|
|
16308
|
-
},
|
|
16309
|
-
args: {
|
|
16310
|
-
type: 'any',
|
|
16311
|
-
rest: true,
|
|
16312
|
-
},
|
|
16313
|
-
},
|
|
16314
|
-
variants: [
|
|
16315
|
-
{ argumentNames: ['fun', 'args'] },
|
|
16316
|
-
],
|
|
16317
|
-
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)`.",
|
|
16318
|
-
examples: [
|
|
16319
|
-
'partial(+, 100)',
|
|
16320
|
-
"\nlet plusMany := partial(+, 100, 1000);\nplusMany(1, 10)",
|
|
16321
|
-
"\nlet addHundred := partial(+, 100);\naddHundred(10)",
|
|
16322
|
-
],
|
|
16323
|
-
noOperatorDocumentation: true,
|
|
16324
|
-
},
|
|
16325
16539
|
'comp': {
|
|
16326
16540
|
title: 'comp',
|
|
16327
16541
|
category: 'Functional',
|
|
@@ -24633,134 +24847,6 @@ var sequenceReference = {
|
|
|
24633
24847
|
'splice("Albert", 2, 2, "fo")',
|
|
24634
24848
|
],
|
|
24635
24849
|
},
|
|
24636
|
-
'reductions': {
|
|
24637
|
-
title: 'reductions',
|
|
24638
|
-
category: 'Sequence',
|
|
24639
|
-
linkName: 'reductions',
|
|
24640
|
-
returns: {
|
|
24641
|
-
type: 'any',
|
|
24642
|
-
rest: true,
|
|
24643
|
-
},
|
|
24644
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24645
|
-
type: 'function',
|
|
24646
|
-
}, seq: {
|
|
24647
|
-
type: 'sequence',
|
|
24648
|
-
rest: true,
|
|
24649
|
-
}, start: {
|
|
24650
|
-
type: 'any',
|
|
24651
|
-
} }),
|
|
24652
|
-
variants: [
|
|
24653
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24654
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24655
|
-
],
|
|
24656
|
-
description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $seq by $fun.',
|
|
24657
|
-
examples: [
|
|
24658
|
-
'[1, 2, 3] reductions +',
|
|
24659
|
-
'reductions([1, 2, 3], +)',
|
|
24660
|
-
'reductions([1, 2, 3], +, 10)',
|
|
24661
|
-
'reductions([], +, 0)',
|
|
24662
|
-
"\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)",
|
|
24663
|
-
],
|
|
24664
|
-
},
|
|
24665
|
-
'reduce': {
|
|
24666
|
-
title: 'reduce',
|
|
24667
|
-
category: 'Sequence',
|
|
24668
|
-
linkName: 'reduce',
|
|
24669
|
-
returns: {
|
|
24670
|
-
type: 'any',
|
|
24671
|
-
},
|
|
24672
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24673
|
-
type: 'function',
|
|
24674
|
-
}, seq: {
|
|
24675
|
-
type: 'sequence',
|
|
24676
|
-
}, start: {
|
|
24677
|
-
type: 'any',
|
|
24678
|
-
} }),
|
|
24679
|
-
variants: [
|
|
24680
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24681
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24682
|
-
],
|
|
24683
|
-
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.',
|
|
24684
|
-
examples: [
|
|
24685
|
-
'[1, 2, 3] reduce +',
|
|
24686
|
-
'reduce([1, 2, 3], +)',
|
|
24687
|
-
'reduce([1, 2, 3], +, 0)',
|
|
24688
|
-
'reduce([], +, 0)',
|
|
24689
|
-
"\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)",
|
|
24690
|
-
],
|
|
24691
|
-
},
|
|
24692
|
-
'reduce-right': {
|
|
24693
|
-
title: 'reduce-right',
|
|
24694
|
-
category: 'Sequence',
|
|
24695
|
-
linkName: 'reduce-right',
|
|
24696
|
-
returns: {
|
|
24697
|
-
type: 'sequence',
|
|
24698
|
-
},
|
|
24699
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24700
|
-
type: 'function',
|
|
24701
|
-
}, seq: {
|
|
24702
|
-
type: 'sequence',
|
|
24703
|
-
}, start: {
|
|
24704
|
-
type: 'any',
|
|
24705
|
-
} }),
|
|
24706
|
-
variants: [
|
|
24707
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24708
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24709
|
-
],
|
|
24710
|
-
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.',
|
|
24711
|
-
examples: [
|
|
24712
|
-
'range(1, 10) reduce-right *',
|
|
24713
|
-
'reduce-right(["A", "B", "C"], str, "")',
|
|
24714
|
-
],
|
|
24715
|
-
},
|
|
24716
|
-
'map': {
|
|
24717
|
-
title: 'map',
|
|
24718
|
-
category: 'Sequence',
|
|
24719
|
-
linkName: 'map',
|
|
24720
|
-
returns: {
|
|
24721
|
-
type: 'any',
|
|
24722
|
-
rest: true,
|
|
24723
|
-
},
|
|
24724
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seqs: {
|
|
24725
|
-
type: 'sequence',
|
|
24726
|
-
rest: true,
|
|
24727
|
-
description: 'At least one.',
|
|
24728
|
-
}, fun: {
|
|
24729
|
-
type: 'function',
|
|
24730
|
-
} }),
|
|
24731
|
-
variants: [
|
|
24732
|
-
{ argumentNames: ['seqs', 'fun'] },
|
|
24733
|
-
],
|
|
24734
|
-
description: 'Creates a new array populated with the results of calling $fun on every element in $seqs.',
|
|
24735
|
-
examples: [
|
|
24736
|
-
'[1, 2, 3] map -',
|
|
24737
|
-
'[1, 2, 3] map -> -($)',
|
|
24738
|
-
'map(["Albert", "Mojir", 42], str)',
|
|
24739
|
-
'map([1, 2, 3], inc)',
|
|
24740
|
-
'map([1, 2, 3], [1, 10, 100], *)',
|
|
24741
|
-
],
|
|
24742
|
-
},
|
|
24743
|
-
'filter': {
|
|
24744
|
-
title: 'filter',
|
|
24745
|
-
category: 'Sequence',
|
|
24746
|
-
linkName: 'filter',
|
|
24747
|
-
returns: {
|
|
24748
|
-
type: 'sequence',
|
|
24749
|
-
},
|
|
24750
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seq: {
|
|
24751
|
-
type: 'sequence',
|
|
24752
|
-
}, fun: {
|
|
24753
|
-
type: 'function',
|
|
24754
|
-
} }),
|
|
24755
|
-
variants: [
|
|
24756
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24757
|
-
],
|
|
24758
|
-
description: 'Creates a new array with all elements that pass the test implemented by $fun.',
|
|
24759
|
-
examples: [
|
|
24760
|
-
"\nfilter(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)",
|
|
24761
|
-
"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)",
|
|
24762
|
-
],
|
|
24763
|
-
},
|
|
24764
24850
|
'position': {
|
|
24765
24851
|
title: 'position',
|
|
24766
24852
|
category: 'Sequence',
|