@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/cli/cli.js
CHANGED
|
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
92
92
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
var version = "2.1.
|
|
95
|
+
var version = "2.1.7";
|
|
96
96
|
|
|
97
97
|
function getCodeMarker(sourceCodeInfo) {
|
|
98
98
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -942,6 +942,32 @@ function assertCharArray(value, sourceCodeInfo) {
|
|
|
942
942
|
throw getAssertionError('array of strings', value, sourceCodeInfo);
|
|
943
943
|
}
|
|
944
944
|
|
|
945
|
+
function mapObjects(_a) {
|
|
946
|
+
var colls = _a.colls, contextStack = _a.contextStack, executeFunction = _a.executeFunction, fn = _a.fn, sourceCodeInfo = _a.sourceCodeInfo;
|
|
947
|
+
assertObj(colls[0], sourceCodeInfo);
|
|
948
|
+
var keys = Object.keys(colls[0]);
|
|
949
|
+
var params = {};
|
|
950
|
+
colls.forEach(function (obj) {
|
|
951
|
+
assertObj(obj, sourceCodeInfo);
|
|
952
|
+
var objKeys = Object.keys(obj);
|
|
953
|
+
if (objKeys.length !== keys.length) {
|
|
954
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
955
|
+
}
|
|
956
|
+
if (!objKeys.every(function (key) { return keys.includes(key); })) {
|
|
957
|
+
throw new LitsError("All objects must have the same keys. Expected: ".concat(keys.join(', '), ". Found: ").concat(objKeys.join(', ')), sourceCodeInfo);
|
|
958
|
+
}
|
|
959
|
+
Object.entries(obj).forEach(function (_a) {
|
|
960
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
961
|
+
if (!params[key])
|
|
962
|
+
params[key] = [];
|
|
963
|
+
params[key].push(value);
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
return keys.reduce(function (result, key) {
|
|
967
|
+
result[key] = executeFunction(fn, params[key], contextStack, sourceCodeInfo);
|
|
968
|
+
return result;
|
|
969
|
+
}, {});
|
|
970
|
+
}
|
|
945
971
|
function cloneAndGetMeta(originalColl, keys, sourceCodeInfo) {
|
|
946
972
|
var coll = cloneColl(originalColl);
|
|
947
973
|
var butLastKeys = keys.slice(0, keys.length - 1);
|
|
@@ -1034,6 +1060,188 @@ function assoc(coll, key, value, sourceCodeInfo) {
|
|
|
1034
1060
|
return copy;
|
|
1035
1061
|
}
|
|
1036
1062
|
var collectionNormalExpression = {
|
|
1063
|
+
'filter': {
|
|
1064
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1065
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
1066
|
+
var executeFunction = _b.executeFunction;
|
|
1067
|
+
assertColl(coll, sourceCodeInfo);
|
|
1068
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1069
|
+
if (Array.isArray(coll)) {
|
|
1070
|
+
var result = coll.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1071
|
+
return result;
|
|
1072
|
+
}
|
|
1073
|
+
if (isString(coll)) {
|
|
1074
|
+
return coll
|
|
1075
|
+
.split('')
|
|
1076
|
+
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
1077
|
+
.join('');
|
|
1078
|
+
}
|
|
1079
|
+
return Object.entries(coll)
|
|
1080
|
+
.filter(function (_a) {
|
|
1081
|
+
var _b = __read(_a, 2), value = _b[1];
|
|
1082
|
+
return executeFunction(fn, [value], contextStack, sourceCodeInfo);
|
|
1083
|
+
})
|
|
1084
|
+
.reduce(function (result, _a) {
|
|
1085
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
1086
|
+
result[key] = value;
|
|
1087
|
+
return result;
|
|
1088
|
+
}, {});
|
|
1089
|
+
},
|
|
1090
|
+
paramCount: 2,
|
|
1091
|
+
},
|
|
1092
|
+
'map': {
|
|
1093
|
+
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1094
|
+
var executeFunction = _a.executeFunction;
|
|
1095
|
+
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
1096
|
+
if (isObj(params[0])) {
|
|
1097
|
+
return mapObjects({
|
|
1098
|
+
colls: params.slice(0, -1),
|
|
1099
|
+
fn: fn,
|
|
1100
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
1101
|
+
contextStack: contextStack,
|
|
1102
|
+
executeFunction: executeFunction,
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
var seqs = params.slice(0, -1);
|
|
1106
|
+
assertSeq(seqs[0], sourceCodeInfo);
|
|
1107
|
+
var isStr = typeof seqs[0] === 'string';
|
|
1108
|
+
var len = seqs[0].length;
|
|
1109
|
+
seqs.slice(1).forEach(function (seq) {
|
|
1110
|
+
if (isStr) {
|
|
1111
|
+
assertString(seq, sourceCodeInfo);
|
|
1112
|
+
}
|
|
1113
|
+
else {
|
|
1114
|
+
assertArray(seq, sourceCodeInfo);
|
|
1115
|
+
}
|
|
1116
|
+
len = Math.min(len, seq.length);
|
|
1117
|
+
});
|
|
1118
|
+
var paramArray = [];
|
|
1119
|
+
var _loop_1 = function (i) {
|
|
1120
|
+
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1121
|
+
};
|
|
1122
|
+
for (var i = 0; i < len; i++) {
|
|
1123
|
+
_loop_1(i);
|
|
1124
|
+
}
|
|
1125
|
+
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1126
|
+
if (!isStr) {
|
|
1127
|
+
return mapped;
|
|
1128
|
+
}
|
|
1129
|
+
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1130
|
+
return mapped.join('');
|
|
1131
|
+
},
|
|
1132
|
+
paramCount: { min: 2 },
|
|
1133
|
+
},
|
|
1134
|
+
'reduce': {
|
|
1135
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1136
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1137
|
+
var executeFunction = _b.executeFunction;
|
|
1138
|
+
assertColl(coll, sourceCodeInfo);
|
|
1139
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1140
|
+
assertAny(initial, sourceCodeInfo);
|
|
1141
|
+
if (typeof coll === 'string') {
|
|
1142
|
+
assertString(initial, sourceCodeInfo);
|
|
1143
|
+
if (coll.length === 0)
|
|
1144
|
+
return initial;
|
|
1145
|
+
return coll.split('').reduce(function (result, elem) {
|
|
1146
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1147
|
+
}, initial);
|
|
1148
|
+
}
|
|
1149
|
+
else if (Array.isArray(coll)) {
|
|
1150
|
+
if (coll.length === 0)
|
|
1151
|
+
return initial;
|
|
1152
|
+
return coll.reduce(function (result, elem) {
|
|
1153
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1154
|
+
}, initial);
|
|
1155
|
+
}
|
|
1156
|
+
else {
|
|
1157
|
+
if (Object.keys(coll).length === 0)
|
|
1158
|
+
return initial;
|
|
1159
|
+
return Object.entries(coll).reduce(function (result, _a) {
|
|
1160
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1161
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1162
|
+
}, initial);
|
|
1163
|
+
}
|
|
1164
|
+
},
|
|
1165
|
+
paramCount: 3,
|
|
1166
|
+
},
|
|
1167
|
+
'reduce-right': {
|
|
1168
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1169
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1170
|
+
var executeFunction = _b.executeFunction;
|
|
1171
|
+
assertColl(coll, sourceCodeInfo);
|
|
1172
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1173
|
+
assertAny(initial, sourceCodeInfo);
|
|
1174
|
+
if (typeof coll === 'string') {
|
|
1175
|
+
if (coll.length === 0)
|
|
1176
|
+
return initial;
|
|
1177
|
+
return coll.split('').reduceRight(function (result, elem) {
|
|
1178
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1179
|
+
}, initial);
|
|
1180
|
+
}
|
|
1181
|
+
else if (Array.isArray(coll)) {
|
|
1182
|
+
if (coll.length === 0)
|
|
1183
|
+
return initial;
|
|
1184
|
+
return coll.reduceRight(function (result, elem) {
|
|
1185
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1186
|
+
}, initial);
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
if (Object.keys(coll).length === 0)
|
|
1190
|
+
return initial;
|
|
1191
|
+
return Object.entries(coll).reduceRight(function (result, _a) {
|
|
1192
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1193
|
+
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1194
|
+
}, initial);
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
paramCount: 3,
|
|
1198
|
+
},
|
|
1199
|
+
'reductions': {
|
|
1200
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1201
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1202
|
+
var executeFunction = _b.executeFunction;
|
|
1203
|
+
assertColl(coll, sourceCodeInfo);
|
|
1204
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1205
|
+
assertAny(initial, sourceCodeInfo);
|
|
1206
|
+
assertAny(initial, sourceCodeInfo);
|
|
1207
|
+
if (typeof coll === 'string') {
|
|
1208
|
+
assertString(initial, sourceCodeInfo);
|
|
1209
|
+
if (coll.length === 0)
|
|
1210
|
+
return [initial];
|
|
1211
|
+
var resultArray_1 = [initial];
|
|
1212
|
+
coll.split('').reduce(function (result, elem) {
|
|
1213
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1214
|
+
resultArray_1.push(newVal);
|
|
1215
|
+
return newVal;
|
|
1216
|
+
}, initial);
|
|
1217
|
+
return resultArray_1;
|
|
1218
|
+
}
|
|
1219
|
+
else if (Array.isArray(coll)) {
|
|
1220
|
+
if (coll.length === 0)
|
|
1221
|
+
return [initial];
|
|
1222
|
+
var resultArray_2 = [initial];
|
|
1223
|
+
coll.reduce(function (result, elem) {
|
|
1224
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1225
|
+
resultArray_2.push(newVal);
|
|
1226
|
+
return newVal;
|
|
1227
|
+
}, initial);
|
|
1228
|
+
return resultArray_2;
|
|
1229
|
+
}
|
|
1230
|
+
else {
|
|
1231
|
+
if (Object.keys(coll).length === 0)
|
|
1232
|
+
return [initial];
|
|
1233
|
+
var resultArray_3 = [initial];
|
|
1234
|
+
Object.entries(coll).reduce(function (result, _a) {
|
|
1235
|
+
var _b = __read(_a, 2), elem = _b[1];
|
|
1236
|
+
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1237
|
+
resultArray_3.push(newVal);
|
|
1238
|
+
return newVal;
|
|
1239
|
+
}, initial);
|
|
1240
|
+
return resultArray_3;
|
|
1241
|
+
}
|
|
1242
|
+
},
|
|
1243
|
+
paramCount: 3,
|
|
1244
|
+
},
|
|
1037
1245
|
'get': {
|
|
1038
1246
|
evaluate: function (params, sourceCodeInfo) {
|
|
1039
1247
|
var _a = __read(params, 2), coll = _a[0], key = _a[1];
|
|
@@ -1337,13 +1545,15 @@ var arrayNormalExpression = {
|
|
|
1337
1545
|
paramCount: 2,
|
|
1338
1546
|
},
|
|
1339
1547
|
flatten: {
|
|
1340
|
-
evaluate: function (_a) {
|
|
1341
|
-
var _b = __read(_a,
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1548
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
1549
|
+
var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
|
|
1550
|
+
assertArray(seq, sourceCodeInfo);
|
|
1551
|
+
var actualDepth = depth === undefined || depth === Number.POSITIVE_INFINITY
|
|
1552
|
+
? Number.POSITIVE_INFINITY
|
|
1553
|
+
: asNumber(depth, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
1554
|
+
return seq.flat(actualDepth);
|
|
1345
1555
|
},
|
|
1346
|
-
paramCount: 1,
|
|
1556
|
+
paramCount: { min: 1, max: 2 },
|
|
1347
1557
|
},
|
|
1348
1558
|
mapcat: {
|
|
1349
1559
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -1376,23 +1586,6 @@ var sequenceNormalExpression = {
|
|
|
1376
1586
|
},
|
|
1377
1587
|
paramCount: { min: 2, max: 3 },
|
|
1378
1588
|
},
|
|
1379
|
-
'filter': {
|
|
1380
|
-
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1381
|
-
var _c = __read(_a, 2), seq = _c[0], fn = _c[1];
|
|
1382
|
-
var executeFunction = _b.executeFunction;
|
|
1383
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1384
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1385
|
-
if (Array.isArray(seq)) {
|
|
1386
|
-
var result = seq.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); });
|
|
1387
|
-
return result;
|
|
1388
|
-
}
|
|
1389
|
-
return seq
|
|
1390
|
-
.split('')
|
|
1391
|
-
.filter(function (elem) { return executeFunction(fn, [elem], contextStack, sourceCodeInfo); })
|
|
1392
|
-
.join('');
|
|
1393
|
-
},
|
|
1394
|
-
paramCount: 2,
|
|
1395
|
-
},
|
|
1396
1589
|
'first': {
|
|
1397
1590
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1398
1591
|
var _b = __read(_a, 1), array = _b[0];
|
|
@@ -1415,39 +1608,6 @@ var sequenceNormalExpression = {
|
|
|
1415
1608
|
},
|
|
1416
1609
|
paramCount: 1,
|
|
1417
1610
|
},
|
|
1418
|
-
'map': {
|
|
1419
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1420
|
-
var executeFunction = _a.executeFunction;
|
|
1421
|
-
var fn = asFunctionLike(params.at(-1), sourceCodeInfo);
|
|
1422
|
-
var seqs = params.slice(0, -1);
|
|
1423
|
-
assertSeq(seqs[0], sourceCodeInfo);
|
|
1424
|
-
var isString = typeof seqs[0] === 'string';
|
|
1425
|
-
var len = seqs[0].length;
|
|
1426
|
-
seqs.slice(1).forEach(function (seq) {
|
|
1427
|
-
if (isString) {
|
|
1428
|
-
assertString(seq, sourceCodeInfo);
|
|
1429
|
-
}
|
|
1430
|
-
else {
|
|
1431
|
-
assertArray(seq, sourceCodeInfo);
|
|
1432
|
-
}
|
|
1433
|
-
len = Math.min(len, seq.length);
|
|
1434
|
-
});
|
|
1435
|
-
var paramArray = [];
|
|
1436
|
-
var _loop_1 = function (i) {
|
|
1437
|
-
paramArray.push(seqs.map(function (seq) { return seq[i]; }));
|
|
1438
|
-
};
|
|
1439
|
-
for (var i = 0; i < len; i++) {
|
|
1440
|
-
_loop_1(i);
|
|
1441
|
-
}
|
|
1442
|
-
var mapped = paramArray.map(function (p) { return executeFunction(fn, p, contextStack, sourceCodeInfo); });
|
|
1443
|
-
if (!isString) {
|
|
1444
|
-
return mapped;
|
|
1445
|
-
}
|
|
1446
|
-
mapped.forEach(function (char) { return assertString(char, sourceCodeInfo); });
|
|
1447
|
-
return mapped.join('');
|
|
1448
|
-
},
|
|
1449
|
-
paramCount: { min: 2 },
|
|
1450
|
-
},
|
|
1451
1611
|
'pop': {
|
|
1452
1612
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1453
1613
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -1530,160 +1690,6 @@ var sequenceNormalExpression = {
|
|
|
1530
1690
|
},
|
|
1531
1691
|
paramCount: { min: 2 },
|
|
1532
1692
|
},
|
|
1533
|
-
'reductions': {
|
|
1534
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1535
|
-
var executeFunction = _a.executeFunction;
|
|
1536
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1537
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1538
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1539
|
-
if (params.length === 2) {
|
|
1540
|
-
if (seq.length === 0)
|
|
1541
|
-
return [executeFunction(fn, [], contextStack, sourceCodeInfo)];
|
|
1542
|
-
else if (seq.length === 1)
|
|
1543
|
-
return [toAny(seq[0])];
|
|
1544
|
-
if (typeof seq === 'string') {
|
|
1545
|
-
var chars = seq.split('');
|
|
1546
|
-
var resultArray_1 = [asAny(chars[0], sourceCodeInfo)];
|
|
1547
|
-
chars.slice(1).reduce(function (result, elem) {
|
|
1548
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1549
|
-
resultArray_1.push(newVal);
|
|
1550
|
-
return newVal;
|
|
1551
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1552
|
-
return resultArray_1;
|
|
1553
|
-
}
|
|
1554
|
-
else {
|
|
1555
|
-
var resultArray_2 = [toAny(seq[0])];
|
|
1556
|
-
seq.slice(1).reduce(function (result, elem) {
|
|
1557
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1558
|
-
resultArray_2.push(newVal);
|
|
1559
|
-
return newVal;
|
|
1560
|
-
}, toAny(seq[0]));
|
|
1561
|
-
return resultArray_2;
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
else {
|
|
1565
|
-
var val = params[2];
|
|
1566
|
-
assertAny(val, sourceCodeInfo);
|
|
1567
|
-
if (typeof seq === 'string') {
|
|
1568
|
-
assertString(val, sourceCodeInfo);
|
|
1569
|
-
if (seq.length === 0)
|
|
1570
|
-
return [val];
|
|
1571
|
-
var resultArray_3 = [val];
|
|
1572
|
-
seq.split('').reduce(function (result, elem) {
|
|
1573
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1574
|
-
resultArray_3.push(newVal);
|
|
1575
|
-
return newVal;
|
|
1576
|
-
}, val);
|
|
1577
|
-
return resultArray_3;
|
|
1578
|
-
}
|
|
1579
|
-
else {
|
|
1580
|
-
if (seq.length === 0)
|
|
1581
|
-
return [val];
|
|
1582
|
-
var resultArray_4 = [val];
|
|
1583
|
-
seq.reduce(function (result, elem) {
|
|
1584
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1585
|
-
resultArray_4.push(newVal);
|
|
1586
|
-
return newVal;
|
|
1587
|
-
}, val);
|
|
1588
|
-
return resultArray_4;
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
},
|
|
1592
|
-
paramCount: { min: 2, max: 3 },
|
|
1593
|
-
},
|
|
1594
|
-
'reduce': {
|
|
1595
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1596
|
-
var executeFunction = _a.executeFunction;
|
|
1597
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1598
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1599
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1600
|
-
if (params.length === 2) {
|
|
1601
|
-
if (seq.length === 0)
|
|
1602
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1603
|
-
else if (seq.length === 1)
|
|
1604
|
-
return toAny(seq[0]);
|
|
1605
|
-
if (typeof seq === 'string') {
|
|
1606
|
-
var chars = seq.split('');
|
|
1607
|
-
return chars.slice(1).reduce(function (result, elem) {
|
|
1608
|
-
var val = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1609
|
-
return val;
|
|
1610
|
-
}, asAny(chars[0], sourceCodeInfo));
|
|
1611
|
-
}
|
|
1612
|
-
else {
|
|
1613
|
-
return seq.slice(1).reduce(function (result, elem) {
|
|
1614
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1615
|
-
}, toAny(seq[0]));
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
else {
|
|
1619
|
-
var val = params[2];
|
|
1620
|
-
assertAny(val, sourceCodeInfo);
|
|
1621
|
-
if (typeof seq === 'string') {
|
|
1622
|
-
assertString(val, sourceCodeInfo);
|
|
1623
|
-
if (seq.length === 0)
|
|
1624
|
-
return val;
|
|
1625
|
-
return seq.split('').reduce(function (result, elem) {
|
|
1626
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1627
|
-
}, val);
|
|
1628
|
-
}
|
|
1629
|
-
else {
|
|
1630
|
-
if (seq.length === 0)
|
|
1631
|
-
return val;
|
|
1632
|
-
return seq.reduce(function (result, elem) {
|
|
1633
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1634
|
-
}, val);
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
},
|
|
1638
|
-
paramCount: { min: 2, max: 3 },
|
|
1639
|
-
},
|
|
1640
|
-
'reduce-right': {
|
|
1641
|
-
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
1642
|
-
var executeFunction = _a.executeFunction;
|
|
1643
|
-
var _b = __read(params, 2), seq = _b[0], fn = _b[1];
|
|
1644
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1645
|
-
assertFunctionLike(fn, sourceCodeInfo);
|
|
1646
|
-
if (params.length === 2) {
|
|
1647
|
-
if (seq.length === 0)
|
|
1648
|
-
return executeFunction(fn, [], contextStack, sourceCodeInfo);
|
|
1649
|
-
else if (seq.length === 1)
|
|
1650
|
-
return toAny(seq[0]);
|
|
1651
|
-
if (typeof seq === 'string') {
|
|
1652
|
-
var chars = seq.split('');
|
|
1653
|
-
return chars.slice(0, chars.length - 1).reduceRight(function (result, elem) {
|
|
1654
|
-
var newVal = executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1655
|
-
assertString(newVal, sourceCodeInfo);
|
|
1656
|
-
return newVal;
|
|
1657
|
-
}, chars[chars.length - 1]);
|
|
1658
|
-
}
|
|
1659
|
-
else {
|
|
1660
|
-
return seq.slice(0, seq.length - 1).reduceRight(function (result, elem) {
|
|
1661
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1662
|
-
}, asAny(seq[seq.length - 1], sourceCodeInfo));
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
else {
|
|
1666
|
-
var val = params[2];
|
|
1667
|
-
assertAny(val, sourceCodeInfo);
|
|
1668
|
-
assertSeq(seq, sourceCodeInfo);
|
|
1669
|
-
if (typeof seq === 'string') {
|
|
1670
|
-
if (seq.length === 0)
|
|
1671
|
-
return val;
|
|
1672
|
-
return seq.split('').reduceRight(function (result, elem) {
|
|
1673
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1674
|
-
}, val);
|
|
1675
|
-
}
|
|
1676
|
-
else {
|
|
1677
|
-
if (seq.length === 0)
|
|
1678
|
-
return val;
|
|
1679
|
-
return seq.reduceRight(function (result, elem) {
|
|
1680
|
-
return executeFunction(fn, [result, elem], contextStack, sourceCodeInfo);
|
|
1681
|
-
}, val);
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
},
|
|
1685
|
-
paramCount: { min: 2, max: 3 },
|
|
1686
|
-
},
|
|
1687
1693
|
'rest': {
|
|
1688
1694
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1689
1695
|
var _b = __read(_a, 1), seq = _b[0];
|
|
@@ -2002,7 +2008,7 @@ var sequenceNormalExpression = {
|
|
|
2002
2008
|
assertSeq(input, sourceCodeInfo);
|
|
2003
2009
|
if (Array.isArray(input)) {
|
|
2004
2010
|
var result = [];
|
|
2005
|
-
var
|
|
2011
|
+
var _loop_1 = function (item) {
|
|
2006
2012
|
assertAny(item, sourceCodeInfo);
|
|
2007
2013
|
if (!result.some(function (existingItem) { return deepEqual(existingItem, item, sourceCodeInfo); })) {
|
|
2008
2014
|
result.push(item);
|
|
@@ -2011,7 +2017,7 @@ var sequenceNormalExpression = {
|
|
|
2011
2017
|
try {
|
|
2012
2018
|
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
2013
2019
|
var item = input_1_1.value;
|
|
2014
|
-
|
|
2020
|
+
_loop_1(item);
|
|
2015
2021
|
}
|
|
2016
2022
|
}
|
|
2017
2023
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -3997,6 +4003,13 @@ var regexpNormalExpression = {
|
|
|
3997
4003
|
assertString(sourceArg, sourceCodeInfo);
|
|
3998
4004
|
var source = sourceArg || '(?:)';
|
|
3999
4005
|
var flags = typeof flagsArg === 'string' ? flagsArg : '';
|
|
4006
|
+
try {
|
|
4007
|
+
// eslint-disable-next-line no-new
|
|
4008
|
+
new RegExp(source, flags); // Throws if invalid regexp
|
|
4009
|
+
}
|
|
4010
|
+
catch (e) {
|
|
4011
|
+
throw new LitsError("Invalid regular expression: ".concat(source, " ").concat(flags), sourceCodeInfo);
|
|
4012
|
+
}
|
|
4000
4013
|
return _b = {},
|
|
4001
4014
|
_b[REGEXP_SYMBOL] = true,
|
|
4002
4015
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
@@ -4315,6 +4328,15 @@ function applyPlaceholders(templateString, placeholders, sourceCodeInfo) {
|
|
|
4315
4328
|
}
|
|
4316
4329
|
|
|
4317
4330
|
var functionalNormalExpression = {
|
|
4331
|
+
'|>': {
|
|
4332
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4333
|
+
var _c = __read(_a, 2), value = _c[0], func = _c[1];
|
|
4334
|
+
var executeFunction = _b.executeFunction;
|
|
4335
|
+
assertFunctionLike(func, sourceCodeInfo);
|
|
4336
|
+
return executeFunction(func, [value], contextStack, sourceCodeInfo);
|
|
4337
|
+
},
|
|
4338
|
+
paramCount: 2,
|
|
4339
|
+
},
|
|
4318
4340
|
'apply': {
|
|
4319
4341
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
4320
4342
|
var _c = __read(_a), func = _c[0], params = _c.slice(1);
|
|
@@ -4335,20 +4357,6 @@ var functionalNormalExpression = {
|
|
|
4335
4357
|
},
|
|
4336
4358
|
paramCount: 1,
|
|
4337
4359
|
},
|
|
4338
|
-
'partial': {
|
|
4339
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
4340
|
-
var _b;
|
|
4341
|
-
var _c = __read(_a), fn = _c[0], params = _c.slice(1);
|
|
4342
|
-
return _b = {},
|
|
4343
|
-
_b[FUNCTION_SYMBOL] = true,
|
|
4344
|
-
_b.sourceCodeInfo = sourceCodeInfo,
|
|
4345
|
-
_b.functionType = 'Partial',
|
|
4346
|
-
_b.function = asFunctionLike(fn, sourceCodeInfo),
|
|
4347
|
-
_b.params = params,
|
|
4348
|
-
_b;
|
|
4349
|
-
},
|
|
4350
|
-
paramCount: { min: 1 },
|
|
4351
|
-
},
|
|
4352
4360
|
'comp': {
|
|
4353
4361
|
evaluate: function (params, sourceCodeInfo) {
|
|
4354
4362
|
var _a;
|
|
@@ -7108,10 +7116,10 @@ var linearAlgebraNormalExpression = {
|
|
|
7108
7116
|
assertVector(vectorA, sourceCodeInfo);
|
|
7109
7117
|
assertVector(vectorB, sourceCodeInfo);
|
|
7110
7118
|
if (vectorA.length < 2) {
|
|
7111
|
-
throw new
|
|
7119
|
+
throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
|
|
7112
7120
|
}
|
|
7113
7121
|
if (vectorA.length !== vectorB.length) {
|
|
7114
|
-
throw new
|
|
7122
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
7115
7123
|
}
|
|
7116
7124
|
assertNumber(lag, sourceCodeInfo, {
|
|
7117
7125
|
integer: true,
|
|
@@ -8363,7 +8371,7 @@ var partitionsNormalExpressions = {
|
|
|
8363
8371
|
if (n === 0)
|
|
8364
8372
|
return 1;
|
|
8365
8373
|
if (n > partitionNumbers.length) {
|
|
8366
|
-
throw new
|
|
8374
|
+
throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
|
|
8367
8375
|
}
|
|
8368
8376
|
return partitionNumbers[n - 1];
|
|
8369
8377
|
},
|
|
@@ -10502,7 +10510,12 @@ var combinatoricalNormalExpression = {
|
|
|
10502
10510
|
var _b = __read(_a, 2), a = _b[0], m = _b[1];
|
|
10503
10511
|
assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
|
|
10504
10512
|
assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
|
|
10505
|
-
|
|
10513
|
+
try {
|
|
10514
|
+
return modInverse(a, m);
|
|
10515
|
+
}
|
|
10516
|
+
catch (error) {
|
|
10517
|
+
throw new LitsError(error, sourceCodeInfo);
|
|
10518
|
+
}
|
|
10506
10519
|
},
|
|
10507
10520
|
paramCount: 2,
|
|
10508
10521
|
},
|
|
@@ -10521,7 +10534,7 @@ var combinatoricalNormalExpression = {
|
|
|
10521
10534
|
assertVector(remainders, sourceCodeInfo);
|
|
10522
10535
|
assertVector(moduli, sourceCodeInfo);
|
|
10523
10536
|
if (remainders.length !== moduli.length) {
|
|
10524
|
-
throw new
|
|
10537
|
+
throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
|
|
10525
10538
|
}
|
|
10526
10539
|
try {
|
|
10527
10540
|
return chineseRemainder(remainders, moduli);
|
|
@@ -11275,6 +11288,7 @@ var nonNumberReservedSymbolRecord = {
|
|
|
11275
11288
|
function: null,
|
|
11276
11289
|
export: null,
|
|
11277
11290
|
as: null,
|
|
11291
|
+
_: null,
|
|
11278
11292
|
};
|
|
11279
11293
|
var phi = (1 + Math.sqrt(5)) / 2;
|
|
11280
11294
|
var numberReservedSymbolRecord = {
|
|
@@ -11964,7 +11978,11 @@ var objectSpecialExpression = {
|
|
|
11964
11978
|
}
|
|
11965
11979
|
else {
|
|
11966
11980
|
var key = evaluateNode(keyNode, contextStack);
|
|
11967
|
-
var
|
|
11981
|
+
var valueNode = params[i + 1];
|
|
11982
|
+
if (valueNode === undefined) {
|
|
11983
|
+
throw new LitsError('Missing value for key', keyNode[2]);
|
|
11984
|
+
}
|
|
11985
|
+
var value = evaluateNode(valueNode, contextStack);
|
|
11968
11986
|
assertString(key, keyNode[2]);
|
|
11969
11987
|
result[key] = value;
|
|
11970
11988
|
}
|
|
@@ -12124,8 +12142,27 @@ var functionExecutors = {
|
|
|
12124
12142
|
}
|
|
12125
12143
|
},
|
|
12126
12144
|
Partial: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12145
|
+
var e_2, _b;
|
|
12127
12146
|
var executeFunction = _a.executeFunction;
|
|
12128
|
-
|
|
12147
|
+
var actualParams = __spreadArray([], __read(fn.params), false);
|
|
12148
|
+
if (params.length !== fn.placeholders.length) {
|
|
12149
|
+
throw new LitsError("(partial) expects ".concat(fn.placeholders.length, " arguments, got ").concat(params.length, "."), sourceCodeInfo);
|
|
12150
|
+
}
|
|
12151
|
+
var paramsCopy = __spreadArray([], __read(params), false);
|
|
12152
|
+
try {
|
|
12153
|
+
for (var _c = __values(fn.placeholders), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
12154
|
+
var placeholderIndex = _d.value;
|
|
12155
|
+
actualParams.splice(placeholderIndex, 0, paramsCopy.shift());
|
|
12156
|
+
}
|
|
12157
|
+
}
|
|
12158
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
12159
|
+
finally {
|
|
12160
|
+
try {
|
|
12161
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
12162
|
+
}
|
|
12163
|
+
finally { if (e_2) throw e_2.error; }
|
|
12164
|
+
}
|
|
12165
|
+
return executeFunction(fn.function, actualParams, contextStack, sourceCodeInfo);
|
|
12129
12166
|
},
|
|
12130
12167
|
Comp: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12131
12168
|
var executeFunction = _a.executeFunction;
|
|
@@ -12151,66 +12188,66 @@ var functionExecutors = {
|
|
|
12151
12188
|
return !executeFunction(fn.function, params, contextStack, sourceCodeInfo);
|
|
12152
12189
|
},
|
|
12153
12190
|
EveryPred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12154
|
-
var
|
|
12191
|
+
var e_3, _b, e_4, _c;
|
|
12155
12192
|
var executeFunction = _a.executeFunction;
|
|
12156
12193
|
try {
|
|
12157
12194
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12158
12195
|
var f = _e.value;
|
|
12159
12196
|
try {
|
|
12160
|
-
for (var params_1 = (
|
|
12197
|
+
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()) {
|
|
12161
12198
|
var param = params_1_1.value;
|
|
12162
12199
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12163
12200
|
if (!result)
|
|
12164
12201
|
return false;
|
|
12165
12202
|
}
|
|
12166
12203
|
}
|
|
12167
|
-
catch (
|
|
12204
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
12168
12205
|
finally {
|
|
12169
12206
|
try {
|
|
12170
12207
|
if (params_1_1 && !params_1_1.done && (_c = params_1.return)) _c.call(params_1);
|
|
12171
12208
|
}
|
|
12172
|
-
finally { if (
|
|
12209
|
+
finally { if (e_4) throw e_4.error; }
|
|
12173
12210
|
}
|
|
12174
12211
|
}
|
|
12175
12212
|
}
|
|
12176
|
-
catch (
|
|
12213
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
12177
12214
|
finally {
|
|
12178
12215
|
try {
|
|
12179
12216
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12180
12217
|
}
|
|
12181
|
-
finally { if (
|
|
12218
|
+
finally { if (e_3) throw e_3.error; }
|
|
12182
12219
|
}
|
|
12183
12220
|
return true;
|
|
12184
12221
|
},
|
|
12185
12222
|
SomePred: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
12186
|
-
var
|
|
12223
|
+
var e_5, _b, e_6, _c;
|
|
12187
12224
|
var executeFunction = _a.executeFunction;
|
|
12188
12225
|
try {
|
|
12189
12226
|
for (var _d = __values(fn.params), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
12190
12227
|
var f = _e.value;
|
|
12191
12228
|
try {
|
|
12192
|
-
for (var params_2 = (
|
|
12229
|
+
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()) {
|
|
12193
12230
|
var param = params_2_1.value;
|
|
12194
12231
|
var result = executeFunction(asFunctionLike(f, sourceCodeInfo), [param], contextStack, sourceCodeInfo);
|
|
12195
12232
|
if (result)
|
|
12196
12233
|
return true;
|
|
12197
12234
|
}
|
|
12198
12235
|
}
|
|
12199
|
-
catch (
|
|
12236
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
12200
12237
|
finally {
|
|
12201
12238
|
try {
|
|
12202
12239
|
if (params_2_1 && !params_2_1.done && (_c = params_2.return)) _c.call(params_2);
|
|
12203
12240
|
}
|
|
12204
|
-
finally { if (
|
|
12241
|
+
finally { if (e_6) throw e_6.error; }
|
|
12205
12242
|
}
|
|
12206
12243
|
}
|
|
12207
12244
|
}
|
|
12208
|
-
catch (
|
|
12245
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
12209
12246
|
finally {
|
|
12210
12247
|
try {
|
|
12211
12248
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
12212
12249
|
}
|
|
12213
|
-
finally { if (
|
|
12250
|
+
finally { if (e_5) throw e_5.error; }
|
|
12214
12251
|
}
|
|
12215
12252
|
return false;
|
|
12216
12253
|
},
|
|
@@ -12283,6 +12320,9 @@ function evaluateString(node) {
|
|
|
12283
12320
|
}
|
|
12284
12321
|
function evaluateReservedSymbol(node) {
|
|
12285
12322
|
var reservedName = node[1];
|
|
12323
|
+
if (!['true', 'false', 'null'].includes(reservedName)) {
|
|
12324
|
+
throw new LitsError("Reserved symbol ".concat(reservedName, " cannot be evaluated"), node[2]);
|
|
12325
|
+
}
|
|
12286
12326
|
var value = reservedSymbolRecord[reservedName];
|
|
12287
12327
|
return asNonUndefined(value, node[2]);
|
|
12288
12328
|
}
|
|
@@ -12290,7 +12330,8 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12290
12330
|
var sourceCodeInfo = node[2];
|
|
12291
12331
|
var paramNodes = node[1][1];
|
|
12292
12332
|
var params = [];
|
|
12293
|
-
|
|
12333
|
+
var placeholders = [];
|
|
12334
|
+
paramNodes.forEach(function (paramNode, index) {
|
|
12294
12335
|
if (isSpreadNode(paramNode)) {
|
|
12295
12336
|
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
12296
12337
|
if (Array.isArray(spreadValue)) {
|
|
@@ -12300,12 +12341,27 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12300
12341
|
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
12301
12342
|
}
|
|
12302
12343
|
}
|
|
12344
|
+
else if (paramNode[0] === NodeTypes.ReservedSymbol && paramNode[1] === '_') {
|
|
12345
|
+
placeholders.push(index);
|
|
12346
|
+
}
|
|
12303
12347
|
else {
|
|
12304
12348
|
params.push(evaluateNode(paramNode, contextStack));
|
|
12305
12349
|
}
|
|
12306
12350
|
});
|
|
12307
12351
|
if (isNormalExpressionNodeWithName(node)) {
|
|
12308
12352
|
var nameSymbol = node[1][0];
|
|
12353
|
+
if (placeholders.length > 0) {
|
|
12354
|
+
var fn = evaluateNode(nameSymbol, contextStack);
|
|
12355
|
+
var partialFunction = {
|
|
12356
|
+
'^^fn^^': true,
|
|
12357
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12358
|
+
'functionType': 'Partial',
|
|
12359
|
+
params: params,
|
|
12360
|
+
placeholders: placeholders,
|
|
12361
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12362
|
+
};
|
|
12363
|
+
return partialFunction;
|
|
12364
|
+
}
|
|
12309
12365
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
12310
12366
|
var type = nameSymbol[1];
|
|
12311
12367
|
var normalExpression = builtin.allNormalExpressions[type];
|
|
@@ -12322,6 +12378,17 @@ function evaluateNormalExpression(node, contextStack) {
|
|
|
12322
12378
|
else {
|
|
12323
12379
|
var fnNode = node[1][0];
|
|
12324
12380
|
var fn = asFunctionLike(evaluateNode(fnNode, contextStack), sourceCodeInfo);
|
|
12381
|
+
if (placeholders.length > 0) {
|
|
12382
|
+
var partialFunction = {
|
|
12383
|
+
'^^fn^^': true,
|
|
12384
|
+
'function': asFunctionLike(fn, sourceCodeInfo),
|
|
12385
|
+
'functionType': 'Partial',
|
|
12386
|
+
params: params,
|
|
12387
|
+
placeholders: placeholders,
|
|
12388
|
+
sourceCodeInfo: sourceCodeInfo,
|
|
12389
|
+
};
|
|
12390
|
+
return partialFunction;
|
|
12391
|
+
}
|
|
12325
12392
|
return executeFunction(fn, params, contextStack, sourceCodeInfo);
|
|
12326
12393
|
}
|
|
12327
12394
|
}
|
|
@@ -12627,6 +12694,7 @@ var binaryOperators = [
|
|
|
12627
12694
|
'&&', // logical AND
|
|
12628
12695
|
'||', // logical OR
|
|
12629
12696
|
'??', // nullish coalescing
|
|
12697
|
+
'|>', // pipe
|
|
12630
12698
|
];
|
|
12631
12699
|
var otherOperators = [
|
|
12632
12700
|
'->', // lambda
|
|
@@ -12805,21 +12873,30 @@ var tokenizeNumber = function (input, position) {
|
|
|
12805
12873
|
var char = input[i];
|
|
12806
12874
|
if (char === '_') {
|
|
12807
12875
|
if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
|
|
12808
|
-
|
|
12876
|
+
if (i === start) {
|
|
12877
|
+
return NO_MATCH;
|
|
12878
|
+
}
|
|
12879
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12809
12880
|
}
|
|
12810
12881
|
}
|
|
12811
12882
|
else if (char === '.') {
|
|
12812
|
-
if (i === start
|
|
12883
|
+
if (i === start) {
|
|
12813
12884
|
return NO_MATCH;
|
|
12814
12885
|
}
|
|
12886
|
+
if (hasDecimalPoint || hasExponent) {
|
|
12887
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12888
|
+
}
|
|
12815
12889
|
hasDecimalPoint = true;
|
|
12816
12890
|
}
|
|
12817
12891
|
else if (char === 'e' || char === 'E') {
|
|
12818
|
-
if (i === start
|
|
12892
|
+
if (i === start) {
|
|
12819
12893
|
return NO_MATCH;
|
|
12820
12894
|
}
|
|
12895
|
+
if (hasExponent) {
|
|
12896
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12897
|
+
}
|
|
12821
12898
|
if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
|
|
12822
|
-
|
|
12899
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12823
12900
|
}
|
|
12824
12901
|
if (input[i + 1] === '+' || input[i + 1] === '-') {
|
|
12825
12902
|
i += 1;
|
|
@@ -12839,7 +12916,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
12839
12916
|
}
|
|
12840
12917
|
var nextChar = input[i];
|
|
12841
12918
|
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
12842
|
-
|
|
12919
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12843
12920
|
}
|
|
12844
12921
|
return [length, ['Number', input.substring(position, i)]];
|
|
12845
12922
|
};
|
|
@@ -13005,10 +13082,10 @@ function tokenize(input, debug, filePath) {
|
|
|
13005
13082
|
hasDebugData: debug,
|
|
13006
13083
|
};
|
|
13007
13084
|
while (position < input.length) {
|
|
13008
|
-
var tokenDescriptor = getCurrentToken(input, position);
|
|
13009
13085
|
var sourceCodeInfo = debug
|
|
13010
13086
|
? createSourceCodeInfo(input, position, filePath)
|
|
13011
13087
|
: undefined;
|
|
13088
|
+
var tokenDescriptor = getCurrentToken(input, position);
|
|
13012
13089
|
if (!tokenDescriptor) {
|
|
13013
13090
|
throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
|
|
13014
13091
|
}
|
|
@@ -13118,9 +13195,6 @@ function isOperatorToken(token, operatorName) {
|
|
|
13118
13195
|
}
|
|
13119
13196
|
function assertOperatorToken(token, operatorName) {
|
|
13120
13197
|
if (!isOperatorToken(token, operatorName)) {
|
|
13121
|
-
if (operatorName) {
|
|
13122
|
-
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
|
|
13123
|
-
}
|
|
13124
13198
|
throwUnexpectedToken('Operator', operatorName, token);
|
|
13125
13199
|
}
|
|
13126
13200
|
}
|
|
@@ -13190,8 +13264,8 @@ function isA_BinaryOperatorToken(token) {
|
|
|
13190
13264
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
|
|
13191
13265
|
}
|
|
13192
13266
|
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
13193
|
-
var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
|
|
13194
|
-
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual[2]);
|
|
13267
|
+
var actualOutput = actual ? "".concat(actual[0], " '").concat(actual[1], "'") : 'end of input';
|
|
13268
|
+
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual === null || actual === void 0 ? void 0 : actual[2]);
|
|
13195
13269
|
}
|
|
13196
13270
|
|
|
13197
13271
|
function minifyTokenStream(tokenStream, _a) {
|
|
@@ -13220,8 +13294,8 @@ function untokenize(tokenStream) {
|
|
|
13220
13294
|
}, '');
|
|
13221
13295
|
}
|
|
13222
13296
|
|
|
13223
|
-
var exponentiationPrecedence =
|
|
13224
|
-
var binaryFunctionalOperatorPrecedence =
|
|
13297
|
+
var exponentiationPrecedence = 11;
|
|
13298
|
+
var binaryFunctionalOperatorPrecedence = 2;
|
|
13225
13299
|
var placeholderRegexp = /^\$([1-9]\d?)?$/;
|
|
13226
13300
|
function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
13227
13301
|
if (sourceCodeInfo) {
|
|
@@ -13236,38 +13310,40 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13236
13310
|
case '*': // multiplication
|
|
13237
13311
|
case '/': // division
|
|
13238
13312
|
case '%': // remainder
|
|
13239
|
-
return
|
|
13313
|
+
return 10;
|
|
13240
13314
|
case '+': // addition
|
|
13241
13315
|
case '-': // subtraction
|
|
13242
|
-
return
|
|
13316
|
+
return 9;
|
|
13243
13317
|
case '<<': // left shift
|
|
13244
13318
|
case '>>': // signed right shift
|
|
13245
13319
|
case '>>>': // unsigned right shift
|
|
13246
|
-
return
|
|
13320
|
+
return 8;
|
|
13247
13321
|
case '++': // string concatenation
|
|
13248
|
-
return
|
|
13322
|
+
return 7;
|
|
13249
13323
|
case '<': // less than
|
|
13250
13324
|
case '<=': // less than or equal
|
|
13251
13325
|
case '≤': // less than or equal
|
|
13252
13326
|
case '>': // greater than
|
|
13253
13327
|
case '>=': // greater than or equal
|
|
13254
13328
|
case '≥': // greater than or equal
|
|
13255
|
-
return
|
|
13329
|
+
return 6;
|
|
13256
13330
|
case '=': // equal
|
|
13257
13331
|
case '!=': // not equal
|
|
13258
13332
|
case '≠': // not equal
|
|
13259
13333
|
case '~': // approximate
|
|
13260
13334
|
case '≈': // approximate
|
|
13261
|
-
return
|
|
13335
|
+
return 5;
|
|
13262
13336
|
case '&': // bitwise AND
|
|
13263
13337
|
case 'xor': // bitwise XOR
|
|
13264
13338
|
case '|': // bitwise OR
|
|
13265
|
-
return
|
|
13339
|
+
return 4;
|
|
13266
13340
|
case '&&': // logical AND
|
|
13267
13341
|
case '||': // logical OR
|
|
13268
13342
|
case '??': // nullish coalescing
|
|
13269
|
-
return
|
|
13270
|
-
|
|
13343
|
+
return 3;
|
|
13344
|
+
case '|>': // pipe
|
|
13345
|
+
return 1;
|
|
13346
|
+
// leave room for binaryFunctionalOperatorPrecedence = 2
|
|
13271
13347
|
/* v8 ignore next 2 */
|
|
13272
13348
|
default:
|
|
13273
13349
|
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
@@ -13311,6 +13387,7 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13311
13387
|
case '|':
|
|
13312
13388
|
case '~':
|
|
13313
13389
|
case '≈':
|
|
13390
|
+
case '|>':
|
|
13314
13391
|
return createNamedNormalExpressionNode(symbolNode, [left, right], sourceCodeInfo);
|
|
13315
13392
|
case '&&':
|
|
13316
13393
|
case '||':
|
|
@@ -13336,6 +13413,11 @@ var Parser = /** @class */ (function () {
|
|
|
13336
13413
|
Parser.prototype.peek = function () {
|
|
13337
13414
|
return this.tokenStream.tokens[this.parseState.position];
|
|
13338
13415
|
};
|
|
13416
|
+
Parser.prototype.peekSourceCodeInfo = function () {
|
|
13417
|
+
var _a;
|
|
13418
|
+
var currentToken = this.peek();
|
|
13419
|
+
return currentToken ? currentToken[2] : (_a = this.tokenStream.tokens.at(-1)) === null || _a === void 0 ? void 0 : _a[2];
|
|
13420
|
+
};
|
|
13339
13421
|
Parser.prototype.peekAhead = function (count) {
|
|
13340
13422
|
return this.tokenStream.tokens[this.parseState.position + count];
|
|
13341
13423
|
};
|
|
@@ -13351,7 +13433,7 @@ var Parser = /** @class */ (function () {
|
|
|
13351
13433
|
}
|
|
13352
13434
|
else {
|
|
13353
13435
|
if (!this.isAtEnd()) {
|
|
13354
|
-
throw new LitsError('Expected ;', this.
|
|
13436
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13355
13437
|
}
|
|
13356
13438
|
}
|
|
13357
13439
|
}
|
|
@@ -13440,15 +13522,21 @@ var Parser = /** @class */ (function () {
|
|
|
13440
13522
|
}
|
|
13441
13523
|
return left;
|
|
13442
13524
|
};
|
|
13525
|
+
Parser.prototype.asToken = function (token) {
|
|
13526
|
+
if (!token) {
|
|
13527
|
+
throw new LitsError('Unexpected end of input', this.peekSourceCodeInfo());
|
|
13528
|
+
}
|
|
13529
|
+
return token;
|
|
13530
|
+
};
|
|
13443
13531
|
Parser.prototype.parseOperand = function () {
|
|
13444
13532
|
var operand = this.parseOperandPart();
|
|
13445
13533
|
var token = this.peek();
|
|
13446
13534
|
while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
13447
13535
|
if (token[1] === '.') {
|
|
13448
13536
|
this.advance();
|
|
13449
|
-
var symbolToken = this.peek();
|
|
13537
|
+
var symbolToken = this.asToken(this.peek());
|
|
13450
13538
|
if (!isSymbolToken(symbolToken)) {
|
|
13451
|
-
throw new LitsError('Expected symbol', this.
|
|
13539
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13452
13540
|
}
|
|
13453
13541
|
var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
|
|
13454
13542
|
operand = createAccessorNode(operand, stringNode, token[2]);
|
|
@@ -13459,7 +13547,7 @@ var Parser = /** @class */ (function () {
|
|
|
13459
13547
|
this.advance();
|
|
13460
13548
|
var expression = this.parseExpression();
|
|
13461
13549
|
if (!isRBracketToken(this.peek())) {
|
|
13462
|
-
throw new LitsError('Expected closing bracket', this.
|
|
13550
|
+
throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
|
|
13463
13551
|
}
|
|
13464
13552
|
operand = createAccessorNode(operand, expression, token[2]);
|
|
13465
13553
|
this.advance();
|
|
@@ -13473,7 +13561,7 @@ var Parser = /** @class */ (function () {
|
|
|
13473
13561
|
return operand;
|
|
13474
13562
|
};
|
|
13475
13563
|
Parser.prototype.parseOperandPart = function () {
|
|
13476
|
-
var token = this.peek();
|
|
13564
|
+
var token = this.asToken(this.peek());
|
|
13477
13565
|
// Parentheses
|
|
13478
13566
|
if (isLParenToken(token)) {
|
|
13479
13567
|
var positionBefore = this.parseState.position;
|
|
@@ -13485,7 +13573,7 @@ var Parser = /** @class */ (function () {
|
|
|
13485
13573
|
this.advance();
|
|
13486
13574
|
var expression = this.parseExpression();
|
|
13487
13575
|
if (!isRParenToken(this.peek())) {
|
|
13488
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13576
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13489
13577
|
}
|
|
13490
13578
|
this.advance();
|
|
13491
13579
|
return expression;
|
|
@@ -13545,7 +13633,7 @@ var Parser = /** @class */ (function () {
|
|
|
13545
13633
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
13546
13634
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13547
13635
|
this.advance();
|
|
13548
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13636
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13549
13637
|
}
|
|
13550
13638
|
else {
|
|
13551
13639
|
var token = this.peek();
|
|
@@ -13561,7 +13649,7 @@ var Parser = /** @class */ (function () {
|
|
|
13561
13649
|
this.advance();
|
|
13562
13650
|
}
|
|
13563
13651
|
else {
|
|
13564
|
-
throw new LitsError('Expected key to be a symbol or a string', this.
|
|
13652
|
+
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
13565
13653
|
}
|
|
13566
13654
|
assertOperatorToken(this.peek(), ':=');
|
|
13567
13655
|
this.advance();
|
|
@@ -13569,7 +13657,7 @@ var Parser = /** @class */ (function () {
|
|
|
13569
13657
|
}
|
|
13570
13658
|
var nextToken = this.peek();
|
|
13571
13659
|
if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
13572
|
-
throw new LitsError('Expected comma or closing brace', this.
|
|
13660
|
+
throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
|
|
13573
13661
|
}
|
|
13574
13662
|
if (isOperatorToken(nextToken, ',')) {
|
|
13575
13663
|
this.advance();
|
|
@@ -13586,14 +13674,14 @@ var Parser = /** @class */ (function () {
|
|
|
13586
13674
|
while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
|
|
13587
13675
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13588
13676
|
this.advance();
|
|
13589
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13677
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13590
13678
|
}
|
|
13591
13679
|
else {
|
|
13592
13680
|
params.push(this.parseExpression());
|
|
13593
13681
|
}
|
|
13594
13682
|
var nextToken = this.peek();
|
|
13595
13683
|
if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
|
|
13596
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13684
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13597
13685
|
}
|
|
13598
13686
|
if (isOperatorToken(nextToken, ',')) {
|
|
13599
13687
|
this.advance();
|
|
@@ -13604,26 +13692,27 @@ var Parser = /** @class */ (function () {
|
|
|
13604
13692
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
|
|
13605
13693
|
};
|
|
13606
13694
|
Parser.prototype.parseFunctionCall = function (symbol) {
|
|
13695
|
+
var _a;
|
|
13607
13696
|
this.advance();
|
|
13608
13697
|
var params = [];
|
|
13609
13698
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
13610
13699
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13611
13700
|
this.advance();
|
|
13612
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13701
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13613
13702
|
}
|
|
13614
13703
|
else {
|
|
13615
13704
|
params.push(this.parseExpression());
|
|
13616
13705
|
}
|
|
13617
13706
|
var nextToken = this.peek();
|
|
13618
13707
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
13619
|
-
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
13708
|
+
throw new LitsError('Expected comma or closing parenthesis', (_a = this.peek()) === null || _a === void 0 ? void 0 : _a[2]);
|
|
13620
13709
|
}
|
|
13621
13710
|
if (isOperatorToken(nextToken, ',')) {
|
|
13622
13711
|
this.advance();
|
|
13623
13712
|
}
|
|
13624
13713
|
}
|
|
13625
13714
|
if (!isRParenToken(this.peek())) {
|
|
13626
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13715
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13627
13716
|
}
|
|
13628
13717
|
this.advance();
|
|
13629
13718
|
if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
|
|
@@ -13653,14 +13742,14 @@ var Parser = /** @class */ (function () {
|
|
|
13653
13742
|
if (params.length !== 1) {
|
|
13654
13743
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13655
13744
|
}
|
|
13656
|
-
var
|
|
13745
|
+
var _b = __read(params, 1), param = _b[0];
|
|
13657
13746
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13658
13747
|
}
|
|
13659
13748
|
case specialExpressionTypes.throw: {
|
|
13660
13749
|
if (params.length !== 1) {
|
|
13661
13750
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13662
13751
|
}
|
|
13663
|
-
var
|
|
13752
|
+
var _c = __read(params, 1), param = _c[0];
|
|
13664
13753
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13665
13754
|
}
|
|
13666
13755
|
case specialExpressionTypes['0_fn']:
|
|
@@ -13680,7 +13769,7 @@ var Parser = /** @class */ (function () {
|
|
|
13680
13769
|
}
|
|
13681
13770
|
};
|
|
13682
13771
|
Parser.prototype.parseLambdaFunction = function () {
|
|
13683
|
-
var firstToken = this.peek();
|
|
13772
|
+
var firstToken = this.asToken(this.peek());
|
|
13684
13773
|
if (isLParenToken(firstToken)
|
|
13685
13774
|
&& isSymbolToken(this.peekAhead(1))
|
|
13686
13775
|
&& isOperatorToken(this.peekAhead(2), '->')) {
|
|
@@ -13714,7 +13803,7 @@ var Parser = /** @class */ (function () {
|
|
|
13714
13803
|
var functionArguments = [];
|
|
13715
13804
|
while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13716
13805
|
if (rest) {
|
|
13717
|
-
throw new LitsError('Rest argument must be last', this.
|
|
13806
|
+
throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
|
|
13718
13807
|
}
|
|
13719
13808
|
var bindingTarget = this.parseBindingTarget();
|
|
13720
13809
|
if (bindingTarget[1][1] !== undefined) {
|
|
@@ -13724,25 +13813,25 @@ var Parser = /** @class */ (function () {
|
|
|
13724
13813
|
rest = true;
|
|
13725
13814
|
}
|
|
13726
13815
|
if (defaults && !bindingTarget[1][1]) {
|
|
13727
|
-
throw new LitsError('Default arguments must be last', this.
|
|
13816
|
+
throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
|
|
13728
13817
|
}
|
|
13729
13818
|
functionArguments.push(bindingTarget);
|
|
13730
13819
|
if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13731
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13820
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13732
13821
|
}
|
|
13733
13822
|
if (isOperatorToken(this.peek(), ',')) {
|
|
13734
13823
|
this.advance();
|
|
13735
13824
|
}
|
|
13736
13825
|
}
|
|
13737
13826
|
if (!isRParenToken(this.peek())) {
|
|
13738
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13827
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13739
13828
|
}
|
|
13740
13829
|
this.advance();
|
|
13741
13830
|
return functionArguments;
|
|
13742
13831
|
};
|
|
13743
13832
|
Parser.prototype.parseShorthandLamdaFunction = function () {
|
|
13744
13833
|
var _a;
|
|
13745
|
-
var firstToken = this.peek();
|
|
13834
|
+
var firstToken = this.asToken(this.peek());
|
|
13746
13835
|
this.advance();
|
|
13747
13836
|
var startPos = this.parseState.position;
|
|
13748
13837
|
var exprNode = this.parseExpression();
|
|
@@ -13800,7 +13889,7 @@ var Parser = /** @class */ (function () {
|
|
|
13800
13889
|
}
|
|
13801
13890
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13802
13891
|
if (requireDefaultValue && !defaultValue) {
|
|
13803
|
-
throw new LitsError('Expected assignment', this.
|
|
13892
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13804
13893
|
}
|
|
13805
13894
|
return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
|
|
13806
13895
|
}
|
|
@@ -13812,7 +13901,7 @@ var Parser = /** @class */ (function () {
|
|
|
13812
13901
|
this.advance();
|
|
13813
13902
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13814
13903
|
if (isOperatorToken(this.peek(), ':=')) {
|
|
13815
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13904
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13816
13905
|
}
|
|
13817
13906
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
13818
13907
|
}
|
|
@@ -13820,7 +13909,7 @@ var Parser = /** @class */ (function () {
|
|
|
13820
13909
|
if (isLBracketToken(firstToken)) {
|
|
13821
13910
|
this.advance();
|
|
13822
13911
|
var elements = [];
|
|
13823
|
-
var token = this.peek();
|
|
13912
|
+
var token = this.asToken(this.peek());
|
|
13824
13913
|
var rest = false;
|
|
13825
13914
|
while (!isRBracketToken(token)) {
|
|
13826
13915
|
if (rest) {
|
|
@@ -13829,7 +13918,7 @@ var Parser = /** @class */ (function () {
|
|
|
13829
13918
|
if (isOperatorToken(token, ',')) {
|
|
13830
13919
|
elements.push(null);
|
|
13831
13920
|
this.advance();
|
|
13832
|
-
token = this.peek();
|
|
13921
|
+
token = this.asToken(this.peek());
|
|
13833
13922
|
continue;
|
|
13834
13923
|
}
|
|
13835
13924
|
var target = this.parseBindingTarget();
|
|
@@ -13837,17 +13926,17 @@ var Parser = /** @class */ (function () {
|
|
|
13837
13926
|
rest = true;
|
|
13838
13927
|
}
|
|
13839
13928
|
elements.push(target);
|
|
13840
|
-
token = this.peek();
|
|
13929
|
+
token = this.asToken(this.peek());
|
|
13841
13930
|
if (!isRBracketToken(token)) {
|
|
13842
13931
|
assertOperatorToken(token, ',');
|
|
13843
13932
|
this.advance();
|
|
13844
13933
|
}
|
|
13845
|
-
token = this.peek();
|
|
13934
|
+
token = this.asToken(this.peek());
|
|
13846
13935
|
}
|
|
13847
13936
|
this.advance();
|
|
13848
13937
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13849
13938
|
if (requireDefaultValue && !defaultValue) {
|
|
13850
|
-
throw new LitsError('Expected assignment', this.
|
|
13939
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13851
13940
|
}
|
|
13852
13941
|
return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
|
|
13853
13942
|
}
|
|
@@ -13855,7 +13944,7 @@ var Parser = /** @class */ (function () {
|
|
|
13855
13944
|
if (isLBraceToken(firstToken)) {
|
|
13856
13945
|
this.advance();
|
|
13857
13946
|
var elements = {};
|
|
13858
|
-
var token = this.peek();
|
|
13947
|
+
var token = this.asToken(this.peek());
|
|
13859
13948
|
var rest = false;
|
|
13860
13949
|
while (!isRBraceToken(token)) {
|
|
13861
13950
|
if (rest) {
|
|
@@ -13866,7 +13955,7 @@ var Parser = /** @class */ (function () {
|
|
|
13866
13955
|
this.advance();
|
|
13867
13956
|
}
|
|
13868
13957
|
var key = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13869
|
-
token = this.peek();
|
|
13958
|
+
token = this.asToken(this.peek());
|
|
13870
13959
|
if (isReservedSymbolToken(token, 'as')) {
|
|
13871
13960
|
if (rest) {
|
|
13872
13961
|
throw new LitsError('Rest argument can not have alias', token[2]);
|
|
@@ -13883,7 +13972,7 @@ var Parser = /** @class */ (function () {
|
|
|
13883
13972
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
13884
13973
|
}
|
|
13885
13974
|
if (rest && isOperatorToken(this.peek(), ':=')) {
|
|
13886
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13975
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13887
13976
|
}
|
|
13888
13977
|
elements[key[1]] = rest
|
|
13889
13978
|
? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
|
|
@@ -13896,17 +13985,17 @@ var Parser = /** @class */ (function () {
|
|
|
13896
13985
|
assertOperatorToken(this.peek(), ',');
|
|
13897
13986
|
this.advance();
|
|
13898
13987
|
}
|
|
13899
|
-
token = this.peek();
|
|
13988
|
+
token = this.asToken(this.peek());
|
|
13900
13989
|
}
|
|
13901
13990
|
this.advance();
|
|
13902
|
-
token = this.peek();
|
|
13991
|
+
token = this.asToken(this.peek());
|
|
13903
13992
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13904
13993
|
if (requireDefaultValue && !defaultValue) {
|
|
13905
13994
|
throw new LitsError('Expected assignment', token[2]);
|
|
13906
13995
|
}
|
|
13907
13996
|
return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
|
|
13908
13997
|
}
|
|
13909
|
-
throw new LitsError('Expected symbol', this.
|
|
13998
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13910
13999
|
};
|
|
13911
14000
|
Parser.prototype.parseLet = function (token, optionalSemicolon) {
|
|
13912
14001
|
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
@@ -13929,7 +14018,7 @@ var Parser = /** @class */ (function () {
|
|
|
13929
14018
|
this.advance();
|
|
13930
14019
|
}
|
|
13931
14020
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13932
|
-
throw new LitsError('Expected ;', this.
|
|
14021
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13933
14022
|
}
|
|
13934
14023
|
}
|
|
13935
14024
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -13953,7 +14042,7 @@ var Parser = /** @class */ (function () {
|
|
|
13953
14042
|
token = this.peek();
|
|
13954
14043
|
}
|
|
13955
14044
|
if (bindingNodes.length === 0) {
|
|
13956
|
-
throw new LitsError('Expected binding', this.
|
|
14045
|
+
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
13957
14046
|
}
|
|
13958
14047
|
assertSymbolToken(token, 'do');
|
|
13959
14048
|
this.advance();
|
|
@@ -13964,7 +14053,7 @@ var Parser = /** @class */ (function () {
|
|
|
13964
14053
|
this.advance();
|
|
13965
14054
|
}
|
|
13966
14055
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13967
|
-
throw new LitsError('Expected ;', this.
|
|
14056
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13968
14057
|
}
|
|
13969
14058
|
}
|
|
13970
14059
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -13980,7 +14069,7 @@ var Parser = /** @class */ (function () {
|
|
|
13980
14069
|
this.advance();
|
|
13981
14070
|
}
|
|
13982
14071
|
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
13983
|
-
throw new LitsError('Expected ;', this.
|
|
14072
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13984
14073
|
}
|
|
13985
14074
|
}
|
|
13986
14075
|
var tryExpression = tryExpressions.length === 1
|
|
@@ -14002,7 +14091,7 @@ var Parser = /** @class */ (function () {
|
|
|
14002
14091
|
this.advance();
|
|
14003
14092
|
}
|
|
14004
14093
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14005
|
-
throw new LitsError('Expected ;', this.
|
|
14094
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14006
14095
|
}
|
|
14007
14096
|
}
|
|
14008
14097
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14038,7 +14127,7 @@ var Parser = /** @class */ (function () {
|
|
|
14038
14127
|
this.advance();
|
|
14039
14128
|
}
|
|
14040
14129
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14041
|
-
throw new LitsError('Expected ;', this.
|
|
14130
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14042
14131
|
}
|
|
14043
14132
|
}
|
|
14044
14133
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14052,13 +14141,13 @@ var Parser = /** @class */ (function () {
|
|
|
14052
14141
|
this.advance();
|
|
14053
14142
|
var bindingNode = this.parseBinding();
|
|
14054
14143
|
var modifiers = [];
|
|
14055
|
-
var token = this.peek();
|
|
14144
|
+
var token = this.asToken(this.peek());
|
|
14056
14145
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14057
14146
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14058
14147
|
}
|
|
14059
14148
|
if (isOperatorToken(token, ',')) {
|
|
14060
14149
|
this.advance();
|
|
14061
|
-
token = this.peek();
|
|
14150
|
+
token = this.asToken(this.peek());
|
|
14062
14151
|
}
|
|
14063
14152
|
if (!isSymbolToken(token, 'let')
|
|
14064
14153
|
&& !isReservedSymbolToken(token, 'when')
|
|
@@ -14078,14 +14167,14 @@ var Parser = /** @class */ (function () {
|
|
|
14078
14167
|
throw new LitsError('Duplicate binding', letNode[1][1][2]);
|
|
14079
14168
|
}
|
|
14080
14169
|
letBindings.push(letNode[1][1]);
|
|
14081
|
-
token = this_2.peek();
|
|
14170
|
+
token = this_2.asToken(this_2.peek());
|
|
14082
14171
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14083
14172
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14084
14173
|
}
|
|
14085
14174
|
if (isOperatorToken(token, ',')) {
|
|
14086
14175
|
this_2.advance();
|
|
14087
14176
|
}
|
|
14088
|
-
token = this_2.peek();
|
|
14177
|
+
token = this_2.asToken(this_2.peek());
|
|
14089
14178
|
};
|
|
14090
14179
|
var this_2 = this;
|
|
14091
14180
|
while (isSymbolToken(token, 'let')) {
|
|
@@ -14111,14 +14200,14 @@ var Parser = /** @class */ (function () {
|
|
|
14111
14200
|
modifiers.push('&while');
|
|
14112
14201
|
whileNode = this.parseExpression();
|
|
14113
14202
|
}
|
|
14114
|
-
token = this.peek();
|
|
14203
|
+
token = this.asToken(this.peek());
|
|
14115
14204
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14116
14205
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14117
14206
|
}
|
|
14118
14207
|
if (isOperatorToken(token, ',')) {
|
|
14119
14208
|
this.advance();
|
|
14120
14209
|
}
|
|
14121
|
-
token = this.peek();
|
|
14210
|
+
token = this.asToken(this.peek());
|
|
14122
14211
|
}
|
|
14123
14212
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
|
|
14124
14213
|
throw new LitsError('Expected do or each', token[2]);
|
|
@@ -14155,7 +14244,7 @@ var Parser = /** @class */ (function () {
|
|
|
14155
14244
|
this.advance();
|
|
14156
14245
|
}
|
|
14157
14246
|
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14158
|
-
throw new LitsError('Expected ;', this.
|
|
14247
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14159
14248
|
}
|
|
14160
14249
|
}
|
|
14161
14250
|
var thenExpression = thenExpressions.length === 1
|
|
@@ -14171,7 +14260,7 @@ var Parser = /** @class */ (function () {
|
|
|
14171
14260
|
this.advance();
|
|
14172
14261
|
}
|
|
14173
14262
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14174
|
-
throw new LitsError('Expected ;', this.
|
|
14263
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14175
14264
|
}
|
|
14176
14265
|
}
|
|
14177
14266
|
elseExpression = elseExpressions.length === 1
|
|
@@ -14202,7 +14291,7 @@ var Parser = /** @class */ (function () {
|
|
|
14202
14291
|
this.advance();
|
|
14203
14292
|
}
|
|
14204
14293
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14205
|
-
throw new LitsError('Expected ;', this.
|
|
14294
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14206
14295
|
}
|
|
14207
14296
|
}
|
|
14208
14297
|
var thenExpression = expressions.length === 1
|
|
@@ -14237,7 +14326,7 @@ var Parser = /** @class */ (function () {
|
|
|
14237
14326
|
this.advance();
|
|
14238
14327
|
}
|
|
14239
14328
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14240
|
-
throw new LitsError('Expected ;', this.
|
|
14329
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14241
14330
|
}
|
|
14242
14331
|
}
|
|
14243
14332
|
var thenExpression = expressions.length === 1
|
|
@@ -14264,7 +14353,7 @@ var Parser = /** @class */ (function () {
|
|
|
14264
14353
|
this.advance();
|
|
14265
14354
|
}
|
|
14266
14355
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14267
|
-
throw new LitsError('Expected ;', this.
|
|
14356
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14268
14357
|
}
|
|
14269
14358
|
}
|
|
14270
14359
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14308,7 +14397,7 @@ var Parser = /** @class */ (function () {
|
|
|
14308
14397
|
this.advance();
|
|
14309
14398
|
}
|
|
14310
14399
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14311
|
-
throw new LitsError('Expected ;', this.
|
|
14400
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14312
14401
|
}
|
|
14313
14402
|
}
|
|
14314
14403
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14319,7 +14408,7 @@ var Parser = /** @class */ (function () {
|
|
|
14319
14408
|
]]], token[2]);
|
|
14320
14409
|
}
|
|
14321
14410
|
else {
|
|
14322
|
-
throw new LitsError('Expected let or function', this.
|
|
14411
|
+
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|
|
14323
14412
|
}
|
|
14324
14413
|
};
|
|
14325
14414
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -14344,7 +14433,7 @@ var Parser = /** @class */ (function () {
|
|
|
14344
14433
|
});
|
|
14345
14434
|
};
|
|
14346
14435
|
Parser.prototype.parseSymbol = function () {
|
|
14347
|
-
var token = this.peek();
|
|
14436
|
+
var token = this.asToken(this.peek());
|
|
14348
14437
|
this.advance();
|
|
14349
14438
|
if (!isSymbolToken(token)) {
|
|
14350
14439
|
throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
|
|
@@ -14366,7 +14455,7 @@ var Parser = /** @class */ (function () {
|
|
|
14366
14455
|
return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
|
|
14367
14456
|
};
|
|
14368
14457
|
Parser.prototype.parseNumber = function () {
|
|
14369
|
-
var token = this.peek();
|
|
14458
|
+
var token = this.asToken(this.peek());
|
|
14370
14459
|
this.advance();
|
|
14371
14460
|
var value = token[1];
|
|
14372
14461
|
var negative = value[0] === '-';
|
|
@@ -14374,7 +14463,7 @@ var Parser = /** @class */ (function () {
|
|
|
14374
14463
|
return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
|
|
14375
14464
|
};
|
|
14376
14465
|
Parser.prototype.parseString = function () {
|
|
14377
|
-
var token = this.peek();
|
|
14466
|
+
var token = this.asToken(this.peek());
|
|
14378
14467
|
this.advance();
|
|
14379
14468
|
var value = token[1].substring(1, token[1].length - 1)
|
|
14380
14469
|
.replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
|
|
@@ -14406,7 +14495,7 @@ var Parser = /** @class */ (function () {
|
|
|
14406
14495
|
return withSourceCodeInfo([NodeTypes.String, value], token[2]);
|
|
14407
14496
|
};
|
|
14408
14497
|
Parser.prototype.parseRegexpShorthand = function () {
|
|
14409
|
-
var token = this.peek();
|
|
14498
|
+
var token = this.asToken(this.peek());
|
|
14410
14499
|
this.advance();
|
|
14411
14500
|
var endStringPosition = token[1].lastIndexOf('"');
|
|
14412
14501
|
var regexpString = token[1].substring(2, endStringPosition);
|
|
@@ -14768,6 +14857,11 @@ function getVectorReductionNames(name) {
|
|
|
14768
14857
|
}
|
|
14769
14858
|
var api = {
|
|
14770
14859
|
collection: [
|
|
14860
|
+
'filter',
|
|
14861
|
+
'map',
|
|
14862
|
+
'reduce',
|
|
14863
|
+
'reduce-right',
|
|
14864
|
+
'reductions',
|
|
14771
14865
|
'count',
|
|
14772
14866
|
'get',
|
|
14773
14867
|
'get-in',
|
|
@@ -14797,11 +14891,6 @@ var api = {
|
|
|
14797
14891
|
'shift',
|
|
14798
14892
|
'slice',
|
|
14799
14893
|
'splice',
|
|
14800
|
-
'reductions',
|
|
14801
|
-
'reduce',
|
|
14802
|
-
'reduce-right',
|
|
14803
|
-
'map',
|
|
14804
|
-
'filter',
|
|
14805
14894
|
'position',
|
|
14806
14895
|
'index-of',
|
|
14807
14896
|
'last-index-of',
|
|
@@ -14874,9 +14963,9 @@ var api = {
|
|
|
14874
14963
|
'atanh',
|
|
14875
14964
|
],
|
|
14876
14965
|
functional: [
|
|
14966
|
+
'|>',
|
|
14877
14967
|
'apply',
|
|
14878
14968
|
'identity',
|
|
14879
|
-
'partial',
|
|
14880
14969
|
'comp',
|
|
14881
14970
|
'constantly',
|
|
14882
14971
|
'juxt',
|
|
@@ -15304,7 +15393,6 @@ var arrayReference = {
|
|
|
15304
15393
|
examples: [
|
|
15305
15394
|
'flatten([1, 2, [3, 4], 5])',
|
|
15306
15395
|
"\nlet foo := \"bar\";\nflatten([\n 1,\n \" 2 A \",\n [foo, [4, [\"ABC\"]]],\n 6,\n])",
|
|
15307
|
-
'flatten(12)',
|
|
15308
15396
|
],
|
|
15309
15397
|
noOperatorDocumentation: true,
|
|
15310
15398
|
},
|
|
@@ -15971,6 +16059,142 @@ var bitwiseReference = {
|
|
|
15971
16059
|
};
|
|
15972
16060
|
|
|
15973
16061
|
var collectionReference = {
|
|
16062
|
+
'filter': {
|
|
16063
|
+
title: 'filter',
|
|
16064
|
+
category: 'Collection',
|
|
16065
|
+
linkName: 'filter',
|
|
16066
|
+
returns: {
|
|
16067
|
+
type: 'collection',
|
|
16068
|
+
},
|
|
16069
|
+
args: __assign(__assign({}, getOperatorArgs('collection', 'function')), { coll: {
|
|
16070
|
+
type: 'collection',
|
|
16071
|
+
}, fun: {
|
|
16072
|
+
type: 'function',
|
|
16073
|
+
} }),
|
|
16074
|
+
variants: [
|
|
16075
|
+
{ argumentNames: ['coll', 'fun'] },
|
|
16076
|
+
],
|
|
16077
|
+
description: 'Creates a new collection with all elements that pass the test implemented by $fun.',
|
|
16078
|
+
examples: [
|
|
16079
|
+
"\nfilter(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)",
|
|
16080
|
+
"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)",
|
|
16081
|
+
"\nfilter(\n { a := 1, b := 2 },\n odd?\n)",
|
|
16082
|
+
],
|
|
16083
|
+
},
|
|
16084
|
+
'map': {
|
|
16085
|
+
title: 'map',
|
|
16086
|
+
category: 'Collection',
|
|
16087
|
+
linkName: 'map',
|
|
16088
|
+
returns: {
|
|
16089
|
+
type: 'collection',
|
|
16090
|
+
},
|
|
16091
|
+
args: __assign(__assign({}, getOperatorArgs('collection', 'function')), { colls: {
|
|
16092
|
+
type: 'collection',
|
|
16093
|
+
rest: true,
|
|
16094
|
+
description: 'At least one.',
|
|
16095
|
+
}, fun: {
|
|
16096
|
+
type: 'function',
|
|
16097
|
+
} }),
|
|
16098
|
+
variants: [
|
|
16099
|
+
{ argumentNames: ['colls', 'fun'] },
|
|
16100
|
+
],
|
|
16101
|
+
description: 'Creates a new collection populated with the results of calling $fun on every element in $colls.',
|
|
16102
|
+
examples: [
|
|
16103
|
+
'[1, 2, 3] map -',
|
|
16104
|
+
'[1, 2, 3] map -> -($)',
|
|
16105
|
+
'map(["Albert", "Mojir", 42], str)',
|
|
16106
|
+
'map([1, 2, 3], inc)',
|
|
16107
|
+
'map([1, 2, 3], [1, 10, 100], *)',
|
|
16108
|
+
'map({ a := 1, b := 2 }, inc)',
|
|
16109
|
+
'map({ a := 1, b := 2 }, { a := 10, b := 20 }, +)',
|
|
16110
|
+
],
|
|
16111
|
+
},
|
|
16112
|
+
'reduce': {
|
|
16113
|
+
title: 'reduce',
|
|
16114
|
+
category: 'Collection',
|
|
16115
|
+
linkName: 'reduce',
|
|
16116
|
+
returns: {
|
|
16117
|
+
type: 'any',
|
|
16118
|
+
},
|
|
16119
|
+
args: {
|
|
16120
|
+
fun: {
|
|
16121
|
+
type: 'function',
|
|
16122
|
+
},
|
|
16123
|
+
coll: {
|
|
16124
|
+
type: 'collection',
|
|
16125
|
+
},
|
|
16126
|
+
initial: {
|
|
16127
|
+
type: 'any',
|
|
16128
|
+
},
|
|
16129
|
+
},
|
|
16130
|
+
variants: [
|
|
16131
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16132
|
+
],
|
|
16133
|
+
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.',
|
|
16134
|
+
examples: [
|
|
16135
|
+
'reduce([1, 2, 3], +, 0)',
|
|
16136
|
+
'reduce([], +, 0)',
|
|
16137
|
+
'reduce({ a := 1, b := 2 }, +, 0)',
|
|
16138
|
+
"\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)",
|
|
16139
|
+
],
|
|
16140
|
+
},
|
|
16141
|
+
'reduce-right': {
|
|
16142
|
+
title: 'reduce-right',
|
|
16143
|
+
category: 'Collection',
|
|
16144
|
+
linkName: 'reduce-right',
|
|
16145
|
+
returns: {
|
|
16146
|
+
type: 'any',
|
|
16147
|
+
},
|
|
16148
|
+
args: {
|
|
16149
|
+
fun: {
|
|
16150
|
+
type: 'function',
|
|
16151
|
+
},
|
|
16152
|
+
coll: {
|
|
16153
|
+
type: 'collection',
|
|
16154
|
+
},
|
|
16155
|
+
initial: {
|
|
16156
|
+
type: 'any',
|
|
16157
|
+
},
|
|
16158
|
+
},
|
|
16159
|
+
variants: [
|
|
16160
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16161
|
+
],
|
|
16162
|
+
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.',
|
|
16163
|
+
examples: [
|
|
16164
|
+
'reduce-right(["A", "B", "C"], str, "")',
|
|
16165
|
+
'reduce-right({ a := 1, b := 2 }, +, 0)',
|
|
16166
|
+
],
|
|
16167
|
+
},
|
|
16168
|
+
'reductions': {
|
|
16169
|
+
title: 'reductions',
|
|
16170
|
+
category: 'Collection',
|
|
16171
|
+
linkName: 'reductions',
|
|
16172
|
+
returns: {
|
|
16173
|
+
type: 'any',
|
|
16174
|
+
},
|
|
16175
|
+
args: {
|
|
16176
|
+
fun: {
|
|
16177
|
+
type: 'function',
|
|
16178
|
+
},
|
|
16179
|
+
coll: {
|
|
16180
|
+
type: 'collection',
|
|
16181
|
+
},
|
|
16182
|
+
initial: {
|
|
16183
|
+
type: 'any',
|
|
16184
|
+
},
|
|
16185
|
+
},
|
|
16186
|
+
variants: [
|
|
16187
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16188
|
+
],
|
|
16189
|
+
description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.',
|
|
16190
|
+
examples: [
|
|
16191
|
+
'reductions([1, 2, 3], +, 0)',
|
|
16192
|
+
'reductions([1, 2, 3], +, 10)',
|
|
16193
|
+
'reductions([], +, 0)',
|
|
16194
|
+
'reductions({ a := 1, b := 2 }, +, 0)',
|
|
16195
|
+
"\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)",
|
|
16196
|
+
],
|
|
16197
|
+
},
|
|
15974
16198
|
'count': {
|
|
15975
16199
|
title: 'count',
|
|
15976
16200
|
category: 'Collection',
|
|
@@ -16354,6 +16578,23 @@ var collectionReference = {
|
|
|
16354
16578
|
};
|
|
16355
16579
|
|
|
16356
16580
|
var functionalReference = {
|
|
16581
|
+
'|>': {
|
|
16582
|
+
title: '|>',
|
|
16583
|
+
category: 'Functional',
|
|
16584
|
+
linkName: '-or-gt',
|
|
16585
|
+
returns: {
|
|
16586
|
+
type: 'any',
|
|
16587
|
+
},
|
|
16588
|
+
args: __assign({}, getOperatorArgs('any', 'function')),
|
|
16589
|
+
variants: [
|
|
16590
|
+
{ argumentNames: ['a', 'b'] },
|
|
16591
|
+
],
|
|
16592
|
+
description: 'Takes a value $a and a function $b, and returns the result of applying $b to $a.',
|
|
16593
|
+
examples: [
|
|
16594
|
+
"\n1 |> inc |> inc",
|
|
16595
|
+
"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)",
|
|
16596
|
+
],
|
|
16597
|
+
},
|
|
16357
16598
|
'apply': {
|
|
16358
16599
|
title: 'apply',
|
|
16359
16600
|
category: 'Functional',
|
|
@@ -16394,33 +16635,6 @@ var functionalReference = {
|
|
|
16394
16635
|
description: 'Returns $x.',
|
|
16395
16636
|
examples: ['identity(1)', 'identity("Albert")', 'identity({ a := 1 })', 'identity(null)'],
|
|
16396
16637
|
},
|
|
16397
|
-
'partial': {
|
|
16398
|
-
title: 'partial',
|
|
16399
|
-
category: 'Functional',
|
|
16400
|
-
linkName: 'partial',
|
|
16401
|
-
returns: {
|
|
16402
|
-
type: 'function',
|
|
16403
|
-
},
|
|
16404
|
-
args: {
|
|
16405
|
-
fun: {
|
|
16406
|
-
type: 'function',
|
|
16407
|
-
},
|
|
16408
|
-
args: {
|
|
16409
|
-
type: 'any',
|
|
16410
|
-
rest: true,
|
|
16411
|
-
},
|
|
16412
|
-
},
|
|
16413
|
-
variants: [
|
|
16414
|
-
{ argumentNames: ['fun', 'args'] },
|
|
16415
|
-
],
|
|
16416
|
-
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)`.",
|
|
16417
|
-
examples: [
|
|
16418
|
-
'partial(+, 100)',
|
|
16419
|
-
"\nlet plusMany := partial(+, 100, 1000);\nplusMany(1, 10)",
|
|
16420
|
-
"\nlet addHundred := partial(+, 100);\naddHundred(10)",
|
|
16421
|
-
],
|
|
16422
|
-
noOperatorDocumentation: true,
|
|
16423
|
-
},
|
|
16424
16638
|
'comp': {
|
|
16425
16639
|
title: 'comp',
|
|
16426
16640
|
category: 'Functional',
|
|
@@ -24732,134 +24946,6 @@ var sequenceReference = {
|
|
|
24732
24946
|
'splice("Albert", 2, 2, "fo")',
|
|
24733
24947
|
],
|
|
24734
24948
|
},
|
|
24735
|
-
'reductions': {
|
|
24736
|
-
title: 'reductions',
|
|
24737
|
-
category: 'Sequence',
|
|
24738
|
-
linkName: 'reductions',
|
|
24739
|
-
returns: {
|
|
24740
|
-
type: 'any',
|
|
24741
|
-
rest: true,
|
|
24742
|
-
},
|
|
24743
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24744
|
-
type: 'function',
|
|
24745
|
-
}, seq: {
|
|
24746
|
-
type: 'sequence',
|
|
24747
|
-
rest: true,
|
|
24748
|
-
}, start: {
|
|
24749
|
-
type: 'any',
|
|
24750
|
-
} }),
|
|
24751
|
-
variants: [
|
|
24752
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24753
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24754
|
-
],
|
|
24755
|
-
description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $seq by $fun.',
|
|
24756
|
-
examples: [
|
|
24757
|
-
'[1, 2, 3] reductions +',
|
|
24758
|
-
'reductions([1, 2, 3], +)',
|
|
24759
|
-
'reductions([1, 2, 3], +, 10)',
|
|
24760
|
-
'reductions([], +, 0)',
|
|
24761
|
-
"\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)",
|
|
24762
|
-
],
|
|
24763
|
-
},
|
|
24764
|
-
'reduce': {
|
|
24765
|
-
title: 'reduce',
|
|
24766
|
-
category: 'Sequence',
|
|
24767
|
-
linkName: 'reduce',
|
|
24768
|
-
returns: {
|
|
24769
|
-
type: 'any',
|
|
24770
|
-
},
|
|
24771
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24772
|
-
type: 'function',
|
|
24773
|
-
}, seq: {
|
|
24774
|
-
type: 'sequence',
|
|
24775
|
-
}, start: {
|
|
24776
|
-
type: 'any',
|
|
24777
|
-
} }),
|
|
24778
|
-
variants: [
|
|
24779
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24780
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24781
|
-
],
|
|
24782
|
-
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.',
|
|
24783
|
-
examples: [
|
|
24784
|
-
'[1, 2, 3] reduce +',
|
|
24785
|
-
'reduce([1, 2, 3], +)',
|
|
24786
|
-
'reduce([1, 2, 3], +, 0)',
|
|
24787
|
-
'reduce([], +, 0)',
|
|
24788
|
-
"\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)",
|
|
24789
|
-
],
|
|
24790
|
-
},
|
|
24791
|
-
'reduce-right': {
|
|
24792
|
-
title: 'reduce-right',
|
|
24793
|
-
category: 'Sequence',
|
|
24794
|
-
linkName: 'reduce-right',
|
|
24795
|
-
returns: {
|
|
24796
|
-
type: 'sequence',
|
|
24797
|
-
},
|
|
24798
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { fun: {
|
|
24799
|
-
type: 'function',
|
|
24800
|
-
}, seq: {
|
|
24801
|
-
type: 'sequence',
|
|
24802
|
-
}, start: {
|
|
24803
|
-
type: 'any',
|
|
24804
|
-
} }),
|
|
24805
|
-
variants: [
|
|
24806
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24807
|
-
{ argumentNames: ['seq', 'fun', 'start'] },
|
|
24808
|
-
],
|
|
24809
|
-
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.',
|
|
24810
|
-
examples: [
|
|
24811
|
-
'range(1, 10) reduce-right *',
|
|
24812
|
-
'reduce-right(["A", "B", "C"], str, "")',
|
|
24813
|
-
],
|
|
24814
|
-
},
|
|
24815
|
-
'map': {
|
|
24816
|
-
title: 'map',
|
|
24817
|
-
category: 'Sequence',
|
|
24818
|
-
linkName: 'map',
|
|
24819
|
-
returns: {
|
|
24820
|
-
type: 'any',
|
|
24821
|
-
rest: true,
|
|
24822
|
-
},
|
|
24823
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seqs: {
|
|
24824
|
-
type: 'sequence',
|
|
24825
|
-
rest: true,
|
|
24826
|
-
description: 'At least one.',
|
|
24827
|
-
}, fun: {
|
|
24828
|
-
type: 'function',
|
|
24829
|
-
} }),
|
|
24830
|
-
variants: [
|
|
24831
|
-
{ argumentNames: ['seqs', 'fun'] },
|
|
24832
|
-
],
|
|
24833
|
-
description: 'Creates a new array populated with the results of calling $fun on every element in $seqs.',
|
|
24834
|
-
examples: [
|
|
24835
|
-
'[1, 2, 3] map -',
|
|
24836
|
-
'[1, 2, 3] map -> -($)',
|
|
24837
|
-
'map(["Albert", "Mojir", 42], str)',
|
|
24838
|
-
'map([1, 2, 3], inc)',
|
|
24839
|
-
'map([1, 2, 3], [1, 10, 100], *)',
|
|
24840
|
-
],
|
|
24841
|
-
},
|
|
24842
|
-
'filter': {
|
|
24843
|
-
title: 'filter',
|
|
24844
|
-
category: 'Sequence',
|
|
24845
|
-
linkName: 'filter',
|
|
24846
|
-
returns: {
|
|
24847
|
-
type: 'sequence',
|
|
24848
|
-
},
|
|
24849
|
-
args: __assign(__assign({}, getOperatorArgs('sequence', 'function')), { seq: {
|
|
24850
|
-
type: 'sequence',
|
|
24851
|
-
}, fun: {
|
|
24852
|
-
type: 'function',
|
|
24853
|
-
} }),
|
|
24854
|
-
variants: [
|
|
24855
|
-
{ argumentNames: ['seq', 'fun'] },
|
|
24856
|
-
],
|
|
24857
|
-
description: 'Creates a new array with all elements that pass the test implemented by $fun.',
|
|
24858
|
-
examples: [
|
|
24859
|
-
"\nfilter(\n [\"Albert\", \"Mojir\", 160, [1, 2]],\n string?\n)",
|
|
24860
|
-
"\nfilter(\n [5, 10, 15, 20],\n -> $ > 10\n)",
|
|
24861
|
-
],
|
|
24862
|
-
},
|
|
24863
24949
|
'position': {
|
|
24864
24950
|
title: 'position',
|
|
24865
24951
|
category: 'Sequence',
|