@mojir/lits 2.0.8 → 2.0.10

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/index.esm.js CHANGED
@@ -3161,7 +3161,7 @@ var mathNormalExpression = {
3161
3161
  },
3162
3162
  };
3163
3163
 
3164
- var version = "2.0.8";
3164
+ var version = "2.0.10";
3165
3165
 
3166
3166
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3167
3167
  var xyRegexp = /[xy]/g;
@@ -4376,6 +4376,7 @@ var andSpecialExpression = {
4376
4376
  };
4377
4377
  return node;
4378
4378
  },
4379
+ validateParameterCount: function () { return undefined; },
4379
4380
  evaluate: function (node, contextStack, _a) {
4380
4381
  var e_1, _b;
4381
4382
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4403,42 +4404,30 @@ var andSpecialExpression = {
4403
4404
  },
4404
4405
  };
4405
4406
 
4406
- var commentSpecialExpression = {
4407
- parse: function (tokenStream, parseState, firstToken, _a) {
4408
- var parseToken = _a.parseToken;
4409
- var node = {
4410
- t: AstNodeType.SpecialExpression,
4411
- n: 'comment',
4412
- p: [],
4413
- token: undefined,
4414
- };
4415
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4416
- while (!isRParenToken(tkn)) {
4417
- node.p.push(parseToken(tokenStream, parseState));
4418
- tkn = asToken(tokenStream.tokens[parseState.position]);
4419
- }
4420
- parseState.position += 1;
4421
- node.token = getTokenDebugData(firstToken) && firstToken;
4422
- return node;
4423
- },
4424
- evaluate: function () { return null; },
4425
- findUnresolvedIdentifiers: function () { return new Set(); },
4426
- };
4427
-
4428
- var condSpecialExpression = {
4429
- parse: function (tokenStream, parseState, firstToken, _a) {
4407
+ function getCommonParser(name) {
4408
+ return function (tokenStream, parseState, firstToken, _a) {
4430
4409
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4431
4410
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4432
4411
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4433
- var node = {
4412
+ return {
4434
4413
  t: AstNodeType.SpecialExpression,
4435
- n: 'cond',
4414
+ n: name,
4436
4415
  p: params,
4437
4416
  token: getTokenDebugData(firstToken) && firstToken,
4438
4417
  };
4439
- assertEvenNumberOfParams(node);
4440
- return node;
4441
- },
4418
+ };
4419
+ }
4420
+
4421
+ var commentSpecialExpression = {
4422
+ parse: getCommonParser('comment'),
4423
+ validateParameterCount: function () { return undefined; },
4424
+ evaluate: function () { return null; },
4425
+ findUnresolvedIdentifiers: function () { return new Set(); },
4426
+ };
4427
+
4428
+ var condSpecialExpression = {
4429
+ parse: getCommonParser('cond'),
4430
+ validateParameterCount: function (node) { return assertEvenNumberOfParams(node); },
4442
4431
  evaluate: function (node, contextStack, _a) {
4443
4432
  var e_1, _b;
4444
4433
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4467,19 +4456,8 @@ var condSpecialExpression = {
4467
4456
  };
4468
4457
 
4469
4458
  var declaredSpecialExpression = {
4470
- parse: function (tokenStream, parseState, firstToken, _a) {
4471
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4472
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4473
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4474
- var node = {
4475
- t: AstNodeType.SpecialExpression,
4476
- n: 'declared?',
4477
- p: params,
4478
- token: getTokenDebugData(firstToken) && firstToken,
4479
- };
4480
- assertNumberOfParams(1, node);
4481
- return node;
4482
- },
4459
+ parse: getCommonParser('declared?'),
4460
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
4483
4461
  evaluate: function (node, contextStack) {
4484
4462
  var lookUpResult = contextStack.lookUp(node.p[0]);
4485
4463
  return lookUpResult !== null;
@@ -4525,9 +4503,9 @@ var defSpecialExpression = {
4525
4503
  token: getTokenDebugData(firstToken) && firstToken,
4526
4504
  };
4527
4505
  assertSymbolNode(node.p[0], (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
4528
- assertNumberOfParams(2, node);
4529
4506
  return node;
4530
4507
  },
4508
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4531
4509
  evaluate: function (node, contextStack, _a) {
4532
4510
  var _b;
4533
4511
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4563,9 +4541,9 @@ var defsSpecialExpression = {
4563
4541
  p: params,
4564
4542
  token: getTokenDebugData(firstToken) && firstToken,
4565
4543
  };
4566
- assertNumberOfParams(2, node);
4567
4544
  return node;
4568
4545
  },
4546
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4569
4547
  evaluate: function (node, contextStack, _a) {
4570
4548
  var _b, _c;
4571
4549
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4593,23 +4571,8 @@ var defsSpecialExpression = {
4593
4571
  };
4594
4572
 
4595
4573
  var doSpecialExpression = {
4596
- parse: function (tokenStream, parseState, firstToken, _a) {
4597
- var parseToken = _a.parseToken;
4598
- var node = {
4599
- t: AstNodeType.SpecialExpression,
4600
- n: 'do',
4601
- p: [],
4602
- token: undefined,
4603
- };
4604
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4605
- while (!isRParenToken(tkn)) {
4606
- node.p.push(parseToken(tokenStream, parseState));
4607
- tkn = asToken(tokenStream.tokens[parseState.position]);
4608
- }
4609
- parseState.position += 1;
4610
- node.token = getTokenDebugData(firstToken) && firstToken;
4611
- return node;
4612
- },
4574
+ parse: getCommonParser('do'),
4575
+ validateParameterCount: function () { return undefined; },
4613
4576
  evaluate: function (node, contextStack, _a) {
4614
4577
  var e_1, _b;
4615
4578
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4686,6 +4649,7 @@ var defnSpecialExpression = {
4686
4649
  };
4687
4650
  return node;
4688
4651
  },
4652
+ validateParameterCount: function () { return undefined; },
4689
4653
  evaluate: function (node, contextStack, _a) {
4690
4654
  var _b;
4691
4655
  var _c, _d;
@@ -4727,6 +4691,7 @@ var defnsSpecialExpression = {
4727
4691
  };
4728
4692
  return node;
4729
4693
  },
4694
+ validateParameterCount: function () { return undefined; },
4730
4695
  evaluate: function (node, contextStack, _a) {
4731
4696
  var _b;
4732
4697
  var _c, _d;
@@ -4770,6 +4735,7 @@ var fnSpecialExpression = {
4770
4735
  };
4771
4736
  return node;
4772
4737
  },
4738
+ validateParameterCount: function () { return undefined; },
4773
4739
  evaluate: function (node, contextStack, _a) {
4774
4740
  var _b;
4775
4741
  var _c;
@@ -5001,19 +4967,8 @@ function parseFunctionArguments(tokenStream, parseState, parsers) {
5001
4967
  }
5002
4968
 
5003
4969
  var ifSpecialExpression = {
5004
- parse: function (tokenStream, parseState, firstToken, _a) {
5005
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5006
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5007
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5008
- var node = {
5009
- t: AstNodeType.SpecialExpression,
5010
- n: 'if',
5011
- p: params,
5012
- token: getTokenDebugData(firstToken) && firstToken,
5013
- };
5014
- assertNumberOfParams({ min: 2, max: 3 }, node);
5015
- return node;
5016
- },
4970
+ parse: getCommonParser('if'),
4971
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5017
4972
  evaluate: function (node, contextStack, _a) {
5018
4973
  var _b;
5019
4974
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5052,9 +5007,9 @@ var ifLetSpecialExpression = {
5052
5007
  p: params,
5053
5008
  token: getTokenDebugData(firstToken) && firstToken,
5054
5009
  };
5055
- assertNumberOfParams({ min: 1, max: 2 }, node);
5056
5010
  return node;
5057
5011
  },
5012
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5058
5013
  evaluate: function (node, contextStack, _a) {
5059
5014
  var _b;
5060
5015
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5084,19 +5039,8 @@ var ifLetSpecialExpression = {
5084
5039
  };
5085
5040
 
5086
5041
  var ifNotSpecialExpression = {
5087
- parse: function (tokenStream, parseState, firstToken, _a) {
5088
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5089
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5090
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5091
- var node = {
5092
- t: AstNodeType.SpecialExpression,
5093
- n: 'if-not',
5094
- p: params,
5095
- token: getTokenDebugData(firstToken) && firstToken,
5096
- };
5097
- assertNumberOfParams({ min: 2, max: 3 }, node);
5098
- return node;
5099
- },
5042
+ parse: getCommonParser('if-not'),
5043
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5100
5044
  evaluate: function (node, contextStack, _a) {
5101
5045
  var _b;
5102
5046
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5133,6 +5077,7 @@ var letSpecialExpression = {
5133
5077
  };
5134
5078
  return node;
5135
5079
  },
5080
+ validateParameterCount: function () { return undefined; },
5136
5081
  evaluate: function (node, contextStack, _a) {
5137
5082
  var e_1, _b, e_2, _c;
5138
5083
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5204,6 +5149,7 @@ var loopSpecialExpression = {
5204
5149
  };
5205
5150
  return node;
5206
5151
  },
5152
+ validateParameterCount: function () { return undefined; },
5207
5153
  evaluate: function (node, contextStack, _a) {
5208
5154
  var _b;
5209
5155
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5467,9 +5413,9 @@ var forSpecialExpression = {
5467
5413
  p: params,
5468
5414
  token: getTokenDebugData(firstToken) && firstToken,
5469
5415
  };
5470
- assertNumberOfParams(1, node);
5471
5416
  return node;
5472
5417
  },
5418
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5473
5419
  evaluate: function (node, contextStack, helpers) { return evaluateLoop(true, node, contextStack, helpers.evaluateAstNode); },
5474
5420
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
5475
5421
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
@@ -5489,9 +5435,9 @@ var doseqSpecialExpression = {
5489
5435
  p: params,
5490
5436
  token: getTokenDebugData(firstToken) && firstToken,
5491
5437
  };
5492
- assertNumberOfParams(1, node);
5493
5438
  return node;
5494
5439
  },
5440
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5495
5441
  evaluate: function (node, contextStack, helpers) {
5496
5442
  evaluateLoop(false, node, contextStack, helpers.evaluateAstNode);
5497
5443
  return null;
@@ -5503,18 +5449,8 @@ var doseqSpecialExpression = {
5503
5449
  };
5504
5450
 
5505
5451
  var orSpecialExpression = {
5506
- parse: function (tokenStream, parseState, firstToken, _a) {
5507
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5508
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5509
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5510
- var node = {
5511
- t: AstNodeType.SpecialExpression,
5512
- n: 'or',
5513
- p: params,
5514
- token: getTokenDebugData(firstToken) && firstToken,
5515
- };
5516
- return node;
5517
- },
5452
+ parse: getCommonParser('or'),
5453
+ validateParameterCount: function () { return undefined; },
5518
5454
  evaluate: function (node, contextStack, _a) {
5519
5455
  var e_1, _b;
5520
5456
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5543,19 +5479,8 @@ var orSpecialExpression = {
5543
5479
  };
5544
5480
 
5545
5481
  var qqSpecialExpression = {
5546
- parse: function (tokenStream, parseState, firstToken, _a) {
5547
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5548
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5549
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5550
- var node = {
5551
- t: AstNodeType.SpecialExpression,
5552
- n: '??',
5553
- p: params,
5554
- token: getTokenDebugData(firstToken) && firstToken,
5555
- };
5556
- assertNumberOfParams({ min: 1, max: 2 }, node);
5557
- return node;
5558
- },
5482
+ parse: getCommonParser('??'),
5483
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5559
5484
  evaluate: function (node, contextStack, _a) {
5560
5485
  var _b;
5561
5486
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5587,6 +5512,7 @@ var recurSpecialExpression = {
5587
5512
  };
5588
5513
  return node;
5589
5514
  },
5515
+ validateParameterCount: function () { return undefined; },
5590
5516
  evaluate: function (node, contextStack, _a) {
5591
5517
  var evaluateAstNode = _a.evaluateAstNode;
5592
5518
  var params = node.p.map(function (paramNode) { return evaluateAstNode(paramNode, contextStack); });
@@ -5599,19 +5525,8 @@ var recurSpecialExpression = {
5599
5525
  };
5600
5526
 
5601
5527
  var throwSpecialExpression = {
5602
- parse: function (tokenStream, parseState, firstToken, _a) {
5603
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5604
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5605
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5606
- var node = {
5607
- t: AstNodeType.SpecialExpression,
5608
- n: 'throw',
5609
- p: params,
5610
- token: getTokenDebugData(firstToken) && firstToken,
5611
- };
5612
- assertNumberOfParams(1, node);
5613
- return node;
5614
- },
5528
+ parse: getCommonParser('throw'),
5529
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5615
5530
  evaluate: function (node, contextStack, _a) {
5616
5531
  var _b, _c;
5617
5532
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5627,19 +5542,8 @@ var throwSpecialExpression = {
5627
5542
  };
5628
5543
 
5629
5544
  var timeSpecialExpression = {
5630
- parse: function (tokenStream, parseState, firstToken, _a) {
5631
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5632
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5633
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5634
- var node = {
5635
- t: AstNodeType.SpecialExpression,
5636
- n: 'time!',
5637
- p: params,
5638
- token: getTokenDebugData(firstToken) && firstToken,
5639
- };
5640
- assertNumberOfParams(1, node);
5641
- return node;
5642
- },
5545
+ parse: getCommonParser('time!'),
5546
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5643
5547
  evaluate: function (node, contextStack, _a) {
5644
5548
  var evaluateAstNode = _a.evaluateAstNode;
5645
5549
  var param = node.p[0];
@@ -5680,9 +5584,9 @@ var trySpecialExpression = {
5680
5584
  e: error,
5681
5585
  token: getTokenDebugData(firstToken) && firstToken,
5682
5586
  };
5683
- assertNumberOfParams(1, node);
5684
5587
  return node;
5685
5588
  },
5589
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5686
5590
  evaluate: function (node, contextStack, _a) {
5687
5591
  var _b;
5688
5592
  var _c;
@@ -5712,19 +5616,8 @@ var trySpecialExpression = {
5712
5616
  };
5713
5617
 
5714
5618
  var whenSpecialExpression = {
5715
- parse: function (tokenStream, parseState, firstToken, _a) {
5716
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5717
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5718
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5719
- var node = {
5720
- t: AstNodeType.SpecialExpression,
5721
- n: 'when',
5722
- p: params,
5723
- token: getTokenDebugData(firstToken) && firstToken,
5724
- };
5725
- assertNumberOfParams({ min: 1 }, node);
5726
- return node;
5727
- },
5619
+ parse: getCommonParser('when'),
5620
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5728
5621
  evaluate: function (node, contextStack, _a) {
5729
5622
  var e_1, _b;
5730
5623
  var _c;
@@ -5774,6 +5667,7 @@ var whenFirstSpecialExpression = {
5774
5667
  };
5775
5668
  return node;
5776
5669
  },
5670
+ validateParameterCount: function () { return undefined; },
5777
5671
  evaluate: function (node, contextStack, _a) {
5778
5672
  var e_1, _b;
5779
5673
  var _c;
@@ -5835,6 +5729,7 @@ var whenLetSpecialExpression = {
5835
5729
  };
5836
5730
  return node;
5837
5731
  },
5732
+ validateParameterCount: function () { return undefined; },
5838
5733
  evaluate: function (node, contextStack, _a) {
5839
5734
  var e_1, _b;
5840
5735
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5873,19 +5768,8 @@ var whenLetSpecialExpression = {
5873
5768
  };
5874
5769
 
5875
5770
  var whenNotSpecialExpression = {
5876
- parse: function (tokenStream, parseState, firstToken, _a) {
5877
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5878
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5879
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5880
- var node = {
5881
- t: AstNodeType.SpecialExpression,
5882
- n: 'when-not',
5883
- p: params,
5884
- token: getTokenDebugData(firstToken) && firstToken,
5885
- };
5886
- assertNumberOfParams({ min: 1 }, node);
5887
- return node;
5888
- },
5771
+ parse: getCommonParser('when-not'),
5772
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5889
5773
  evaluate: function (node, contextStack, _a) {
5890
5774
  var e_1, _b;
5891
5775
  var _c;
@@ -7113,6 +6997,7 @@ function parseString(tokenStream, parseState) {
7113
6997
  }
7114
6998
 
7115
6999
  var exponentiationPrecedence = 9;
7000
+ var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
7116
7001
  function getPrecedence(operator) {
7117
7002
  var operatorSign = operator[1];
7118
7003
  switch (operatorSign) {
@@ -7345,7 +7230,7 @@ var AlgebraicParser = /** @class */ (function () {
7345
7230
  // Parentheses
7346
7231
  if (isLParenToken(token)) {
7347
7232
  var positionBefore = this.parseState.position;
7348
- var lamdaFunction = this.parseLamdaFunction();
7233
+ var lamdaFunction = this.parseLambdaFunction();
7349
7234
  if (lamdaFunction) {
7350
7235
  return lamdaFunction;
7351
7236
  }
@@ -7366,6 +7251,9 @@ var AlgebraicParser = /** @class */ (function () {
7366
7251
  var operand = this.parseOperand();
7367
7252
  return fromUnaryAlgebraicToAstNode(token, operand);
7368
7253
  }
7254
+ else if (operatorName === '=>') {
7255
+ return this.parseShorthandLamdaFunction();
7256
+ }
7369
7257
  else {
7370
7258
  throw new Error("Unknown unary operator: ".concat(operatorName));
7371
7259
  }
@@ -7481,7 +7369,7 @@ var AlgebraicParser = /** @class */ (function () {
7481
7369
  };
7482
7370
  };
7483
7371
  AlgebraicParser.prototype.parseFunctionCall = function (symbol) {
7484
- var _a, _b;
7372
+ var _a, _b, _c;
7485
7373
  var params = [];
7486
7374
  this.advance();
7487
7375
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
@@ -7513,13 +7401,17 @@ var AlgebraicParser = /** @class */ (function () {
7513
7401
  case 'when':
7514
7402
  case 'when-not':
7515
7403
  case 'do':
7516
- case 'throw':
7517
- return {
7404
+ case 'time!':
7405
+ case 'throw': {
7406
+ var node_1 = {
7518
7407
  t: AstNodeType.SpecialExpression,
7519
7408
  n: name_1,
7520
7409
  p: params,
7521
7410
  token: getTokenDebugData(symbol.token) && symbol.token,
7522
7411
  };
7412
+ builtin.specialExpressions[node_1.n].validateParameterCount(node_1);
7413
+ return node_1;
7414
+ }
7523
7415
  case 'def':
7524
7416
  case 'defs':
7525
7417
  case 'let':
@@ -7532,7 +7424,6 @@ var AlgebraicParser = /** @class */ (function () {
7532
7424
  case 'try':
7533
7425
  case 'recur':
7534
7426
  case 'loop':
7535
- case 'time!':
7536
7427
  case 'doseq':
7537
7428
  case 'for':
7538
7429
  throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
@@ -7540,7 +7431,12 @@ var AlgebraicParser = /** @class */ (function () {
7540
7431
  throw new Error("Unknown special expression: ".concat(name_1));
7541
7432
  }
7542
7433
  }
7543
- return createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7434
+ var node = createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7435
+ var builtinExpression = builtin.normalExpressions[node.n];
7436
+ if (builtinExpression) {
7437
+ (_c = builtinExpression.validate) === null || _c === void 0 ? void 0 : _c.call(builtinExpression, __assign(__assign({}, node), { p: withoutCommentNodes(node.p) }));
7438
+ }
7439
+ return node;
7544
7440
  }
7545
7441
  else {
7546
7442
  return {
@@ -7551,7 +7447,7 @@ var AlgebraicParser = /** @class */ (function () {
7551
7447
  };
7552
7448
  }
7553
7449
  };
7554
- AlgebraicParser.prototype.parseLamdaFunction = function () {
7450
+ AlgebraicParser.prototype.parseLambdaFunction = function () {
7555
7451
  var _a;
7556
7452
  var firstToken = this.peek();
7557
7453
  this.advance();
@@ -7610,6 +7506,62 @@ var AlgebraicParser = /** @class */ (function () {
7610
7506
  token: getTokenDebugData(firstToken) && firstToken,
7611
7507
  };
7612
7508
  };
7509
+ AlgebraicParser.prototype.parseShorthandLamdaFunction = function () {
7510
+ var _a, _b, _c, _d;
7511
+ var firstToken = this.peek();
7512
+ this.advance();
7513
+ var startPos = this.parseState.position;
7514
+ var exprNode = this.parseExpression();
7515
+ var endPos = this.parseState.position - 1;
7516
+ var arity = 0;
7517
+ var percent1 = 'NOT_SET'; // referring to argument bindings. % = NAKED, %1, %2, %3, etc = WITH_1
7518
+ for (var pos = startPos; pos <= endPos; pos += 1) {
7519
+ var tkn = this.tokenStream.tokens[pos];
7520
+ if (isA_SymbolToken(tkn)) {
7521
+ var match = placeholderRegexp$1.exec(tkn[1]);
7522
+ if (match) {
7523
+ var number = (_a = match[1]) !== null && _a !== void 0 ? _a : '1';
7524
+ if (number === '1') {
7525
+ var mixedPercent1 = (!match[1] && percent1 === 'WITH_1') || (match[1] && percent1 === 'NAKED');
7526
+ if (mixedPercent1)
7527
+ throw new LitsError('Please make up your mind, either use $ or $1', (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7528
+ percent1 = match[1] ? 'WITH_1' : 'NAKED';
7529
+ }
7530
+ arity = Math.max(arity, Number(number));
7531
+ if (arity > 20)
7532
+ throw new LitsError('Can\'t specify more than 20 arguments', (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
7533
+ }
7534
+ }
7535
+ if (isA_OperatorToken(tkn, '=>')) {
7536
+ throw new LitsError('Nested shortcut functions are not allowed', (_d = getTokenDebugData(firstToken)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo);
7537
+ }
7538
+ }
7539
+ var mandatoryArguments = [];
7540
+ for (var i = 1; i <= arity; i += 1) {
7541
+ if (i === 1 && percent1 === 'NAKED')
7542
+ mandatoryArguments.push('$');
7543
+ else
7544
+ mandatoryArguments.push("$".concat(i));
7545
+ }
7546
+ var args = {
7547
+ b: [],
7548
+ m: mandatoryArguments,
7549
+ };
7550
+ var node = {
7551
+ t: AstNodeType.SpecialExpression,
7552
+ n: 'fn',
7553
+ p: [],
7554
+ o: [
7555
+ {
7556
+ as: args,
7557
+ b: [exprNode],
7558
+ a: args.m.length,
7559
+ },
7560
+ ],
7561
+ token: getTokenDebugData(firstToken) && firstToken,
7562
+ };
7563
+ return node;
7564
+ };
7613
7565
  AlgebraicParser.prototype.isAtEnd = function () {
7614
7566
  return this.parseState.position >= this.tokenStream.tokens.length;
7615
7567
  };
@@ -7853,7 +7805,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7853
7805
  var firstToken = asLParenToken(tokenStream.tokens[parseState.position++]);
7854
7806
  var nameToken = asP_SymbolToken(tokenStream.tokens[parseState.position++]);
7855
7807
  var expressionName = nameToken[1];
7856
- var parse = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo).parse;
7808
+ var _b = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo), parse = _b.parse, validateParameterCount = _b.validateParameterCount;
7857
7809
  var node = parse(tokenStream, parseState, firstToken, {
7858
7810
  parseExpression: parseExpression,
7859
7811
  parseTokensUntilClosingBracket: parseTokensUntilClosingBracket,
@@ -7862,6 +7814,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7862
7814
  parseBindings: parseBindings,
7863
7815
  parseArgument: parseArgument,
7864
7816
  });
7817
+ validateParameterCount(node);
7865
7818
  return node;
7866
7819
  }
7867
7820
  function parsePolishToken(tokenStream, parseState) {