@mojir/lits 2.0.9 → 2.0.11

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.
@@ -413,6 +413,12 @@ function isA_SymbolToken(token) {
413
413
  function isA_ReservedSymbolToken(token) {
414
414
  return (token === null || token === void 0 ? void 0 : token[0]) === 'A_ReservedSymbol';
415
415
  }
416
+ function isA_CommentToken(token) {
417
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'A_SingleLineComment';
418
+ }
419
+ function isA_MultiLineCommentToken(token) {
420
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'A_MultiLineComment';
421
+ }
416
422
  function isA_OperatorToken(token, operatorName) {
417
423
  if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Operator') {
418
424
  return false;
@@ -3124,7 +3130,7 @@ var mathNormalExpression = {
3124
3130
  },
3125
3131
  };
3126
3132
 
3127
- var version = "2.0.9";
3133
+ var version = "2.0.11";
3128
3134
 
3129
3135
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3130
3136
  var xyRegexp = /[xy]/g;
@@ -4327,7 +4333,7 @@ var functionalNormalExpression = {
4327
4333
  var normalExpressions = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, bitwiseNormalExpression), collectionNormalExpression), arrayNormalExpression), sequenceNormalExpression), mathNormalExpression), miscNormalExpression), assertNormalExpression), objectNormalExpression), predicatesNormalExpression), regexpNormalExpression), stringNormalExpression), functionalNormalExpression);
4328
4334
 
4329
4335
  var andSpecialExpression = {
4330
- parse: function (tokenStream, parseState, firstToken, _a) {
4336
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4331
4337
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4332
4338
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4333
4339
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -4339,6 +4345,7 @@ var andSpecialExpression = {
4339
4345
  };
4340
4346
  return node;
4341
4347
  },
4348
+ validateParameterCount: function () { return undefined; },
4342
4349
  evaluate: function (node, contextStack, _a) {
4343
4350
  var e_1, _b;
4344
4351
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4366,42 +4373,30 @@ var andSpecialExpression = {
4366
4373
  },
4367
4374
  };
4368
4375
 
4369
- var commentSpecialExpression = {
4370
- parse: function (tokenStream, parseState, firstToken, _a) {
4371
- var parseToken = _a.parseToken;
4372
- var node = {
4373
- t: AstNodeType.SpecialExpression,
4374
- n: 'comment',
4375
- p: [],
4376
- token: undefined,
4377
- };
4378
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4379
- while (!isRParenToken(tkn)) {
4380
- node.p.push(parseToken(tokenStream, parseState));
4381
- tkn = asToken(tokenStream.tokens[parseState.position]);
4382
- }
4383
- parseState.position += 1;
4384
- node.token = getTokenDebugData(firstToken) && firstToken;
4385
- return node;
4386
- },
4387
- evaluate: function () { return null; },
4388
- findUnresolvedIdentifiers: function () { return new Set(); },
4389
- };
4390
-
4391
- var condSpecialExpression = {
4392
- parse: function (tokenStream, parseState, firstToken, _a) {
4376
+ function getCommonPolishSpecialExpressionParser(name) {
4377
+ return function (tokenStream, parseState, firstToken, _a) {
4393
4378
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4394
4379
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4395
4380
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4396
- var node = {
4381
+ return {
4397
4382
  t: AstNodeType.SpecialExpression,
4398
- n: 'cond',
4383
+ n: name,
4399
4384
  p: params,
4400
4385
  token: getTokenDebugData(firstToken) && firstToken,
4401
4386
  };
4402
- assertEvenNumberOfParams(node);
4403
- return node;
4404
- },
4387
+ };
4388
+ }
4389
+
4390
+ var commentSpecialExpression = {
4391
+ polishParse: getCommonPolishSpecialExpressionParser('comment'),
4392
+ validateParameterCount: function () { return undefined; },
4393
+ evaluate: function () { return null; },
4394
+ findUnresolvedIdentifiers: function () { return new Set(); },
4395
+ };
4396
+
4397
+ var condSpecialExpression = {
4398
+ polishParse: getCommonPolishSpecialExpressionParser('cond'),
4399
+ validateParameterCount: function (node) { return assertEvenNumberOfParams(node); },
4405
4400
  evaluate: function (node, contextStack, _a) {
4406
4401
  var e_1, _b;
4407
4402
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4430,19 +4425,8 @@ var condSpecialExpression = {
4430
4425
  };
4431
4426
 
4432
4427
  var declaredSpecialExpression = {
4433
- parse: function (tokenStream, parseState, firstToken, _a) {
4434
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4435
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4436
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4437
- var node = {
4438
- t: AstNodeType.SpecialExpression,
4439
- n: 'declared?',
4440
- p: params,
4441
- token: getTokenDebugData(firstToken) && firstToken,
4442
- };
4443
- assertNumberOfParams(1, node);
4444
- return node;
4445
- },
4428
+ polishParse: getCommonPolishSpecialExpressionParser('declared?'),
4429
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
4446
4430
  evaluate: function (node, contextStack) {
4447
4431
  var lookUpResult = contextStack.lookUp(node.p[0]);
4448
4432
  return lookUpResult !== null;
@@ -4475,7 +4459,7 @@ function assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo) {
4475
4459
  }
4476
4460
 
4477
4461
  var defSpecialExpression = {
4478
- parse: function (tokenStream, parseState, firstToken, _a) {
4462
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4479
4463
  var _b;
4480
4464
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4481
4465
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -4487,9 +4471,9 @@ var defSpecialExpression = {
4487
4471
  token: getTokenDebugData(firstToken) && firstToken,
4488
4472
  };
4489
4473
  assertSymbolNode(node.p[0], (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
4490
- assertNumberOfParams(2, node);
4491
4474
  return node;
4492
4475
  },
4476
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4493
4477
  evaluate: function (node, contextStack, _a) {
4494
4478
  var _b;
4495
4479
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4515,7 +4499,7 @@ var defSpecialExpression = {
4515
4499
  };
4516
4500
 
4517
4501
  var defsSpecialExpression = {
4518
- parse: function (tokenStream, parseState, firstToken, _a) {
4502
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4519
4503
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4520
4504
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4521
4505
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -4525,9 +4509,9 @@ var defsSpecialExpression = {
4525
4509
  p: params,
4526
4510
  token: getTokenDebugData(firstToken) && firstToken,
4527
4511
  };
4528
- assertNumberOfParams(2, node);
4529
4512
  return node;
4530
4513
  },
4514
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4531
4515
  evaluate: function (node, contextStack, _a) {
4532
4516
  var _b, _c;
4533
4517
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4555,23 +4539,8 @@ var defsSpecialExpression = {
4555
4539
  };
4556
4540
 
4557
4541
  var doSpecialExpression = {
4558
- parse: function (tokenStream, parseState, firstToken, _a) {
4559
- var parseToken = _a.parseToken;
4560
- var node = {
4561
- t: AstNodeType.SpecialExpression,
4562
- n: 'do',
4563
- p: [],
4564
- token: undefined,
4565
- };
4566
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4567
- while (!isRParenToken(tkn)) {
4568
- node.p.push(parseToken(tokenStream, parseState));
4569
- tkn = asToken(tokenStream.tokens[parseState.position]);
4570
- }
4571
- parseState.position += 1;
4572
- node.token = getTokenDebugData(firstToken) && firstToken;
4573
- return node;
4574
- },
4542
+ polishParse: getCommonPolishSpecialExpressionParser('do'),
4543
+ validateParameterCount: function () { return undefined; },
4575
4544
  evaluate: function (node, contextStack, _a) {
4576
4545
  var e_1, _b;
4577
4546
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4631,7 +4600,7 @@ function combinate(arrays) {
4631
4600
  }
4632
4601
 
4633
4602
  var defnSpecialExpression = {
4634
- parse: function (tokenStream, parseState, firstToken, parsers) {
4603
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4635
4604
  var _a;
4636
4605
  var parseToken = parsers.parseToken;
4637
4606
  var functionName = parseToken(tokenStream, parseState);
@@ -4648,6 +4617,7 @@ var defnSpecialExpression = {
4648
4617
  };
4649
4618
  return node;
4650
4619
  },
4620
+ validateParameterCount: function () { return undefined; },
4651
4621
  evaluate: function (node, contextStack, _a) {
4652
4622
  var _b;
4653
4623
  var _c, _d;
@@ -4674,7 +4644,7 @@ var defnSpecialExpression = {
4674
4644
  },
4675
4645
  };
4676
4646
  var defnsSpecialExpression = {
4677
- parse: function (tokenStream, parseState, firstToken, parsers) {
4647
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4678
4648
  var parseToken = parsers.parseToken;
4679
4649
  var functionName = parseToken(tokenStream, parseState);
4680
4650
  var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
@@ -4689,6 +4659,7 @@ var defnsSpecialExpression = {
4689
4659
  };
4690
4660
  return node;
4691
4661
  },
4662
+ validateParameterCount: function () { return undefined; },
4692
4663
  evaluate: function (node, contextStack, _a) {
4693
4664
  var _b;
4694
4665
  var _c, _d;
@@ -4720,7 +4691,7 @@ var defnsSpecialExpression = {
4720
4691
  },
4721
4692
  };
4722
4693
  var fnSpecialExpression = {
4723
- parse: function (tokenStream, parseState, firstToken, parsers) {
4694
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4724
4695
  var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
4725
4696
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4726
4697
  var node = {
@@ -4732,6 +4703,7 @@ var fnSpecialExpression = {
4732
4703
  };
4733
4704
  return node;
4734
4705
  },
4706
+ validateParameterCount: function () { return undefined; },
4735
4707
  evaluate: function (node, contextStack, _a) {
4736
4708
  var _b;
4737
4709
  var _c;
@@ -4963,19 +4935,8 @@ function parseFunctionArguments(tokenStream, parseState, parsers) {
4963
4935
  }
4964
4936
 
4965
4937
  var ifSpecialExpression = {
4966
- parse: function (tokenStream, parseState, firstToken, _a) {
4967
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4968
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4969
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4970
- var node = {
4971
- t: AstNodeType.SpecialExpression,
4972
- n: 'if',
4973
- p: params,
4974
- token: getTokenDebugData(firstToken) && firstToken,
4975
- };
4976
- assertNumberOfParams({ min: 2, max: 3 }, node);
4977
- return node;
4978
- },
4938
+ polishParse: getCommonPolishSpecialExpressionParser('if'),
4939
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
4979
4940
  evaluate: function (node, contextStack, _a) {
4980
4941
  var _b;
4981
4942
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4998,7 +4959,7 @@ var ifSpecialExpression = {
4998
4959
  };
4999
4960
 
5000
4961
  var ifLetSpecialExpression = {
5001
- parse: function (tokenStream, parseState, firstToken, _a) {
4962
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5002
4963
  var _b, _c;
5003
4964
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5004
4965
  var bindings = parseBindings(tokenStream, parseState);
@@ -5014,9 +4975,9 @@ var ifLetSpecialExpression = {
5014
4975
  p: params,
5015
4976
  token: getTokenDebugData(firstToken) && firstToken,
5016
4977
  };
5017
- assertNumberOfParams({ min: 1, max: 2 }, node);
5018
4978
  return node;
5019
4979
  },
4980
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5020
4981
  evaluate: function (node, contextStack, _a) {
5021
4982
  var _b;
5022
4983
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5046,19 +5007,8 @@ var ifLetSpecialExpression = {
5046
5007
  };
5047
5008
 
5048
5009
  var ifNotSpecialExpression = {
5049
- parse: function (tokenStream, parseState, firstToken, _a) {
5050
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5051
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5052
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5053
- var node = {
5054
- t: AstNodeType.SpecialExpression,
5055
- n: 'if-not',
5056
- p: params,
5057
- token: getTokenDebugData(firstToken) && firstToken,
5058
- };
5059
- assertNumberOfParams({ min: 2, max: 3 }, node);
5060
- return node;
5061
- },
5010
+ polishParse: getCommonPolishSpecialExpressionParser('if-not'),
5011
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5062
5012
  evaluate: function (node, contextStack, _a) {
5063
5013
  var _b;
5064
5014
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5081,7 +5031,7 @@ var ifNotSpecialExpression = {
5081
5031
  };
5082
5032
 
5083
5033
  var letSpecialExpression = {
5084
- parse: function (tokenStream, parseState, firstToken, _a) {
5034
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5085
5035
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5086
5036
  var bindings = parseBindings(tokenStream, parseState);
5087
5037
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5095,6 +5045,7 @@ var letSpecialExpression = {
5095
5045
  };
5096
5046
  return node;
5097
5047
  },
5048
+ validateParameterCount: function () { return undefined; },
5098
5049
  evaluate: function (node, contextStack, _a) {
5099
5050
  var e_1, _b, e_2, _c;
5100
5051
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5152,7 +5103,7 @@ var letSpecialExpression = {
5152
5103
  };
5153
5104
 
5154
5105
  var loopSpecialExpression = {
5155
- parse: function (tokenStream, parseState, firstToken, _a) {
5106
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5156
5107
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket, parseBindings = _a.parseBindings;
5157
5108
  var bindings = parseBindings(tokenStream, parseState);
5158
5109
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5166,6 +5117,7 @@ var loopSpecialExpression = {
5166
5117
  };
5167
5118
  return node;
5168
5119
  },
5120
+ validateParameterCount: function () { return undefined; },
5169
5121
  evaluate: function (node, contextStack, _a) {
5170
5122
  var _b;
5171
5123
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5417,7 +5369,7 @@ function analyze$1(node, contextStack, findUnresolvedIdentifiers, builtin) {
5417
5369
  return result;
5418
5370
  }
5419
5371
  var forSpecialExpression = {
5420
- parse: function (tokenStream, parseState, firstToken, parsers) {
5372
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
5421
5373
  var parseTokensUntilClosingBracket = parsers.parseTokensUntilClosingBracket;
5422
5374
  var loopBindings = parseLoopBindings(tokenStream, parseState, parsers);
5423
5375
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5429,9 +5381,9 @@ var forSpecialExpression = {
5429
5381
  p: params,
5430
5382
  token: getTokenDebugData(firstToken) && firstToken,
5431
5383
  };
5432
- assertNumberOfParams(1, node);
5433
5384
  return node;
5434
5385
  },
5386
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5435
5387
  evaluate: function (node, contextStack, helpers) { return evaluateLoop(true, node, contextStack, helpers.evaluateAstNode); },
5436
5388
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
5437
5389
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
@@ -5439,7 +5391,7 @@ var forSpecialExpression = {
5439
5391
  },
5440
5392
  };
5441
5393
  var doseqSpecialExpression = {
5442
- parse: function (tokenStream, parseState, firstToken, parsers) {
5394
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
5443
5395
  var parseTokensUntilClosingBracket = parsers.parseTokensUntilClosingBracket;
5444
5396
  var loopBindings = parseLoopBindings(tokenStream, parseState, parsers);
5445
5397
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5451,9 +5403,9 @@ var doseqSpecialExpression = {
5451
5403
  p: params,
5452
5404
  token: getTokenDebugData(firstToken) && firstToken,
5453
5405
  };
5454
- assertNumberOfParams(1, node);
5455
5406
  return node;
5456
5407
  },
5408
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5457
5409
  evaluate: function (node, contextStack, helpers) {
5458
5410
  evaluateLoop(false, node, contextStack, helpers.evaluateAstNode);
5459
5411
  return null;
@@ -5465,18 +5417,8 @@ var doseqSpecialExpression = {
5465
5417
  };
5466
5418
 
5467
5419
  var orSpecialExpression = {
5468
- parse: function (tokenStream, parseState, firstToken, _a) {
5469
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5470
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5471
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5472
- var node = {
5473
- t: AstNodeType.SpecialExpression,
5474
- n: 'or',
5475
- p: params,
5476
- token: getTokenDebugData(firstToken) && firstToken,
5477
- };
5478
- return node;
5479
- },
5420
+ polishParse: getCommonPolishSpecialExpressionParser('or'),
5421
+ validateParameterCount: function () { return undefined; },
5480
5422
  evaluate: function (node, contextStack, _a) {
5481
5423
  var e_1, _b;
5482
5424
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5505,19 +5447,8 @@ var orSpecialExpression = {
5505
5447
  };
5506
5448
 
5507
5449
  var qqSpecialExpression = {
5508
- parse: function (tokenStream, parseState, firstToken, _a) {
5509
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5510
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5511
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5512
- var node = {
5513
- t: AstNodeType.SpecialExpression,
5514
- n: '??',
5515
- p: params,
5516
- token: getTokenDebugData(firstToken) && firstToken,
5517
- };
5518
- assertNumberOfParams({ min: 1, max: 2 }, node);
5519
- return node;
5520
- },
5450
+ polishParse: getCommonPolishSpecialExpressionParser('??'),
5451
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5521
5452
  evaluate: function (node, contextStack, _a) {
5522
5453
  var _b;
5523
5454
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5537,7 +5468,7 @@ var qqSpecialExpression = {
5537
5468
  };
5538
5469
 
5539
5470
  var recurSpecialExpression = {
5540
- parse: function (tokenStream, parseState, firstToken, _a) {
5471
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5541
5472
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5542
5473
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5543
5474
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -5549,6 +5480,7 @@ var recurSpecialExpression = {
5549
5480
  };
5550
5481
  return node;
5551
5482
  },
5483
+ validateParameterCount: function () { return undefined; },
5552
5484
  evaluate: function (node, contextStack, _a) {
5553
5485
  var evaluateAstNode = _a.evaluateAstNode;
5554
5486
  var params = node.p.map(function (paramNode) { return evaluateAstNode(paramNode, contextStack); });
@@ -5561,19 +5493,8 @@ var recurSpecialExpression = {
5561
5493
  };
5562
5494
 
5563
5495
  var throwSpecialExpression = {
5564
- parse: function (tokenStream, parseState, firstToken, _a) {
5565
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5566
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5567
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5568
- var node = {
5569
- t: AstNodeType.SpecialExpression,
5570
- n: 'throw',
5571
- p: params,
5572
- token: getTokenDebugData(firstToken) && firstToken,
5573
- };
5574
- assertNumberOfParams(1, node);
5575
- return node;
5576
- },
5496
+ polishParse: getCommonPolishSpecialExpressionParser('throw'),
5497
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5577
5498
  evaluate: function (node, contextStack, _a) {
5578
5499
  var _b, _c;
5579
5500
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5589,19 +5510,8 @@ var throwSpecialExpression = {
5589
5510
  };
5590
5511
 
5591
5512
  var timeSpecialExpression = {
5592
- parse: function (tokenStream, parseState, firstToken, _a) {
5593
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5594
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5595
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5596
- var node = {
5597
- t: AstNodeType.SpecialExpression,
5598
- n: 'time!',
5599
- p: params,
5600
- token: getTokenDebugData(firstToken) && firstToken,
5601
- };
5602
- assertNumberOfParams(1, node);
5603
- return node;
5604
- },
5513
+ polishParse: getCommonPolishSpecialExpressionParser('time!'),
5514
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5605
5515
  evaluate: function (node, contextStack, _a) {
5606
5516
  var evaluateAstNode = _a.evaluateAstNode;
5607
5517
  var param = node.p[0];
@@ -5619,7 +5529,7 @@ var timeSpecialExpression = {
5619
5529
  };
5620
5530
 
5621
5531
  var trySpecialExpression = {
5622
- parse: function (tokenStream, parseState, firstToken, _a) {
5532
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5623
5533
  var _b, _c, _d;
5624
5534
  var parseToken = _a.parseToken;
5625
5535
  var tryExpression = parseToken(tokenStream, parseState);
@@ -5642,9 +5552,9 @@ var trySpecialExpression = {
5642
5552
  e: error,
5643
5553
  token: getTokenDebugData(firstToken) && firstToken,
5644
5554
  };
5645
- assertNumberOfParams(1, node);
5646
5555
  return node;
5647
5556
  },
5557
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5648
5558
  evaluate: function (node, contextStack, _a) {
5649
5559
  var _b;
5650
5560
  var _c;
@@ -5674,19 +5584,8 @@ var trySpecialExpression = {
5674
5584
  };
5675
5585
 
5676
5586
  var whenSpecialExpression = {
5677
- parse: function (tokenStream, parseState, firstToken, _a) {
5678
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5679
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5680
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5681
- var node = {
5682
- t: AstNodeType.SpecialExpression,
5683
- n: 'when',
5684
- p: params,
5685
- token: getTokenDebugData(firstToken) && firstToken,
5686
- };
5687
- assertNumberOfParams({ min: 1 }, node);
5688
- return node;
5689
- },
5587
+ polishParse: getCommonPolishSpecialExpressionParser('when'),
5588
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5690
5589
  evaluate: function (node, contextStack, _a) {
5691
5590
  var e_1, _b;
5692
5591
  var _c;
@@ -5718,7 +5617,7 @@ var whenSpecialExpression = {
5718
5617
  };
5719
5618
 
5720
5619
  var whenFirstSpecialExpression = {
5721
- parse: function (tokenStream, parseState, firstToken, _a) {
5620
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5722
5621
  var _b, _c;
5723
5622
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5724
5623
  var bindings = parseBindings(tokenStream, parseState);
@@ -5736,6 +5635,7 @@ var whenFirstSpecialExpression = {
5736
5635
  };
5737
5636
  return node;
5738
5637
  },
5638
+ validateParameterCount: function () { return undefined; },
5739
5639
  evaluate: function (node, contextStack, _a) {
5740
5640
  var e_1, _b;
5741
5641
  var _c;
@@ -5779,7 +5679,7 @@ var whenFirstSpecialExpression = {
5779
5679
  };
5780
5680
 
5781
5681
  var whenLetSpecialExpression = {
5782
- parse: function (tokenStream, parseState, firstToken, _a) {
5682
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5783
5683
  var _b, _c;
5784
5684
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5785
5685
  var bindings = parseBindings(tokenStream, parseState);
@@ -5797,6 +5697,7 @@ var whenLetSpecialExpression = {
5797
5697
  };
5798
5698
  return node;
5799
5699
  },
5700
+ validateParameterCount: function () { return undefined; },
5800
5701
  evaluate: function (node, contextStack, _a) {
5801
5702
  var e_1, _b;
5802
5703
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5835,19 +5736,8 @@ var whenLetSpecialExpression = {
5835
5736
  };
5836
5737
 
5837
5738
  var whenNotSpecialExpression = {
5838
- parse: function (tokenStream, parseState, firstToken, _a) {
5839
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5840
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5841
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5842
- var node = {
5843
- t: AstNodeType.SpecialExpression,
5844
- n: 'when-not',
5845
- p: params,
5846
- token: getTokenDebugData(firstToken) && firstToken,
5847
- };
5848
- assertNumberOfParams({ min: 1 }, node);
5849
- return node;
5850
- },
5739
+ polishParse: getCommonPolishSpecialExpressionParser('when-not'),
5740
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5851
5741
  evaluate: function (node, contextStack, _a) {
5852
5742
  var e_1, _b;
5853
5743
  var _c;
@@ -7447,7 +7337,7 @@ var AlgebraicParser = /** @class */ (function () {
7447
7337
  };
7448
7338
  };
7449
7339
  AlgebraicParser.prototype.parseFunctionCall = function (symbol) {
7450
- var _a, _b;
7340
+ var _a, _b, _c;
7451
7341
  var params = [];
7452
7342
  this.advance();
7453
7343
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
@@ -7479,16 +7369,21 @@ var AlgebraicParser = /** @class */ (function () {
7479
7369
  case 'when':
7480
7370
  case 'when-not':
7481
7371
  case 'do':
7482
- case 'throw':
7483
- return {
7372
+ case 'time!':
7373
+ case 'throw': {
7374
+ var node_1 = {
7484
7375
  t: AstNodeType.SpecialExpression,
7485
7376
  n: name_1,
7486
7377
  p: params,
7487
7378
  token: getTokenDebugData(symbol.token) && symbol.token,
7488
7379
  };
7380
+ builtin.specialExpressions[node_1.n].validateParameterCount(node_1);
7381
+ return node_1;
7382
+ }
7383
+ case 'let':
7384
+ return this.parseLet(symbol, params);
7489
7385
  case 'def':
7490
7386
  case 'defs':
7491
- case 'let':
7492
7387
  case 'if-let':
7493
7388
  case 'when-let':
7494
7389
  case 'when-first':
@@ -7498,7 +7393,6 @@ var AlgebraicParser = /** @class */ (function () {
7498
7393
  case 'try':
7499
7394
  case 'recur':
7500
7395
  case 'loop':
7501
- case 'time!':
7502
7396
  case 'doseq':
7503
7397
  case 'for':
7504
7398
  throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
@@ -7506,7 +7400,12 @@ var AlgebraicParser = /** @class */ (function () {
7506
7400
  throw new Error("Unknown special expression: ".concat(name_1));
7507
7401
  }
7508
7402
  }
7509
- return createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7403
+ var node = createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7404
+ var builtinExpression = builtin.normalExpressions[node.n];
7405
+ if (builtinExpression) {
7406
+ (_c = builtinExpression.validate) === null || _c === void 0 ? void 0 : _c.call(builtinExpression, __assign(__assign({}, node), { p: withoutCommentNodes(node.p) }));
7407
+ }
7408
+ return node;
7510
7409
  }
7511
7410
  else {
7512
7411
  return {
@@ -7518,31 +7417,40 @@ var AlgebraicParser = /** @class */ (function () {
7518
7417
  }
7519
7418
  };
7520
7419
  AlgebraicParser.prototype.parseLambdaFunction = function () {
7521
- var _a;
7420
+ var _a, _b;
7522
7421
  var firstToken = this.peek();
7523
7422
  this.advance();
7524
- var spread = false;
7423
+ var rest = false;
7424
+ var letBindingObject;
7525
7425
  var args = [];
7526
7426
  var restArg;
7527
7427
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
7528
- if (isA_OperatorToken(this.peek(), '...')) {
7529
- if (spread) {
7530
- throw new LitsError('Multiple spread operators in lambda function', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7531
- }
7532
- this.advance();
7533
- spread = true;
7534
- }
7535
- var symbolToken = this.peek();
7536
- if (!isA_SymbolToken(symbolToken)) {
7537
- return null;
7428
+ if (letBindingObject) {
7429
+ throw new LitsError('Expected right parentheses', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7538
7430
  }
7539
- if (spread) {
7540
- restArg = symbolToken[1];
7431
+ if (isLBraceToken(this.peek())) {
7432
+ letBindingObject = this.parseObject();
7541
7433
  }
7542
7434
  else {
7543
- args.push(symbolToken[1]);
7435
+ if (isA_OperatorToken(this.peek(), '...')) {
7436
+ if (rest) {
7437
+ throw new LitsError('Multiple spread operators in lambda function', (_b = getTokenDebugData(this.peek())) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7438
+ }
7439
+ this.advance();
7440
+ rest = true;
7441
+ }
7442
+ var symbolToken = this.peek();
7443
+ if (!isA_SymbolToken(symbolToken)) {
7444
+ return null;
7445
+ }
7446
+ if (rest) {
7447
+ restArg = symbolToken[1];
7448
+ }
7449
+ else {
7450
+ args.push(symbolToken[1]);
7451
+ }
7452
+ this.advance();
7544
7453
  }
7545
- this.advance();
7546
7454
  if (!isA_OperatorToken(this.peek(), ',') && !isRParenToken(this.peek())) {
7547
7455
  return null;
7548
7456
  }
@@ -7558,6 +7466,7 @@ var AlgebraicParser = /** @class */ (function () {
7558
7466
  return null;
7559
7467
  }
7560
7468
  this.advance();
7469
+ var letBindings = letBindingObject ? arrayToPairs(letBindingObject.p) : [];
7561
7470
  var body = this.parseExpression();
7562
7471
  var arity = restArg !== undefined ? { min: args.length } : args.length;
7563
7472
  return {
@@ -7568,7 +7477,17 @@ var AlgebraicParser = /** @class */ (function () {
7568
7477
  as: {
7569
7478
  m: args,
7570
7479
  r: restArg,
7571
- b: [],
7480
+ b: letBindings.map(function (pair) {
7481
+ var key = pair[0];
7482
+ var value = pair[1];
7483
+ return {
7484
+ t: AstNodeType.Binding,
7485
+ n: key.v,
7486
+ v: value,
7487
+ p: [],
7488
+ token: getTokenDebugData(key.token) && key.token,
7489
+ };
7490
+ }),
7572
7491
  },
7573
7492
  b: [body],
7574
7493
  a: arity,
@@ -7632,6 +7551,35 @@ var AlgebraicParser = /** @class */ (function () {
7632
7551
  };
7633
7552
  return node;
7634
7553
  };
7554
+ AlgebraicParser.prototype.parseLet = function (nameSymbol, params) {
7555
+ var _a, _b;
7556
+ if (params.length !== 2) {
7557
+ throw new LitsError('let expects two arguments', (_a = getTokenDebugData(nameSymbol.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7558
+ }
7559
+ var letObject = params[0];
7560
+ if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
7561
+ throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7562
+ }
7563
+ var letBindings = arrayToPairs(letObject.p);
7564
+ var expression = params[1];
7565
+ return {
7566
+ t: AstNodeType.SpecialExpression,
7567
+ n: 'let',
7568
+ p: [expression],
7569
+ token: getTokenDebugData(nameSymbol.token) && nameSymbol.token,
7570
+ bs: letBindings.map(function (pair) {
7571
+ var key = pair[0];
7572
+ var value = pair[1];
7573
+ return {
7574
+ t: AstNodeType.Binding,
7575
+ n: key.v,
7576
+ v: value,
7577
+ p: [],
7578
+ token: getTokenDebugData(key.token) && key.token,
7579
+ };
7580
+ }),
7581
+ };
7582
+ };
7635
7583
  AlgebraicParser.prototype.isAtEnd = function () {
7636
7584
  return this.parseState.position >= this.tokenStream.tokens.length;
7637
7585
  };
@@ -7875,7 +7823,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7875
7823
  var firstToken = asLParenToken(tokenStream.tokens[parseState.position++]);
7876
7824
  var nameToken = asP_SymbolToken(tokenStream.tokens[parseState.position++]);
7877
7825
  var expressionName = nameToken[1];
7878
- var parse = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo).parse;
7826
+ var _b = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo), parse = _b.polishParse, validateParameterCount = _b.validateParameterCount;
7879
7827
  var node = parse(tokenStream, parseState, firstToken, {
7880
7828
  parseExpression: parseExpression,
7881
7829
  parseTokensUntilClosingBracket: parseTokensUntilClosingBracket,
@@ -7884,6 +7832,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7884
7832
  parseBindings: parseBindings,
7885
7833
  parseArgument: parseArgument,
7886
7834
  });
7835
+ validateParameterCount(node);
7887
7836
  return node;
7888
7837
  }
7889
7838
  function parsePolishToken(tokenStream, parseState) {
@@ -7973,7 +7922,11 @@ function parse(tokenStream) {
7973
7922
  }
7974
7923
  function removeUnnecessaryTokens(tokenStream) {
7975
7924
  var tokens = tokenStream.tokens.filter(function (token) {
7976
- if (isP_CommentToken(token) || isA_WhitespaceToken(token) || isP_WhitespaceToken(token)) {
7925
+ if (isP_CommentToken(token)
7926
+ || isA_CommentToken(token)
7927
+ || isA_MultiLineCommentToken(token)
7928
+ || isA_WhitespaceToken(token)
7929
+ || isP_WhitespaceToken(token)) {
7977
7930
  return false;
7978
7931
  }
7979
7932
  return true;
@@ -8288,7 +8241,6 @@ var algebraicReservedNamesRecord = {
8288
8241
  'null': { value: null },
8289
8242
  'def': { value: null, forbidden: true },
8290
8243
  'defs': { value: null, forbidden: true },
8291
- 'let': { value: null, forbidden: true },
8292
8244
  'if-let': { value: null, forbidden: true },
8293
8245
  'when-let': { value: null, forbidden: true },
8294
8246
  'when-first': { value: null, forbidden: true },