@mojir/lits 2.1.6 → 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 +118 -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 +117 -82
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +117 -82
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +117 -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 +117 -81
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +117 -81
- 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)
|
|
@@ -1545,13 +1545,15 @@ var arrayNormalExpression = {
|
|
|
1545
1545
|
paramCount: 2,
|
|
1546
1546
|
},
|
|
1547
1547
|
flatten: {
|
|
1548
|
-
evaluate: function (_a) {
|
|
1549
|
-
var _b = __read(_a,
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
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);
|
|
1553
1555
|
},
|
|
1554
|
-
paramCount: 1,
|
|
1556
|
+
paramCount: { min: 1, max: 2 },
|
|
1555
1557
|
},
|
|
1556
1558
|
mapcat: {
|
|
1557
1559
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
@@ -4001,6 +4003,13 @@ var regexpNormalExpression = {
|
|
|
4001
4003
|
assertString(sourceArg, sourceCodeInfo);
|
|
4002
4004
|
var source = sourceArg || '(?:)';
|
|
4003
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
|
+
}
|
|
4004
4013
|
return _b = {},
|
|
4005
4014
|
_b[REGEXP_SYMBOL] = true,
|
|
4006
4015
|
_b.sourceCodeInfo = sourceCodeInfo,
|
|
@@ -7107,10 +7116,10 @@ var linearAlgebraNormalExpression = {
|
|
|
7107
7116
|
assertVector(vectorA, sourceCodeInfo);
|
|
7108
7117
|
assertVector(vectorB, sourceCodeInfo);
|
|
7109
7118
|
if (vectorA.length < 2) {
|
|
7110
|
-
throw new
|
|
7119
|
+
throw new LitsError('Vectors must have at least 2 elements', sourceCodeInfo);
|
|
7111
7120
|
}
|
|
7112
7121
|
if (vectorA.length !== vectorB.length) {
|
|
7113
|
-
throw new
|
|
7122
|
+
throw new LitsError('Vectors must be of the same length', sourceCodeInfo);
|
|
7114
7123
|
}
|
|
7115
7124
|
assertNumber(lag, sourceCodeInfo, {
|
|
7116
7125
|
integer: true,
|
|
@@ -8362,7 +8371,7 @@ var partitionsNormalExpressions = {
|
|
|
8362
8371
|
if (n === 0)
|
|
8363
8372
|
return 1;
|
|
8364
8373
|
if (n > partitionNumbers.length) {
|
|
8365
|
-
throw new
|
|
8374
|
+
throw new LitsError("n is too large. The maximum value is ".concat(partitionNumbers.length - 1, "."), sourceCodeInfo);
|
|
8366
8375
|
}
|
|
8367
8376
|
return partitionNumbers[n - 1];
|
|
8368
8377
|
},
|
|
@@ -10501,7 +10510,12 @@ var combinatoricalNormalExpression = {
|
|
|
10501
10510
|
var _b = __read(_a, 2), a = _b[0], m = _b[1];
|
|
10502
10511
|
assertNumber(a, sourceCodeInfo, { integer: true, positive: true });
|
|
10503
10512
|
assertNumber(m, sourceCodeInfo, { integer: true, positive: true });
|
|
10504
|
-
|
|
10513
|
+
try {
|
|
10514
|
+
return modInverse(a, m);
|
|
10515
|
+
}
|
|
10516
|
+
catch (error) {
|
|
10517
|
+
throw new LitsError(error, sourceCodeInfo);
|
|
10518
|
+
}
|
|
10505
10519
|
},
|
|
10506
10520
|
paramCount: 2,
|
|
10507
10521
|
},
|
|
@@ -10520,7 +10534,7 @@ var combinatoricalNormalExpression = {
|
|
|
10520
10534
|
assertVector(remainders, sourceCodeInfo);
|
|
10521
10535
|
assertVector(moduli, sourceCodeInfo);
|
|
10522
10536
|
if (remainders.length !== moduli.length) {
|
|
10523
|
-
throw new
|
|
10537
|
+
throw new LitsError('Remainders and moduli must have the same length.', sourceCodeInfo);
|
|
10524
10538
|
}
|
|
10525
10539
|
try {
|
|
10526
10540
|
return chineseRemainder(remainders, moduli);
|
|
@@ -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
|
}
|
|
@@ -12855,21 +12873,30 @@ var tokenizeNumber = function (input, position) {
|
|
|
12855
12873
|
var char = input[i];
|
|
12856
12874
|
if (char === '_') {
|
|
12857
12875
|
if (!decimalNumberRegExp.test(input[i - 1]) || !decimalNumberRegExp.test(input[i + 1])) {
|
|
12858
|
-
|
|
12876
|
+
if (i === start) {
|
|
12877
|
+
return NO_MATCH;
|
|
12878
|
+
}
|
|
12879
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12859
12880
|
}
|
|
12860
12881
|
}
|
|
12861
12882
|
else if (char === '.') {
|
|
12862
|
-
if (i === start
|
|
12883
|
+
if (i === start) {
|
|
12863
12884
|
return NO_MATCH;
|
|
12864
12885
|
}
|
|
12886
|
+
if (hasDecimalPoint || hasExponent) {
|
|
12887
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12888
|
+
}
|
|
12865
12889
|
hasDecimalPoint = true;
|
|
12866
12890
|
}
|
|
12867
12891
|
else if (char === 'e' || char === 'E') {
|
|
12868
|
-
if (i === start
|
|
12892
|
+
if (i === start) {
|
|
12869
12893
|
return NO_MATCH;
|
|
12870
12894
|
}
|
|
12895
|
+
if (hasExponent) {
|
|
12896
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12897
|
+
}
|
|
12871
12898
|
if (input[i - 1] === '.' || input[i - 1] === '+' || input[i - 1] === '-') {
|
|
12872
|
-
|
|
12899
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12873
12900
|
}
|
|
12874
12901
|
if (input[i + 1] === '+' || input[i + 1] === '-') {
|
|
12875
12902
|
i += 1;
|
|
@@ -12889,7 +12916,7 @@ var tokenizeNumber = function (input, position) {
|
|
|
12889
12916
|
}
|
|
12890
12917
|
var nextChar = input[i];
|
|
12891
12918
|
if (nextChar && !postNumberRegExp.test(nextChar)) {
|
|
12892
|
-
|
|
12919
|
+
throw new LitsError("Invalid number format at position ".concat(i, "."), undefined);
|
|
12893
12920
|
}
|
|
12894
12921
|
return [length, ['Number', input.substring(position, i)]];
|
|
12895
12922
|
};
|
|
@@ -13055,10 +13082,10 @@ function tokenize(input, debug, filePath) {
|
|
|
13055
13082
|
hasDebugData: debug,
|
|
13056
13083
|
};
|
|
13057
13084
|
while (position < input.length) {
|
|
13058
|
-
var tokenDescriptor = getCurrentToken(input, position);
|
|
13059
13085
|
var sourceCodeInfo = debug
|
|
13060
13086
|
? createSourceCodeInfo(input, position, filePath)
|
|
13061
13087
|
: undefined;
|
|
13088
|
+
var tokenDescriptor = getCurrentToken(input, position);
|
|
13062
13089
|
if (!tokenDescriptor) {
|
|
13063
13090
|
throw new LitsError("Unrecognized character '".concat(input[position], "'."), sourceCodeInfo);
|
|
13064
13091
|
}
|
|
@@ -13168,9 +13195,6 @@ function isOperatorToken(token, operatorName) {
|
|
|
13168
13195
|
}
|
|
13169
13196
|
function assertOperatorToken(token, operatorName) {
|
|
13170
13197
|
if (!isOperatorToken(token, operatorName)) {
|
|
13171
|
-
if (operatorName) {
|
|
13172
|
-
throw new LitsError("Unexpected token: ".concat(token, ", expected operator ").concat(operatorName), token[2]);
|
|
13173
|
-
}
|
|
13174
13198
|
throwUnexpectedToken('Operator', operatorName, token);
|
|
13175
13199
|
}
|
|
13176
13200
|
}
|
|
@@ -13240,8 +13264,8 @@ function isA_BinaryOperatorToken(token) {
|
|
|
13240
13264
|
return (token === null || token === void 0 ? void 0 : token[0]) === 'Operator' && isBinaryOperator(token[1]);
|
|
13241
13265
|
}
|
|
13242
13266
|
function throwUnexpectedToken(expected, expectedValue, actual) {
|
|
13243
|
-
var actualOutput = "".concat(actual[0], " '").concat(actual[1], "'");
|
|
13244
|
-
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]);
|
|
13245
13269
|
}
|
|
13246
13270
|
|
|
13247
13271
|
function minifyTokenStream(tokenStream, _a) {
|
|
@@ -13389,6 +13413,11 @@ var Parser = /** @class */ (function () {
|
|
|
13389
13413
|
Parser.prototype.peek = function () {
|
|
13390
13414
|
return this.tokenStream.tokens[this.parseState.position];
|
|
13391
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
|
+
};
|
|
13392
13421
|
Parser.prototype.peekAhead = function (count) {
|
|
13393
13422
|
return this.tokenStream.tokens[this.parseState.position + count];
|
|
13394
13423
|
};
|
|
@@ -13404,7 +13433,7 @@ var Parser = /** @class */ (function () {
|
|
|
13404
13433
|
}
|
|
13405
13434
|
else {
|
|
13406
13435
|
if (!this.isAtEnd()) {
|
|
13407
|
-
throw new LitsError('Expected ;', this.
|
|
13436
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13408
13437
|
}
|
|
13409
13438
|
}
|
|
13410
13439
|
}
|
|
@@ -13493,15 +13522,21 @@ var Parser = /** @class */ (function () {
|
|
|
13493
13522
|
}
|
|
13494
13523
|
return left;
|
|
13495
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
|
+
};
|
|
13496
13531
|
Parser.prototype.parseOperand = function () {
|
|
13497
13532
|
var operand = this.parseOperandPart();
|
|
13498
13533
|
var token = this.peek();
|
|
13499
13534
|
while (isOperatorToken(token, '.') || isLBracketToken(token) || isLParenToken(token)) {
|
|
13500
13535
|
if (token[1] === '.') {
|
|
13501
13536
|
this.advance();
|
|
13502
|
-
var symbolToken = this.peek();
|
|
13537
|
+
var symbolToken = this.asToken(this.peek());
|
|
13503
13538
|
if (!isSymbolToken(symbolToken)) {
|
|
13504
|
-
throw new LitsError('Expected symbol', this.
|
|
13539
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13505
13540
|
}
|
|
13506
13541
|
var stringNode = withSourceCodeInfo([NodeTypes.String, symbolToken[1]], symbolToken[2]);
|
|
13507
13542
|
operand = createAccessorNode(operand, stringNode, token[2]);
|
|
@@ -13512,7 +13547,7 @@ var Parser = /** @class */ (function () {
|
|
|
13512
13547
|
this.advance();
|
|
13513
13548
|
var expression = this.parseExpression();
|
|
13514
13549
|
if (!isRBracketToken(this.peek())) {
|
|
13515
|
-
throw new LitsError('Expected closing bracket', this.
|
|
13550
|
+
throw new LitsError('Expected closing bracket', this.peekSourceCodeInfo());
|
|
13516
13551
|
}
|
|
13517
13552
|
operand = createAccessorNode(operand, expression, token[2]);
|
|
13518
13553
|
this.advance();
|
|
@@ -13526,7 +13561,7 @@ var Parser = /** @class */ (function () {
|
|
|
13526
13561
|
return operand;
|
|
13527
13562
|
};
|
|
13528
13563
|
Parser.prototype.parseOperandPart = function () {
|
|
13529
|
-
var token = this.peek();
|
|
13564
|
+
var token = this.asToken(this.peek());
|
|
13530
13565
|
// Parentheses
|
|
13531
13566
|
if (isLParenToken(token)) {
|
|
13532
13567
|
var positionBefore = this.parseState.position;
|
|
@@ -13538,7 +13573,7 @@ var Parser = /** @class */ (function () {
|
|
|
13538
13573
|
this.advance();
|
|
13539
13574
|
var expression = this.parseExpression();
|
|
13540
13575
|
if (!isRParenToken(this.peek())) {
|
|
13541
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13576
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13542
13577
|
}
|
|
13543
13578
|
this.advance();
|
|
13544
13579
|
return expression;
|
|
@@ -13598,7 +13633,7 @@ var Parser = /** @class */ (function () {
|
|
|
13598
13633
|
while (!this.isAtEnd() && !isRBraceToken(this.peek())) {
|
|
13599
13634
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13600
13635
|
this.advance();
|
|
13601
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13636
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13602
13637
|
}
|
|
13603
13638
|
else {
|
|
13604
13639
|
var token = this.peek();
|
|
@@ -13614,7 +13649,7 @@ var Parser = /** @class */ (function () {
|
|
|
13614
13649
|
this.advance();
|
|
13615
13650
|
}
|
|
13616
13651
|
else {
|
|
13617
|
-
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());
|
|
13618
13653
|
}
|
|
13619
13654
|
assertOperatorToken(this.peek(), ':=');
|
|
13620
13655
|
this.advance();
|
|
@@ -13622,7 +13657,7 @@ var Parser = /** @class */ (function () {
|
|
|
13622
13657
|
}
|
|
13623
13658
|
var nextToken = this.peek();
|
|
13624
13659
|
if (!isOperatorToken(nextToken, ',') && !isRBraceToken(nextToken)) {
|
|
13625
|
-
throw new LitsError('Expected comma or closing brace', this.
|
|
13660
|
+
throw new LitsError('Expected comma or closing brace', this.peekSourceCodeInfo());
|
|
13626
13661
|
}
|
|
13627
13662
|
if (isOperatorToken(nextToken, ',')) {
|
|
13628
13663
|
this.advance();
|
|
@@ -13639,14 +13674,14 @@ var Parser = /** @class */ (function () {
|
|
|
13639
13674
|
while (!this.isAtEnd() && !isRBracketToken(this.peek())) {
|
|
13640
13675
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13641
13676
|
this.advance();
|
|
13642
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13677
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13643
13678
|
}
|
|
13644
13679
|
else {
|
|
13645
13680
|
params.push(this.parseExpression());
|
|
13646
13681
|
}
|
|
13647
13682
|
var nextToken = this.peek();
|
|
13648
13683
|
if (!isOperatorToken(nextToken, ',') && !isRBracketToken(nextToken)) {
|
|
13649
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13684
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13650
13685
|
}
|
|
13651
13686
|
if (isOperatorToken(nextToken, ',')) {
|
|
13652
13687
|
this.advance();
|
|
@@ -13657,26 +13692,27 @@ var Parser = /** @class */ (function () {
|
|
|
13657
13692
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.array, params]], firstToken[2]);
|
|
13658
13693
|
};
|
|
13659
13694
|
Parser.prototype.parseFunctionCall = function (symbol) {
|
|
13695
|
+
var _a;
|
|
13660
13696
|
this.advance();
|
|
13661
13697
|
var params = [];
|
|
13662
13698
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
13663
13699
|
if (isOperatorToken(this.peek(), '...')) {
|
|
13664
13700
|
this.advance();
|
|
13665
|
-
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.
|
|
13701
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peekSourceCodeInfo()));
|
|
13666
13702
|
}
|
|
13667
13703
|
else {
|
|
13668
13704
|
params.push(this.parseExpression());
|
|
13669
13705
|
}
|
|
13670
13706
|
var nextToken = this.peek();
|
|
13671
13707
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
13672
|
-
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]);
|
|
13673
13709
|
}
|
|
13674
13710
|
if (isOperatorToken(nextToken, ',')) {
|
|
13675
13711
|
this.advance();
|
|
13676
13712
|
}
|
|
13677
13713
|
}
|
|
13678
13714
|
if (!isRParenToken(this.peek())) {
|
|
13679
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13715
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13680
13716
|
}
|
|
13681
13717
|
this.advance();
|
|
13682
13718
|
if (isSpecialBuiltinSymbolNode(symbol)) { // Named function
|
|
@@ -13706,14 +13742,14 @@ var Parser = /** @class */ (function () {
|
|
|
13706
13742
|
if (params.length !== 1) {
|
|
13707
13743
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13708
13744
|
}
|
|
13709
|
-
var
|
|
13745
|
+
var _b = __read(params, 1), param = _b[0];
|
|
13710
13746
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13711
13747
|
}
|
|
13712
13748
|
case specialExpressionTypes.throw: {
|
|
13713
13749
|
if (params.length !== 1) {
|
|
13714
13750
|
throw new LitsError('Expected exactly one parameter', symbol[2]);
|
|
13715
13751
|
}
|
|
13716
|
-
var
|
|
13752
|
+
var _c = __read(params, 1), param = _c[0];
|
|
13717
13753
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [type, param]], symbol[2]);
|
|
13718
13754
|
}
|
|
13719
13755
|
case specialExpressionTypes['0_fn']:
|
|
@@ -13733,7 +13769,7 @@ var Parser = /** @class */ (function () {
|
|
|
13733
13769
|
}
|
|
13734
13770
|
};
|
|
13735
13771
|
Parser.prototype.parseLambdaFunction = function () {
|
|
13736
|
-
var firstToken = this.peek();
|
|
13772
|
+
var firstToken = this.asToken(this.peek());
|
|
13737
13773
|
if (isLParenToken(firstToken)
|
|
13738
13774
|
&& isSymbolToken(this.peekAhead(1))
|
|
13739
13775
|
&& isOperatorToken(this.peekAhead(2), '->')) {
|
|
@@ -13767,7 +13803,7 @@ var Parser = /** @class */ (function () {
|
|
|
13767
13803
|
var functionArguments = [];
|
|
13768
13804
|
while (!this.isAtEnd() && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13769
13805
|
if (rest) {
|
|
13770
|
-
throw new LitsError('Rest argument must be last', this.
|
|
13806
|
+
throw new LitsError('Rest argument must be last', this.peekSourceCodeInfo());
|
|
13771
13807
|
}
|
|
13772
13808
|
var bindingTarget = this.parseBindingTarget();
|
|
13773
13809
|
if (bindingTarget[1][1] !== undefined) {
|
|
@@ -13777,25 +13813,25 @@ var Parser = /** @class */ (function () {
|
|
|
13777
13813
|
rest = true;
|
|
13778
13814
|
}
|
|
13779
13815
|
if (defaults && !bindingTarget[1][1]) {
|
|
13780
|
-
throw new LitsError('Default arguments must be last', this.
|
|
13816
|
+
throw new LitsError('Default arguments must be last', this.peekSourceCodeInfo());
|
|
13781
13817
|
}
|
|
13782
13818
|
functionArguments.push(bindingTarget);
|
|
13783
13819
|
if (!isOperatorToken(this.peek(), ',') && !isRParenToken(this.peek()) && !isSymbolToken(this.peek(), 'let')) {
|
|
13784
|
-
throw new LitsError('Expected comma or closing parenthesis', this.
|
|
13820
|
+
throw new LitsError('Expected comma or closing parenthesis', this.peekSourceCodeInfo());
|
|
13785
13821
|
}
|
|
13786
13822
|
if (isOperatorToken(this.peek(), ',')) {
|
|
13787
13823
|
this.advance();
|
|
13788
13824
|
}
|
|
13789
13825
|
}
|
|
13790
13826
|
if (!isRParenToken(this.peek())) {
|
|
13791
|
-
throw new LitsError('Expected closing parenthesis', this.
|
|
13827
|
+
throw new LitsError('Expected closing parenthesis', this.peekSourceCodeInfo());
|
|
13792
13828
|
}
|
|
13793
13829
|
this.advance();
|
|
13794
13830
|
return functionArguments;
|
|
13795
13831
|
};
|
|
13796
13832
|
Parser.prototype.parseShorthandLamdaFunction = function () {
|
|
13797
13833
|
var _a;
|
|
13798
|
-
var firstToken = this.peek();
|
|
13834
|
+
var firstToken = this.asToken(this.peek());
|
|
13799
13835
|
this.advance();
|
|
13800
13836
|
var startPos = this.parseState.position;
|
|
13801
13837
|
var exprNode = this.parseExpression();
|
|
@@ -13853,7 +13889,7 @@ var Parser = /** @class */ (function () {
|
|
|
13853
13889
|
}
|
|
13854
13890
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13855
13891
|
if (requireDefaultValue && !defaultValue) {
|
|
13856
|
-
throw new LitsError('Expected assignment', this.
|
|
13892
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13857
13893
|
}
|
|
13858
13894
|
return withSourceCodeInfo([bindingTargetTypes.symbol, [symbol, defaultValue]], firstToken[2]);
|
|
13859
13895
|
}
|
|
@@ -13865,7 +13901,7 @@ var Parser = /** @class */ (function () {
|
|
|
13865
13901
|
this.advance();
|
|
13866
13902
|
var symbol = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13867
13903
|
if (isOperatorToken(this.peek(), ':=')) {
|
|
13868
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13904
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13869
13905
|
}
|
|
13870
13906
|
return withSourceCodeInfo([bindingTargetTypes.rest, [symbol[1], undefined]], firstToken[2]);
|
|
13871
13907
|
}
|
|
@@ -13873,7 +13909,7 @@ var Parser = /** @class */ (function () {
|
|
|
13873
13909
|
if (isLBracketToken(firstToken)) {
|
|
13874
13910
|
this.advance();
|
|
13875
13911
|
var elements = [];
|
|
13876
|
-
var token = this.peek();
|
|
13912
|
+
var token = this.asToken(this.peek());
|
|
13877
13913
|
var rest = false;
|
|
13878
13914
|
while (!isRBracketToken(token)) {
|
|
13879
13915
|
if (rest) {
|
|
@@ -13882,7 +13918,7 @@ var Parser = /** @class */ (function () {
|
|
|
13882
13918
|
if (isOperatorToken(token, ',')) {
|
|
13883
13919
|
elements.push(null);
|
|
13884
13920
|
this.advance();
|
|
13885
|
-
token = this.peek();
|
|
13921
|
+
token = this.asToken(this.peek());
|
|
13886
13922
|
continue;
|
|
13887
13923
|
}
|
|
13888
13924
|
var target = this.parseBindingTarget();
|
|
@@ -13890,17 +13926,17 @@ var Parser = /** @class */ (function () {
|
|
|
13890
13926
|
rest = true;
|
|
13891
13927
|
}
|
|
13892
13928
|
elements.push(target);
|
|
13893
|
-
token = this.peek();
|
|
13929
|
+
token = this.asToken(this.peek());
|
|
13894
13930
|
if (!isRBracketToken(token)) {
|
|
13895
13931
|
assertOperatorToken(token, ',');
|
|
13896
13932
|
this.advance();
|
|
13897
13933
|
}
|
|
13898
|
-
token = this.peek();
|
|
13934
|
+
token = this.asToken(this.peek());
|
|
13899
13935
|
}
|
|
13900
13936
|
this.advance();
|
|
13901
13937
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13902
13938
|
if (requireDefaultValue && !defaultValue) {
|
|
13903
|
-
throw new LitsError('Expected assignment', this.
|
|
13939
|
+
throw new LitsError('Expected assignment', this.peekSourceCodeInfo());
|
|
13904
13940
|
}
|
|
13905
13941
|
return withSourceCodeInfo([bindingTargetTypes.array, [elements, defaultValue]], firstToken[2]);
|
|
13906
13942
|
}
|
|
@@ -13908,7 +13944,7 @@ var Parser = /** @class */ (function () {
|
|
|
13908
13944
|
if (isLBraceToken(firstToken)) {
|
|
13909
13945
|
this.advance();
|
|
13910
13946
|
var elements = {};
|
|
13911
|
-
var token = this.peek();
|
|
13947
|
+
var token = this.asToken(this.peek());
|
|
13912
13948
|
var rest = false;
|
|
13913
13949
|
while (!isRBraceToken(token)) {
|
|
13914
13950
|
if (rest) {
|
|
@@ -13919,7 +13955,7 @@ var Parser = /** @class */ (function () {
|
|
|
13919
13955
|
this.advance();
|
|
13920
13956
|
}
|
|
13921
13957
|
var key = asUserDefinedSymbolNode(this.parseSymbol());
|
|
13922
|
-
token = this.peek();
|
|
13958
|
+
token = this.asToken(this.peek());
|
|
13923
13959
|
if (isReservedSymbolToken(token, 'as')) {
|
|
13924
13960
|
if (rest) {
|
|
13925
13961
|
throw new LitsError('Rest argument can not have alias', token[2]);
|
|
@@ -13936,7 +13972,7 @@ var Parser = /** @class */ (function () {
|
|
|
13936
13972
|
throw new LitsError("Duplicate binding name: ".concat(key), token[2]);
|
|
13937
13973
|
}
|
|
13938
13974
|
if (rest && isOperatorToken(this.peek(), ':=')) {
|
|
13939
|
-
throw new LitsError('Rest argument can not have default value', this.
|
|
13975
|
+
throw new LitsError('Rest argument can not have default value', this.peekSourceCodeInfo());
|
|
13940
13976
|
}
|
|
13941
13977
|
elements[key[1]] = rest
|
|
13942
13978
|
? withSourceCodeInfo([bindingTargetTypes.rest, [key[1], this.parseOptionalDefaulValue()]], firstToken[2])
|
|
@@ -13949,17 +13985,17 @@ var Parser = /** @class */ (function () {
|
|
|
13949
13985
|
assertOperatorToken(this.peek(), ',');
|
|
13950
13986
|
this.advance();
|
|
13951
13987
|
}
|
|
13952
|
-
token = this.peek();
|
|
13988
|
+
token = this.asToken(this.peek());
|
|
13953
13989
|
}
|
|
13954
13990
|
this.advance();
|
|
13955
|
-
token = this.peek();
|
|
13991
|
+
token = this.asToken(this.peek());
|
|
13956
13992
|
var defaultValue = this.parseOptionalDefaulValue();
|
|
13957
13993
|
if (requireDefaultValue && !defaultValue) {
|
|
13958
13994
|
throw new LitsError('Expected assignment', token[2]);
|
|
13959
13995
|
}
|
|
13960
13996
|
return withSourceCodeInfo([bindingTargetTypes.object, [elements, defaultValue]], firstToken[2]);
|
|
13961
13997
|
}
|
|
13962
|
-
throw new LitsError('Expected symbol', this.
|
|
13998
|
+
throw new LitsError('Expected symbol', this.peekSourceCodeInfo());
|
|
13963
13999
|
};
|
|
13964
14000
|
Parser.prototype.parseLet = function (token, optionalSemicolon) {
|
|
13965
14001
|
if (optionalSemicolon === void 0) { optionalSemicolon = false; }
|
|
@@ -13982,7 +14018,7 @@ var Parser = /** @class */ (function () {
|
|
|
13982
14018
|
this.advance();
|
|
13983
14019
|
}
|
|
13984
14020
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
13985
|
-
throw new LitsError('Expected ;', this.
|
|
14021
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
13986
14022
|
}
|
|
13987
14023
|
}
|
|
13988
14024
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14006,7 +14042,7 @@ var Parser = /** @class */ (function () {
|
|
|
14006
14042
|
token = this.peek();
|
|
14007
14043
|
}
|
|
14008
14044
|
if (bindingNodes.length === 0) {
|
|
14009
|
-
throw new LitsError('Expected binding', this.
|
|
14045
|
+
throw new LitsError('Expected binding', this.peekSourceCodeInfo());
|
|
14010
14046
|
}
|
|
14011
14047
|
assertSymbolToken(token, 'do');
|
|
14012
14048
|
this.advance();
|
|
@@ -14017,7 +14053,7 @@ var Parser = /** @class */ (function () {
|
|
|
14017
14053
|
this.advance();
|
|
14018
14054
|
}
|
|
14019
14055
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14020
|
-
throw new LitsError('Expected ;', this.
|
|
14056
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14021
14057
|
}
|
|
14022
14058
|
}
|
|
14023
14059
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14033,7 +14069,7 @@ var Parser = /** @class */ (function () {
|
|
|
14033
14069
|
this.advance();
|
|
14034
14070
|
}
|
|
14035
14071
|
else if (!isReservedSymbolToken(this.peek(), 'catch')) {
|
|
14036
|
-
throw new LitsError('Expected ;', this.
|
|
14072
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14037
14073
|
}
|
|
14038
14074
|
}
|
|
14039
14075
|
var tryExpression = tryExpressions.length === 1
|
|
@@ -14055,7 +14091,7 @@ var Parser = /** @class */ (function () {
|
|
|
14055
14091
|
this.advance();
|
|
14056
14092
|
}
|
|
14057
14093
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14058
|
-
throw new LitsError('Expected ;', this.
|
|
14094
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14059
14095
|
}
|
|
14060
14096
|
}
|
|
14061
14097
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14091,7 +14127,7 @@ var Parser = /** @class */ (function () {
|
|
|
14091
14127
|
this.advance();
|
|
14092
14128
|
}
|
|
14093
14129
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14094
|
-
throw new LitsError('Expected ;', this.
|
|
14130
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14095
14131
|
}
|
|
14096
14132
|
}
|
|
14097
14133
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14105,13 +14141,13 @@ var Parser = /** @class */ (function () {
|
|
|
14105
14141
|
this.advance();
|
|
14106
14142
|
var bindingNode = this.parseBinding();
|
|
14107
14143
|
var modifiers = [];
|
|
14108
|
-
var token = this.peek();
|
|
14144
|
+
var token = this.asToken(this.peek());
|
|
14109
14145
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14110
14146
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14111
14147
|
}
|
|
14112
14148
|
if (isOperatorToken(token, ',')) {
|
|
14113
14149
|
this.advance();
|
|
14114
|
-
token = this.peek();
|
|
14150
|
+
token = this.asToken(this.peek());
|
|
14115
14151
|
}
|
|
14116
14152
|
if (!isSymbolToken(token, 'let')
|
|
14117
14153
|
&& !isReservedSymbolToken(token, 'when')
|
|
@@ -14131,14 +14167,14 @@ var Parser = /** @class */ (function () {
|
|
|
14131
14167
|
throw new LitsError('Duplicate binding', letNode[1][1][2]);
|
|
14132
14168
|
}
|
|
14133
14169
|
letBindings.push(letNode[1][1]);
|
|
14134
|
-
token = this_2.peek();
|
|
14170
|
+
token = this_2.asToken(this_2.peek());
|
|
14135
14171
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this_2.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14136
14172
|
throw new LitsError('Expected do, each or comma', token[2]);
|
|
14137
14173
|
}
|
|
14138
14174
|
if (isOperatorToken(token, ',')) {
|
|
14139
14175
|
this_2.advance();
|
|
14140
14176
|
}
|
|
14141
|
-
token = this_2.peek();
|
|
14177
|
+
token = this_2.asToken(this_2.peek());
|
|
14142
14178
|
};
|
|
14143
14179
|
var this_2 = this;
|
|
14144
14180
|
while (isSymbolToken(token, 'let')) {
|
|
@@ -14164,14 +14200,14 @@ var Parser = /** @class */ (function () {
|
|
|
14164
14200
|
modifiers.push('&while');
|
|
14165
14201
|
whileNode = this.parseExpression();
|
|
14166
14202
|
}
|
|
14167
|
-
token = this.peek();
|
|
14203
|
+
token = this.asToken(this.peek());
|
|
14168
14204
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each') && !isOperatorToken(token, ',')) {
|
|
14169
14205
|
throw new LitsError('Expected do or comma', token[2]);
|
|
14170
14206
|
}
|
|
14171
14207
|
if (isOperatorToken(token, ',')) {
|
|
14172
14208
|
this.advance();
|
|
14173
14209
|
}
|
|
14174
|
-
token = this.peek();
|
|
14210
|
+
token = this.asToken(this.peek());
|
|
14175
14211
|
}
|
|
14176
14212
|
if (!isSymbolToken(token, 'do') && !isReservedSymbolToken(this.peek(), 'each')) {
|
|
14177
14213
|
throw new LitsError('Expected do or each', token[2]);
|
|
@@ -14208,7 +14244,7 @@ var Parser = /** @class */ (function () {
|
|
|
14208
14244
|
this.advance();
|
|
14209
14245
|
}
|
|
14210
14246
|
else if (!isReservedSymbolToken(this.peek(), 'else') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14211
|
-
throw new LitsError('Expected ;', this.
|
|
14247
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14212
14248
|
}
|
|
14213
14249
|
}
|
|
14214
14250
|
var thenExpression = thenExpressions.length === 1
|
|
@@ -14224,7 +14260,7 @@ var Parser = /** @class */ (function () {
|
|
|
14224
14260
|
this.advance();
|
|
14225
14261
|
}
|
|
14226
14262
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14227
|
-
throw new LitsError('Expected ;', this.
|
|
14263
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14228
14264
|
}
|
|
14229
14265
|
}
|
|
14230
14266
|
elseExpression = elseExpressions.length === 1
|
|
@@ -14255,7 +14291,7 @@ var Parser = /** @class */ (function () {
|
|
|
14255
14291
|
this.advance();
|
|
14256
14292
|
}
|
|
14257
14293
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14258
|
-
throw new LitsError('Expected ;', this.
|
|
14294
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14259
14295
|
}
|
|
14260
14296
|
}
|
|
14261
14297
|
var thenExpression = expressions.length === 1
|
|
@@ -14290,7 +14326,7 @@ var Parser = /** @class */ (function () {
|
|
|
14290
14326
|
this.advance();
|
|
14291
14327
|
}
|
|
14292
14328
|
else if (!isReservedSymbolToken(this.peek(), 'case') && !isReservedSymbolToken(this.peek(), 'end')) {
|
|
14293
|
-
throw new LitsError('Expected ;', this.
|
|
14329
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14294
14330
|
}
|
|
14295
14331
|
}
|
|
14296
14332
|
var thenExpression = expressions.length === 1
|
|
@@ -14317,7 +14353,7 @@ var Parser = /** @class */ (function () {
|
|
|
14317
14353
|
this.advance();
|
|
14318
14354
|
}
|
|
14319
14355
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14320
|
-
throw new LitsError('Expected ;', this.
|
|
14356
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14321
14357
|
}
|
|
14322
14358
|
}
|
|
14323
14359
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14361,7 +14397,7 @@ var Parser = /** @class */ (function () {
|
|
|
14361
14397
|
this.advance();
|
|
14362
14398
|
}
|
|
14363
14399
|
else if (!isReservedSymbolToken(this.peek(), 'end')) {
|
|
14364
|
-
throw new LitsError('Expected ;', this.
|
|
14400
|
+
throw new LitsError('Expected ;', this.peekSourceCodeInfo());
|
|
14365
14401
|
}
|
|
14366
14402
|
}
|
|
14367
14403
|
assertReservedSymbolToken(this.peek(), 'end');
|
|
@@ -14372,7 +14408,7 @@ var Parser = /** @class */ (function () {
|
|
|
14372
14408
|
]]], token[2]);
|
|
14373
14409
|
}
|
|
14374
14410
|
else {
|
|
14375
|
-
throw new LitsError('Expected let or function', this.
|
|
14411
|
+
throw new LitsError('Expected let or function', this.peekSourceCodeInfo());
|
|
14376
14412
|
}
|
|
14377
14413
|
};
|
|
14378
14414
|
Parser.prototype.stringToSymbolNode = function (value, sourceCodeInfo) {
|
|
@@ -14397,7 +14433,7 @@ var Parser = /** @class */ (function () {
|
|
|
14397
14433
|
});
|
|
14398
14434
|
};
|
|
14399
14435
|
Parser.prototype.parseSymbol = function () {
|
|
14400
|
-
var token = this.peek();
|
|
14436
|
+
var token = this.asToken(this.peek());
|
|
14401
14437
|
this.advance();
|
|
14402
14438
|
if (!isSymbolToken(token)) {
|
|
14403
14439
|
throw new LitsError("Expected symbol token, got ".concat(token[0]), token[2]);
|
|
@@ -14419,7 +14455,7 @@ var Parser = /** @class */ (function () {
|
|
|
14419
14455
|
return withSourceCodeInfo([NodeTypes.ReservedSymbol, token[1]], token[2]);
|
|
14420
14456
|
};
|
|
14421
14457
|
Parser.prototype.parseNumber = function () {
|
|
14422
|
-
var token = this.peek();
|
|
14458
|
+
var token = this.asToken(this.peek());
|
|
14423
14459
|
this.advance();
|
|
14424
14460
|
var value = token[1];
|
|
14425
14461
|
var negative = value[0] === '-';
|
|
@@ -14427,7 +14463,7 @@ var Parser = /** @class */ (function () {
|
|
|
14427
14463
|
return withSourceCodeInfo([NodeTypes.Number, negative ? -Number(numberString) : Number(numberString)], token[2]);
|
|
14428
14464
|
};
|
|
14429
14465
|
Parser.prototype.parseString = function () {
|
|
14430
|
-
var token = this.peek();
|
|
14466
|
+
var token = this.asToken(this.peek());
|
|
14431
14467
|
this.advance();
|
|
14432
14468
|
var value = token[1].substring(1, token[1].length - 1)
|
|
14433
14469
|
.replace(/(\\{2})|(\\")|(\\n)|(\\t)|(\\r)|(\\b)|(\\f)|\\(.)/g, function (_, backslash, doubleQuote, newline, tab, carriageReturn, backspace, formFeed, normalChar) {
|
|
@@ -14459,7 +14495,7 @@ var Parser = /** @class */ (function () {
|
|
|
14459
14495
|
return withSourceCodeInfo([NodeTypes.String, value], token[2]);
|
|
14460
14496
|
};
|
|
14461
14497
|
Parser.prototype.parseRegexpShorthand = function () {
|
|
14462
|
-
var token = this.peek();
|
|
14498
|
+
var token = this.asToken(this.peek());
|
|
14463
14499
|
this.advance();
|
|
14464
14500
|
var endStringPosition = token[1].lastIndexOf('"');
|
|
14465
14501
|
var regexpString = token[1].substring(2, endStringPosition);
|
|
@@ -15357,7 +15393,6 @@ var arrayReference = {
|
|
|
15357
15393
|
examples: [
|
|
15358
15394
|
'flatten([1, 2, [3, 4], 5])',
|
|
15359
15395
|
"\nlet foo := \"bar\";\nflatten([\n 1,\n \" 2 A \",\n [foo, [4, [\"ABC\"]]],\n 6,\n])",
|
|
15360
|
-
'flatten(12)',
|
|
15361
15396
|
],
|
|
15362
15397
|
noOperatorDocumentation: true,
|
|
15363
15398
|
},
|