@mojir/lits 2.1.6 → 2.1.8
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 +120 -83
- package/dist/cli/src/parser/Parser.d.ts +3 -1
- package/dist/cli/src/tokenizer/token.d.ts +51 -51
- package/dist/index.esm.js +119 -82
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +119 -82
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +119 -82
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/parser/Parser.d.ts +3 -1
- package/dist/src/tokenizer/token.d.ts +51 -51
- package/dist/testFramework.esm.js +118 -81
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +118 -81
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1429,13 +1429,15 @@ var arrayNormalExpression = {
|
|
|
1429
1429
|
paramCount: 2,
|
|
1430
1430
|
},
|
|
1431
1431
|
flatten: {
|
|
1432
|
-
evaluate: function (_a) {
|
|
1433
|
-
var _b = __read(_a,
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1432
|
+
evaluate: function (_a, sourceCodeInfo) {
|
|
1433
|
+
var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
|
|
1434
|
+
assertArray(seq, sourceCodeInfo);
|
|
1435
|
+
var actualDepth = depth === undefined || depth === Number.POSITIVE_INFINITY
|
|
1436
|
+
? Number.POSITIVE_INFINITY
|
|
1437
|
+
: asNumber(depth, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
1438
|
+
return seq.flat(actualDepth);
|
|
1437
1439
|
},
|
|
1438
|
-
paramCount: 1,
|
|
1440
|
+
paramCount: { min: 1, max: 2 },
|
|
1439
1441
|
},
|
|
1440
1442
|
mapcat: {
|
|
1441
1443
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -3885,6 +3887,13 @@ var regexpNormalExpression = {
|
|
|
3885
3887
|
assertString(sourceArg, sourceCodeInfo);
|
|
3886
3888
|
var source = sourceArg || '(?:)';
|
|
3887
3889
|
var flags = typeof flagsArg === 'string' ? flagsArg : '';
|
|
3890
|
+
try {
|
|
3891
|
+
// eslint-disable-next-line no-new
|
|
3892
|
+
new RegExp(source, flags); // Throws if invalid regexp
|
|
3893
|
+
}
|
|
3894
|
+
catch (e) {
|
|
3895
|
+
throw new LitsError("Invalid regular expression: ".concat(source, " ").concat(flags), sourceCodeInfo);
|
|
3896
|
+
}
|
|
3888
3897
|
return _b = {},
|
|
3889
3898
|
_b[REGEXP_SYMBOL] = true,
|
|
3890
3899
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
@@ -4613,6 +4622,7 @@ var gridNormalExpression = {
|
|
|
4613
4622
|
return transpose(grid);
|
|
4614
4623
|
},
|
|
4615
4624
|
paramCount: 1,
|
|
4625
|
+
aliases: ['grid:tr'],
|
|
4616
4626
|
},
|
|
4617
4627
|
'grid:flip-h': {
|
|
4618
4628
|
evaluate: function (_a, sourceCodeInfo) {
|
|
@@ -6991,10 +7001,10 @@ var linearAlgebraNormalExpression = {
|
|
|
6991
7001
|
assertVector(vectorA, sourceCodeInfo);
|
|
6992
7002
|
assertVector(vectorB, sourceCodeInfo);
|
|
6993
7003
|
if (vectorA.length < 2) {
|
|
6994
|
-
throw new
|
|
7004
|
+
throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
|
|
6995
7005
|
}
|
|
6996
7006
|
if (vectorA.length !== vectorB.length) {
|
|
6997
|
-
throw new
|
|
7007
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
6998
7008
|
}
|
|
6999
7009
|
assertNumber(lag, sourceCodeInfo, {
|
|
7000
7010
|
integer: true,
|
|
@@ -8246,7 +8256,7 @@ var partitionsNormalExpressions = {
|
|
|
8246
8256
|
if (n === 0)
|
|
8247
8257
|
return 1;
|
|
8248
8258
|
if (n > partitionNumbers.length) {
|
|
8249
|
-
throw new
|
|
8259
|
+
throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
|
|
8250
8260
|
}
|
|
8251
8261
|
return partitionNumbers[n - 1];
|
|
8252
8262
|
},
|
|
@@ -10385,7 +10395,12 @@ var combinatoricalNormalExpression = {
|
|
|
10385
10395
|
var _b = __read(_a, 2), a = _b[0], m = _b[1];
|
|
10386
10396
|
assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
|
|
10387
10397
|
assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
|
|
10388
|
-
|
|
10398
|
+
try {
|
|
10399
|
+
return modInverse(a, m);
|
|
10400
|
+
}
|
|
10401
|
+
catch (error) {
|
|
10402
|
+
throw new LitsError(error, sourceCodeInfo);
|
|
10403
|
+
}
|
|
10389
10404
|
},
|
|
10390
10405
|
paramCount: 2,
|
|
10391
10406
|
},
|
|
@@ -10404,7 +10419,7 @@ var combinatoricalNormalExpression = {
|
|
|
10404
10419
|
assertVector(remainders, sourceCodeInfo);
|
|
10405
10420
|
assertVector(moduli, sourceCodeInfo);
|
|
10406
10421
|
if (remainders.length !== moduli.length) {
|
|
10407
|
-
throw new
|
|
10422
|
+
throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
|
|
10408
10423
|
}
|
|
10409
10424
|
try {
|
|
10410
10425
|
return chineseRemainder(remainders, moduli);
|
|
@@ -11913,7 +11928,11 @@ var objectSpecialExpression = {
|
|
|
11913
11928
|
}
|
|
11914
11929
|
else {
|
|
11915
11930
|
var key = evaluateNode(keyNode, contextStack);
|
|
11916
|
-
var
|
|
11931
|
+
var valueNode = params[i + 1];
|
|
11932
|
+
if (valueNode === undefined) {
|
|
11933
|
+
throw new LitsError('Missing value for key', keyNode[2]);
|
|
11934
|
+
}
|
|
11935
|
+
var value = evaluateNode(valueNode, contextStack);
|
|
11917
11936
|
assertString(key, keyNode[2]);
|
|
11918
11937
|
result[key] = value;
|
|
11919
11938
|
}
|
|
@@ -12894,21 +12913,30 @@ var tokenizeNumber = function (input, position) {
|
|
|
12894
12913
|
var char = input[i];
|
|
12895
12914
|
if (char === '_') {
|
|
12896
12915
|
if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
|
|
12897
|
-
|
|
12916
|
+
if (i === start) {
|
|
12917
|
+
return NO_MATCH;
|
|
12918
|
+
}
|
|
12919
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12898
12920
|
}
|
|
12899
12921
|
}
|
|
12900
12922
|
else if (char === '.') {
|
|
12901
|
-
if (i === start
|
|
12923
|
+
if (i === start) {
|
|
12902
12924
|
return NO_MATCH;
|
|
12903
12925
|
}
|
|
12926
|
+
if (hasDecimalPoint || hasExponent) {
|
|
12927
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12928
|
+
}
|
|
12904
12929
|
hasDecimalPoint = true;
|
|
12905
12930
|
}
|
|
12906
12931
|
else if (char === 'e' || char === 'E') {
|
|
12907
|
-
if (i === start
|
|
12932
|
+
if (i === start) {
|
|
12908
12933
|
return NO_MATCH;
|
|
12909
12934
|
}
|
|
12935
|
+
if (hasExponent) {
|
|
12936
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12937
|
+
}
|
|
12910
12938
|
if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
|
|
12911
|
-
|
|
12939
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12912
12940
|
}
|
|
12913
12941
|
if (input[i + 1] === '+' || input[i + 1] === '-') {
|
|
12914
12942
|
i += 1;
|
|
@@ -12928,7 +12956,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
12928
12956
|
}
|
|
12929
12957
|
var nextChar = input[i];
|
|
12930
12958
|
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
12931
|
-
|
|
12959
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12932
12960
|
}
|
|
12933
12961
|
return [length, ['Number', input.substring(position, i)]];
|
|
12934
12962
|
};
|
|
@@ -13094,10 +13122,10 @@ function tokenize(input, debug, filePath) {
|
|
|
13094
13122
|
hasDebugData: debug,
|
|
13095
13123
|
};
|
|
13096
13124
|
while (position < input.length) {
|
|
13097
|
-
var tokenDescriptor = getCurrentToken(input, position);
|
|
13098
13125
|
var sourceCodeInfo = debug
|
|
13099
13126
|
? createSourceCodeInfo(input, position, filePath)
|
|
13100
13127
|
: undefined;
|
|
13128
|
+
var tokenDescriptor = getCurrentToken(input, position);
|
|
13101
13129
|
if (!tokenDescriptor) {
|
|
13102
13130
|
throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
|
|
13103
13131
|
}
|
|
@@ -13207,9 +13235,6 @@ function isOperatorToken(token, operatorName) {
|
|
|
13207
13235
|
}
|
|
13208
13236
|
function assertOperatorToken(token, operatorName) {
|
|
13209
13237
|
if (!isOperatorToken(token, operatorName)) {
|
|
13210
|
-
if (operatorName) {
|
|
13211
|
-
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
|
|
13212
|
-
}
|
|
13213
13238
|
throwUnexpectedToken('Operator', operatorName, token);
|
|
13214
13239
|
}
|
|
13215
13240
|
}
|
|
@@ -13279,8 +13304,8 @@ function isA_BinaryOperatorToken(token) {
|
|
|
13279
13304
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
|
|
13280
13305
|
}
|
|
13281
13306
|
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
13282
|
-
var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
|
|
13283
|
-
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual[2]);
|
|
13307
|
+
var actualOutput = actual ? "".concat(actual[0], " '").concat(actual[1], "'") : 'end of input';
|
|
13308
|
+
throw new LitsError("Unexpected token: ".concat(actualOutput, ", expected ").concat(expected).concat(expectedValue ? " '".concat(expectedValue, "'") : ''), actual === null || actual === void 0 ? void 0 : actual[2]);
|
|
13284
13309
|
}
|
|
13285
13310
|
|
|
13286
13311
|
function minifyTokenStream(tokenStream, _a) {
|
|
@@ -13428,6 +13453,11 @@ var Parser = /** @class */ (function () {
|
|
|
13428
13453
|
Parser.prototype.peek = function () {
|
|
13429
13454
|
return this.tokenStream.tokens[this.parseState.position];
|
|
13430
13455
|
};
|
|
13456
|
+
Parser.prototype.peekSourceCodeInfo = function () {
|
|
13457
|
+
var _a;
|
|
13458
|
+
var currentToken = this.peek();
|
|
13459
|
+
return currentToken ? currentToken[2] : (_a = this.tokenStream.tokens.at(-1)) === null || _a === void 0 ? void 0 : _a[2];
|
|
13460
|
+
};
|
|
13431
13461
|
Parser.prototype.peekAhead = function (count) {
|
|
13432
13462
|
return this.tokenStream.tokens[this.parseState.position + count];
|
|
13433
13463
|
};
|
|
@@ -13443,7 +13473,7 @@ var Parser = /** @class */ (function () {
|
|
|
13443
13473
|
}
|
|
13444
13474
|
else {
|
|
13445
13475
|
if (!this.isAtEnd()) {
|
|
13446
|
-
throw new LitsError('Expected ;', this.
|
|
13476
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13447
13477
|
}
|
|
13448
13478
|
}
|
|
13449
13479
|
}
|
|
@@ -13532,15 +13562,21 @@ var Parser = /** @class */ (function () {
|
|
|
13532
13562
|
}
|
|
13533
13563
|
return left;
|
|
13534
13564
|
};
|
|
13565
|
+
Parser.prototype.asToken = function (token) {
|
|
13566
|
+
if (!token) {
|
|
13567
|
+
throw new LitsError('Unexpected end of input', this.peekSourceCodeInfo());
|
|
13568
|
+
}
|
|
13569
|
+
return token;
|
|
13570
|
+
};
|
|
13535
13571
|
Parser.prototype.parseOperand = function () {
|
|
13536
13572
|
var operand = this.parseOperandPart();
|
|
13537
13573
|
var token = this.peek();
|
|
13538
13574
|
while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
13539
13575
|
if (token[1] === '.') {
|
|
13540
13576
|
this.advance();
|
|
13541
|
-
var symbolToken = this.peek();
|
|
13577
|
+
var symbolToken = this.asToken(this.peek());
|
|
13542
13578
|
if (!isSymbolToken(symbolToken)) {
|
|
13543
|
-
throw new LitsError('Expected symbol', this.
|
|
13579
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13544
13580
|
}
|
|
13545
13581
|
var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
|
|
13546
13582
|
operand = createAccessorNode(operand, stringNode, token[2]);
|
|
@@ -13551,7 +13587,7 @@ var Parser = /** @class */ (function () {
|
|
|
13551
13587
|
this.advance();
|
|
13552
13588
|
var expression = this.parseExpression();
|
|
13553
13589
|
if (!isRBracketToken(this.peek())) {
|
|
13554
|
-
throw new LitsError('Expected closing bracket', this.
|
|
13590
|
+
throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
|
|
13555
13591
|
}
|
|
13556
13592
|
operand = createAccessorNode(operand, expression, token[2]);
|
|
13557
13593
|
this.advance();
|
|
@@ -13565,7 +13601,7 @@ var Parser = /** @class */ (function () {
|
|
|
13565
13601
|
return operand;
|
|
13566
13602
|
};
|
|
13567
13603
|
Parser.prototype.parseOperandPart = function () {
|
|
13568
|
-
var token = this.peek();
|
|
13604
|
+
var token = this.asToken(this.peek());
|
|
13569
13605
|
// Parentheses
|
|
13570
13606
|
if (isLParenToken(token)) {
|
|
13571
13607
|
var positionBefore = this.parseState.position;
|
|
@@ -13577,7 +13613,7 @@ var Parser = /** @class */ (function () {
|
|
|
13577
13613
|
this.advance();
|
|
13578
13614
|
var expression = this.parseExpression();
|
|
13579
13615
|
if (!isRParenToken(this.peek())) {
|
|
13580
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13616
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13581
13617
|
}
|
|
13582
13618
|
this.advance();
|
|
13583
13619
|
return expression;
|
|
@@ -13637,7 +13673,7 @@ var Parser = /** @class */ (function () {
|
|
|
13637
13673
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
13638
13674
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13639
13675
|
this.advance();
|
|
13640
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13676
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13641
13677
|
}
|
|
13642
13678
|
else {
|
|
13643
13679
|
var token = this.peek();
|
|
@@ -13653,7 +13689,7 @@ var Parser = /** @class */ (function () {
|
|
|
13653
13689
|
this.advance();
|
|
13654
13690
|
}
|
|
13655
13691
|
else {
|
|
13656
|
-
throw new LitsError('Expected key to be a symbol or a string', this.
|
|
13692
|
+
throw new LitsError('Expected key to be a symbol or a string', this.peekSourceCodeInfo());
|
|
13657
13693
|
}
|
|
13658
13694
|
assertOperatorToken(this.peek(), ':=');
|
|
13659
13695
|
this.advance();
|
|
@@ -13661,7 +13697,7 @@ var Parser = /** @class */ (function () {
|
|
|
13661
13697
|
}
|
|
13662
13698
|
var nextToken = this.peek();
|
|
13663
13699
|
if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
13664
|
-
throw new LitsError('Expected comma or closing brace', this.
|
|
13700
|
+
throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
|
|
13665
13701
|
}
|
|
13666
13702
|
if (isOperatorToken(nextToken, ',')) {
|
|
13667
13703
|
this.advance();
|
|
@@ -13678,14 +13714,14 @@ var Parser = /** @class */ (function () {
|
|
|
13678
13714
|
while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
|
|
13679
13715
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13680
13716
|
this.advance();
|
|
13681
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13717
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13682
13718
|
}
|
|
13683
13719
|
else {
|
|
13684
13720
|
params.push(this.parseExpression());
|
|
13685
13721
|
}
|
|
13686
13722
|
var nextToken = this.peek();
|
|
13687
13723
|
if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
|
|
13688
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13724
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13689
13725
|
}
|
|
13690
13726
|
if (isOperatorToken(nextToken, ',')) {
|
|
13691
13727
|
this.advance();
|
|
@@ -13696,26 +13732,27 @@ var Parser = /** @class */ (function () {
|
|
|
13696
13732
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
|
|
13697
13733
|
};
|
|
13698
13734
|
Parser.prototype.parseFunctionCall = function (symbol) {
|
|
13735
|
+
var _a;
|
|
13699
13736
|
this.advance();
|
|
13700
13737
|
var params = [];
|
|
13701
13738
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
13702
13739
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13703
13740
|
this.advance();
|
|
13704
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13741
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13705
13742
|
}
|
|
13706
13743
|
else {
|
|
13707
13744
|
params.push(this.parseExpression());
|
|
13708
13745
|
}
|
|
13709
13746
|
var nextToken = this.peek();
|
|
13710
13747
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
13711
|
-
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
13748
|
+
throw new LitsError('Expected comma or closing parenthesis', (_a = this.peek()) === null || _a === void 0 ? void 0 : _a[2]);
|
|
13712
13749
|
}
|
|
13713
13750
|
if (isOperatorToken(nextToken, ',')) {
|
|
13714
13751
|
this.advance();
|
|
13715
13752
|
}
|
|
13716
13753
|
}
|
|
13717
13754
|
if (!isRParenToken(this.peek())) {
|
|
13718
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13755
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13719
13756
|
}
|
|
13720
13757
|
this.advance();
|
|
13721
13758
|
if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
|
|
@@ -13745,14 +13782,14 @@ var Parser = /** @class */ (function () {
|
|
|
13745
13782
|
if (params.length !== 1) {
|
|
13746
13783
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13747
13784
|
}
|
|
13748
|
-
var
|
|
13785
|
+
var _b = __read(params, 1), param = _b[0];
|
|
13749
13786
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13750
13787
|
}
|
|
13751
13788
|
case specialExpressionTypes.throw: {
|
|
13752
13789
|
if (params.length !== 1) {
|
|
13753
13790
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13754
13791
|
}
|
|
13755
|
-
var
|
|
13792
|
+
var _c = __read(params, 1), param = _c[0];
|
|
13756
13793
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13757
13794
|
}
|
|
13758
13795
|
case specialExpressionTypes['0_fn']:
|
|
@@ -13772,7 +13809,7 @@ var Parser = /** @class */ (function () {
|
|
|
13772
13809
|
}
|
|
13773
13810
|
};
|
|
13774
13811
|
Parser.prototype.parseLambdaFunction = function () {
|
|
13775
|
-
var firstToken = this.peek();
|
|
13812
|
+
var firstToken = this.asToken(this.peek());
|
|
13776
13813
|
if (isLParenToken(firstToken)
|
|
13777
13814
|
&& isSymbolToken(this.peekAhead(1))
|
|
13778
13815
|
&& isOperatorToken(this.peekAhead(2), '->')) {
|
|
@@ -13806,7 +13843,7 @@ var Parser = /** @class */ (function () {
|
|
|
13806
13843
|
var functionArguments = [];
|
|
13807
13844
|
while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13808
13845
|
if (rest) {
|
|
13809
|
-
throw new LitsError('Rest argument must be last', this.
|
|
13846
|
+
throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
|
|
13810
13847
|
}
|
|
13811
13848
|
var bindingTarget = this.parseBindingTarget();
|
|
13812
13849
|
if (bindingTarget[1][1] !== undefined) {
|
|
@@ -13816,25 +13853,25 @@ var Parser = /** @class */ (function () {
|
|
|
13816
13853
|
rest = true;
|
|
13817
13854
|
}
|
|
13818
13855
|
if (defaults && !bindingTarget[1][1]) {
|
|
13819
|
-
throw new LitsError('Default arguments must be last', this.
|
|
13856
|
+
throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
|
|
13820
13857
|
}
|
|
13821
13858
|
functionArguments.push(bindingTarget);
|
|
13822
13859
|
if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13823
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13860
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13824
13861
|
}
|
|
13825
13862
|
if (isOperatorToken(this.peek(), ',')) {
|
|
13826
13863
|
this.advance();
|
|
13827
13864
|
}
|
|
13828
13865
|
}
|
|
13829
13866
|
if (!isRParenToken(this.peek())) {
|
|
13830
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13867
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13831
13868
|
}
|
|
13832
13869
|
this.advance();
|
|
13833
13870
|
return functionArguments;
|
|
13834
13871
|
};
|
|
13835
13872
|
Parser.prototype.parseShorthandLamdaFunction = function () {
|
|
13836
13873
|
var _a;
|
|
13837
|
-
var firstToken = this.peek();
|
|
13874
|
+
var firstToken = this.asToken(this.peek());
|
|
13838
13875
|
this.advance();
|
|
13839
13876
|
var startPos = this.parseState.position;
|
|
13840
13877
|
var exprNode = this.parseExpression();
|
|
@@ -13892,7 +13929,7 @@ var Parser = /** @class */ (function () {
|
|
|
13892
13929
|
}
|
|
13893
13930
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13894
13931
|
if (requireDefaultValue && !defaultValue) {
|
|
13895
|
-
throw new LitsError('Expected assignment', this.
|
|
13932
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13896
13933
|
}
|
|
13897
13934
|
return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
|
|
13898
13935
|
}
|
|
@@ -13904,7 +13941,7 @@ var Parser = /** @class */ (function () {
|
|
|
13904
13941
|
this.advance();
|
|
13905
13942
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13906
13943
|
if (isOperatorToken(this.peek(), ':=')) {
|
|
13907
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13944
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13908
13945
|
}
|
|
13909
13946
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
13910
13947
|
}
|
|
@@ -13912,7 +13949,7 @@ var Parser = /** @class */ (function () {
|
|
|
13912
13949
|
if (isLBracketToken(firstToken)) {
|
|
13913
13950
|
this.advance();
|
|
13914
13951
|
var elements = [];
|
|
13915
|
-
var token = this.peek();
|
|
13952
|
+
var token = this.asToken(this.peek());
|
|
13916
13953
|
var rest = false;
|
|
13917
13954
|
while (!isRBracketToken(token)) {
|
|
13918
13955
|
if (rest) {
|
|
@@ -13921,7 +13958,7 @@ var Parser = /** @class */ (function () {
|
|
|
13921
13958
|
if (isOperatorToken(token, ',')) {
|
|
13922
13959
|
elements.push(null);
|
|
13923
13960
|
this.advance();
|
|
13924
|
-
token = this.peek();
|
|
13961
|
+
token = this.asToken(this.peek());
|
|
13925
13962
|
continue;
|
|
13926
13963
|
}
|
|
13927
13964
|
var target = this.parseBindingTarget();
|
|
@@ -13929,17 +13966,17 @@ var Parser = /** @class */ (function () {
|
|
|
13929
13966
|
rest = true;
|
|
13930
13967
|
}
|
|
13931
13968
|
elements.push(target);
|
|
13932
|
-
token = this.peek();
|
|
13969
|
+
token = this.asToken(this.peek());
|
|
13933
13970
|
if (!isRBracketToken(token)) {
|
|
13934
13971
|
assertOperatorToken(token, ',');
|
|
13935
13972
|
this.advance();
|
|
13936
13973
|
}
|
|
13937
|
-
token = this.peek();
|
|
13974
|
+
token = this.asToken(this.peek());
|
|
13938
13975
|
}
|
|
13939
13976
|
this.advance();
|
|
13940
13977
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13941
13978
|
if (requireDefaultValue && !defaultValue) {
|
|
13942
|
-
throw new LitsError('Expected assignment', this.
|
|
13979
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13943
13980
|
}
|
|
13944
13981
|
return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
|
|
13945
13982
|
}
|
|
@@ -13947,7 +13984,7 @@ var Parser = /** @class */ (function () {
|
|
|
13947
13984
|
if (isLBraceToken(firstToken)) {
|
|
13948
13985
|
this.advance();
|
|
13949
13986
|
var elements = {};
|
|
13950
|
-
var token = this.peek();
|
|
13987
|
+
var token = this.asToken(this.peek());
|
|
13951
13988
|
var rest = false;
|
|
13952
13989
|
while (!isRBraceToken(token)) {
|
|
13953
13990
|
if (rest) {
|
|
@@ -13958,7 +13995,7 @@ var Parser = /** @class */ (function () {
|
|
|
13958
13995
|
this.advance();
|
|
13959
13996
|
}
|
|
13960
13997
|
var key = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13961
|
-
token = this.peek();
|
|
13998
|
+
token = this.asToken(this.peek());
|
|
13962
13999
|
if (isReservedSymbolToken(token, 'as')) {
|
|
13963
14000
|
if (rest) {
|
|
13964
14001
|
throw new LitsError('Rest argument can not have alias', token[2]);
|
|
@@ -13975,7 +14012,7 @@ var Parser = /** @class */ (function () {
|
|
|
13975
14012
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
13976
14013
|
}
|
|
13977
14014
|
if (rest && isOperatorToken(this.peek(), ':=')) {
|
|
13978
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
14015
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13979
14016
|
}
|
|
13980
14017
|
elements[key[1]] = rest
|
|
13981
14018
|
? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
|
|
@@ -13988,17 +14025,17 @@ var Parser = /** @class */ (function () {
|
|
|
13988
14025
|
assertOperatorToken(this.peek(), ',');
|
|
13989
14026
|
this.advance();
|
|
13990
14027
|
}
|
|
13991
|
-
token = this.peek();
|
|
14028
|
+
token = this.asToken(this.peek());
|
|
13992
14029
|
}
|
|
13993
14030
|
this.advance();
|
|
13994
|
-
token = this.peek();
|
|
14031
|
+
token = this.asToken(this.peek());
|
|
13995
14032
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13996
14033
|
if (requireDefaultValue && !defaultValue) {
|
|
13997
14034
|
throw new LitsError('Expected assignment', token[2]);
|
|
13998
14035
|
}
|
|
13999
14036
|
return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
|
|
14000
14037
|
}
|
|
14001
|
-
throw new LitsError('Expected symbol', this.
|
|
14038
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
14002
14039
|
};
|
|
14003
14040
|
Parser.prototype.parseLet = function (token, optionalSemicolon) {
|
|
14004
14041
|
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
@@ -14021,7 +14058,7 @@ var Parser = /** @class */ (function () {
|
|
|
14021
14058
|
this.advance();
|
|
14022
14059
|
}
|
|
14023
14060
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14024
|
-
throw new LitsError('Expected ;', this.
|
|
14061
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14025
14062
|
}
|
|
14026
14063
|
}
|
|
14027
14064
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14045,7 +14082,7 @@ var Parser = /** @class */ (function () {
|
|
|
14045
14082
|
token = this.peek();
|
|
14046
14083
|
}
|
|
14047
14084
|
if (bindingNodes.length === 0) {
|
|
14048
|
-
throw new LitsError('Expected binding', this.
|
|
14085
|
+
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
14049
14086
|
}
|
|
14050
14087
|
assertSymbolToken(token, 'do');
|
|
14051
14088
|
this.advance();
|
|
@@ -14056,7 +14093,7 @@ var Parser = /** @class */ (function () {
|
|
|
14056
14093
|
this.advance();
|
|
14057
14094
|
}
|
|
14058
14095
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14059
|
-
throw new LitsError('Expected ;', this.
|
|
14096
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14060
14097
|
}
|
|
14061
14098
|
}
|
|
14062
14099
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14072,7 +14109,7 @@ var Parser = /** @class */ (function () {
|
|
|
14072
14109
|
this.advance();
|
|
14073
14110
|
}
|
|
14074
14111
|
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14075
|
-
throw new LitsError('Expected ;', this.
|
|
14112
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14076
14113
|
}
|
|
14077
14114
|
}
|
|
14078
14115
|
var tryExpression = tryExpressions.length === 1
|
|
@@ -14094,7 +14131,7 @@ var Parser = /** @class */ (function () {
|
|
|
14094
14131
|
this.advance();
|
|
14095
14132
|
}
|
|
14096
14133
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14097
|
-
throw new LitsError('Expected ;', this.
|
|
14134
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14098
14135
|
}
|
|
14099
14136
|
}
|
|
14100
14137
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14130,7 +14167,7 @@ var Parser = /** @class */ (function () {
|
|
|
14130
14167
|
this.advance();
|
|
14131
14168
|
}
|
|
14132
14169
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14133
|
-
throw new LitsError('Expected ;', this.
|
|
14170
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14134
14171
|
}
|
|
14135
14172
|
}
|
|
14136
14173
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14144,13 +14181,13 @@ var Parser = /** @class */ (function () {
|
|
|
14144
14181
|
this.advance();
|
|
14145
14182
|
var bindingNode = this.parseBinding();
|
|
14146
14183
|
var modifiers = [];
|
|
14147
|
-
var token = this.peek();
|
|
14184
|
+
var token = this.asToken(this.peek());
|
|
14148
14185
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14149
14186
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14150
14187
|
}
|
|
14151
14188
|
if (isOperatorToken(token, ',')) {
|
|
14152
14189
|
this.advance();
|
|
14153
|
-
token = this.peek();
|
|
14190
|
+
token = this.asToken(this.peek());
|
|
14154
14191
|
}
|
|
14155
14192
|
if (!isSymbolToken(token, 'let')
|
|
14156
14193
|
&& !isReservedSymbolToken(token, 'when')
|
|
@@ -14170,14 +14207,14 @@ var Parser = /** @class */ (function () {
|
|
|
14170
14207
|
throw new LitsError('Duplicate binding', letNode[1][1][2]);
|
|
14171
14208
|
}
|
|
14172
14209
|
letBindings.push(letNode[1][1]);
|
|
14173
|
-
token = this_2.peek();
|
|
14210
|
+
token = this_2.asToken(this_2.peek());
|
|
14174
14211
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14175
14212
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14176
14213
|
}
|
|
14177
14214
|
if (isOperatorToken(token, ',')) {
|
|
14178
14215
|
this_2.advance();
|
|
14179
14216
|
}
|
|
14180
|
-
token = this_2.peek();
|
|
14217
|
+
token = this_2.asToken(this_2.peek());
|
|
14181
14218
|
};
|
|
14182
14219
|
var this_2 = this;
|
|
14183
14220
|
while (isSymbolToken(token, 'let')) {
|
|
@@ -14203,14 +14240,14 @@ var Parser = /** @class */ (function () {
|
|
|
14203
14240
|
modifiers.push('&while');
|
|
14204
14241
|
whileNode = this.parseExpression();
|
|
14205
14242
|
}
|
|
14206
|
-
token = this.peek();
|
|
14243
|
+
token = this.asToken(this.peek());
|
|
14207
14244
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14208
14245
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14209
14246
|
}
|
|
14210
14247
|
if (isOperatorToken(token, ',')) {
|
|
14211
14248
|
this.advance();
|
|
14212
14249
|
}
|
|
14213
|
-
token = this.peek();
|
|
14250
|
+
token = this.asToken(this.peek());
|
|
14214
14251
|
}
|
|
14215
14252
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
|
|
14216
14253
|
throw new LitsError('Expected do or each', token[2]);
|
|
@@ -14247,7 +14284,7 @@ var Parser = /** @class */ (function () {
|
|
|
14247
14284
|
this.advance();
|
|
14248
14285
|
}
|
|
14249
14286
|
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14250
|
-
throw new LitsError('Expected ;', this.
|
|
14287
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14251
14288
|
}
|
|
14252
14289
|
}
|
|
14253
14290
|
var thenExpression = thenExpressions.length === 1
|
|
@@ -14263,7 +14300,7 @@ var Parser = /** @class */ (function () {
|
|
|
14263
14300
|
this.advance();
|
|
14264
14301
|
}
|
|
14265
14302
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14266
|
-
throw new LitsError('Expected ;', this.
|
|
14303
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14267
14304
|
}
|
|
14268
14305
|
}
|
|
14269
14306
|
elseExpression = elseExpressions.length === 1
|
|
@@ -14294,7 +14331,7 @@ var Parser = /** @class */ (function () {
|
|
|
14294
14331
|
this.advance();
|
|
14295
14332
|
}
|
|
14296
14333
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14297
|
-
throw new LitsError('Expected ;', this.
|
|
14334
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14298
14335
|
}
|
|
14299
14336
|
}
|
|
14300
14337
|
var thenExpression = expressions.length === 1
|
|
@@ -14329,7 +14366,7 @@ var Parser = /** @class */ (function () {
|
|
|
14329
14366
|
this.advance();
|
|
14330
14367
|
}
|
|
14331
14368
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14332
|
-
throw new LitsError('Expected ;', this.
|
|
14369
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14333
14370
|
}
|
|
14334
14371
|
}
|
|
14335
14372
|
var thenExpression = expressions.length === 1
|
|
@@ -14356,7 +14393,7 @@ var Parser = /** @class */ (function () {
|
|
|
14356
14393
|
this.advance();
|
|
14357
14394
|
}
|
|
14358
14395
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14359
|
-
throw new LitsError('Expected ;', this.
|
|
14396
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14360
14397
|
}
|
|
14361
14398
|
}
|
|
14362
14399
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14400,7 +14437,7 @@ var Parser = /** @class */ (function () {
|
|
|
14400
14437
|
this.advance();
|
|
14401
14438
|
}
|
|
14402
14439
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14403
|
-
throw new LitsError('Expected ;', this.
|
|
14440
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14404
14441
|
}
|
|
14405
14442
|
}
|
|
14406
14443
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14411,7 +14448,7 @@ var Parser = /** @class */ (function () {
|
|
|
14411
14448
|
]]], token[2]);
|
|
14412
14449
|
}
|
|
14413
14450
|
else {
|
|
14414
|
-
throw new LitsError('Expected let or function', this.
|
|
14451
|
+
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|
|
14415
14452
|
}
|
|
14416
14453
|
};
|
|
14417
14454
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -14436,7 +14473,7 @@ var Parser = /** @class */ (function () {
|
|
|
14436
14473
|
});
|
|
14437
14474
|
};
|
|
14438
14475
|
Parser.prototype.parseSymbol = function () {
|
|
14439
|
-
var token = this.peek();
|
|
14476
|
+
var token = this.asToken(this.peek());
|
|
14440
14477
|
this.advance();
|
|
14441
14478
|
if (!isSymbolToken(token)) {
|
|
14442
14479
|
throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
|
|
@@ -14458,7 +14495,7 @@ var Parser = /** @class */ (function () {
|
|
|
14458
14495
|
return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
|
|
14459
14496
|
};
|
|
14460
14497
|
Parser.prototype.parseNumber = function () {
|
|
14461
|
-
var token = this.peek();
|
|
14498
|
+
var token = this.asToken(this.peek());
|
|
14462
14499
|
this.advance();
|
|
14463
14500
|
var value = token[1];
|
|
14464
14501
|
var negative = value[0] === '-';
|
|
@@ -14466,7 +14503,7 @@ var Parser = /** @class */ (function () {
|
|
|
14466
14503
|
return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
|
|
14467
14504
|
};
|
|
14468
14505
|
Parser.prototype.parseString = function () {
|
|
14469
|
-
var token = this.peek();
|
|
14506
|
+
var token = this.asToken(this.peek());
|
|
14470
14507
|
this.advance();
|
|
14471
14508
|
var value = token[1].substring(1, token[1].length - 1)
|
|
14472
14509
|
.replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
|
|
@@ -14498,7 +14535,7 @@ var Parser = /** @class */ (function () {
|
|
|
14498
14535
|
return withSourceCodeInfo([NodeTypes.String, value], token[2]);
|
|
14499
14536
|
};
|
|
14500
14537
|
Parser.prototype.parseRegexpShorthand = function () {
|
|
14501
|
-
var token = this.peek();
|
|
14538
|
+
var token = this.asToken(this.peek());
|
|
14502
14539
|
this.advance();
|
|
14503
14540
|
var endStringPosition = token[1].lastIndexOf('"');
|
|
14504
14541
|
var regexpString = token[1].substring(2, endStringPosition);
|
|
@@ -15260,7 +15297,6 @@ var arrayReference = {
|
|
|
15260
15297
|
examples: [
|
|
15261
15298
|
'flatten([1, 2, [3, 4], 5])',
|
|
15262
15299
|
"\nlet foo := \"bar\";\nflatten([\n 1,\n \" 2 A \",\n [foo, [4, [\"ABC\"]]],\n 6,\n])",
|
|
15263
|
-
'flatten(12)',
|
|
15264
15300
|
],
|
|
15265
15301
|
noOperatorDocumentation: true,
|
|
15266
15302
|
},
|
|
@@ -18978,6 +19014,7 @@ var gridReference = {
|
|
|
18978
19014
|
"grid:transpose(".concat(exampleGrid2, ")"),
|
|
18979
19015
|
"grid:transpose(".concat(exampleGrid3, ")"),
|
|
18980
19016
|
],
|
|
19017
|
+
aliases: ['grid:tr'],
|
|
18981
19018
|
},
|
|
18982
19019
|
'grid:flip-h': {
|
|
18983
19020
|
title: 'grid:flip-h',
|