@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.
@@ -415,6 +415,12 @@ function isA_SymbolToken(token) {
415
415
  function isA_ReservedSymbolToken(token) {
416
416
  return (token === null || token === void 0 ? void 0 : token[0]) === 'A_ReservedSymbol';
417
417
  }
418
+ function isA_CommentToken(token) {
419
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'A_SingleLineComment';
420
+ }
421
+ function isA_MultiLineCommentToken(token) {
422
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'A_MultiLineComment';
423
+ }
418
424
  function isA_OperatorToken(token, operatorName) {
419
425
  if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Operator') {
420
426
  return false;
@@ -3126,7 +3132,7 @@ var mathNormalExpression = {
3126
3132
  },
3127
3133
  };
3128
3134
 
3129
- var version = "2.0.9";
3135
+ var version = "2.0.11";
3130
3136
 
3131
3137
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3132
3138
  var xyRegexp = /[xy]/g;
@@ -4329,7 +4335,7 @@ var functionalNormalExpression = {
4329
4335
  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);
4330
4336
 
4331
4337
  var andSpecialExpression = {
4332
- parse: function (tokenStream, parseState, firstToken, _a) {
4338
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4333
4339
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4334
4340
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4335
4341
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -4341,6 +4347,7 @@ var andSpecialExpression = {
4341
4347
  };
4342
4348
  return node;
4343
4349
  },
4350
+ validateParameterCount: function () { return undefined; },
4344
4351
  evaluate: function (node, contextStack, _a) {
4345
4352
  var e_1, _b;
4346
4353
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4368,42 +4375,30 @@ var andSpecialExpression = {
4368
4375
  },
4369
4376
  };
4370
4377
 
4371
- var commentSpecialExpression = {
4372
- parse: function (tokenStream, parseState, firstToken, _a) {
4373
- var parseToken = _a.parseToken;
4374
- var node = {
4375
- t: AstNodeType.SpecialExpression,
4376
- n: 'comment',
4377
- p: [],
4378
- token: undefined,
4379
- };
4380
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4381
- while (!isRParenToken(tkn)) {
4382
- node.p.push(parseToken(tokenStream, parseState));
4383
- tkn = asToken(tokenStream.tokens[parseState.position]);
4384
- }
4385
- parseState.position += 1;
4386
- node.token = getTokenDebugData(firstToken) && firstToken;
4387
- return node;
4388
- },
4389
- evaluate: function () { return null; },
4390
- findUnresolvedIdentifiers: function () { return new Set(); },
4391
- };
4392
-
4393
- var condSpecialExpression = {
4394
- parse: function (tokenStream, parseState, firstToken, _a) {
4378
+ function getCommonPolishSpecialExpressionParser(name) {
4379
+ return function (tokenStream, parseState, firstToken, _a) {
4395
4380
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4396
4381
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4397
4382
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4398
- var node = {
4383
+ return {
4399
4384
  t: AstNodeType.SpecialExpression,
4400
- n: 'cond',
4385
+ n: name,
4401
4386
  p: params,
4402
4387
  token: getTokenDebugData(firstToken) && firstToken,
4403
4388
  };
4404
- assertEvenNumberOfParams(node);
4405
- return node;
4406
- },
4389
+ };
4390
+ }
4391
+
4392
+ var commentSpecialExpression = {
4393
+ polishParse: getCommonPolishSpecialExpressionParser('comment'),
4394
+ validateParameterCount: function () { return undefined; },
4395
+ evaluate: function () { return null; },
4396
+ findUnresolvedIdentifiers: function () { return new Set(); },
4397
+ };
4398
+
4399
+ var condSpecialExpression = {
4400
+ polishParse: getCommonPolishSpecialExpressionParser('cond'),
4401
+ validateParameterCount: function (node) { return assertEvenNumberOfParams(node); },
4407
4402
  evaluate: function (node, contextStack, _a) {
4408
4403
  var e_1, _b;
4409
4404
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4432,19 +4427,8 @@ var condSpecialExpression = {
4432
4427
  };
4433
4428
 
4434
4429
  var declaredSpecialExpression = {
4435
- parse: function (tokenStream, parseState, firstToken, _a) {
4436
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4437
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4438
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4439
- var node = {
4440
- t: AstNodeType.SpecialExpression,
4441
- n: 'declared?',
4442
- p: params,
4443
- token: getTokenDebugData(firstToken) && firstToken,
4444
- };
4445
- assertNumberOfParams(1, node);
4446
- return node;
4447
- },
4430
+ polishParse: getCommonPolishSpecialExpressionParser('declared?'),
4431
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
4448
4432
  evaluate: function (node, contextStack) {
4449
4433
  var lookUpResult = contextStack.lookUp(node.p[0]);
4450
4434
  return lookUpResult !== null;
@@ -4477,7 +4461,7 @@ function assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo) {
4477
4461
  }
4478
4462
 
4479
4463
  var defSpecialExpression = {
4480
- parse: function (tokenStream, parseState, firstToken, _a) {
4464
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4481
4465
  var _b;
4482
4466
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4483
4467
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -4489,9 +4473,9 @@ var defSpecialExpression = {
4489
4473
  token: getTokenDebugData(firstToken) && firstToken,
4490
4474
  };
4491
4475
  assertSymbolNode(node.p[0], (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
4492
- assertNumberOfParams(2, node);
4493
4476
  return node;
4494
4477
  },
4478
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4495
4479
  evaluate: function (node, contextStack, _a) {
4496
4480
  var _b;
4497
4481
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4517,7 +4501,7 @@ var defSpecialExpression = {
4517
4501
  };
4518
4502
 
4519
4503
  var defsSpecialExpression = {
4520
- parse: function (tokenStream, parseState, firstToken, _a) {
4504
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4521
4505
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4522
4506
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4523
4507
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -4527,9 +4511,9 @@ var defsSpecialExpression = {
4527
4511
  p: params,
4528
4512
  token: getTokenDebugData(firstToken) && firstToken,
4529
4513
  };
4530
- assertNumberOfParams(2, node);
4531
4514
  return node;
4532
4515
  },
4516
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4533
4517
  evaluate: function (node, contextStack, _a) {
4534
4518
  var _b, _c;
4535
4519
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4557,23 +4541,8 @@ var defsSpecialExpression = {
4557
4541
  };
4558
4542
 
4559
4543
  var doSpecialExpression = {
4560
- parse: function (tokenStream, parseState, firstToken, _a) {
4561
- var parseToken = _a.parseToken;
4562
- var node = {
4563
- t: AstNodeType.SpecialExpression,
4564
- n: 'do',
4565
- p: [],
4566
- token: undefined,
4567
- };
4568
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4569
- while (!isRParenToken(tkn)) {
4570
- node.p.push(parseToken(tokenStream, parseState));
4571
- tkn = asToken(tokenStream.tokens[parseState.position]);
4572
- }
4573
- parseState.position += 1;
4574
- node.token = getTokenDebugData(firstToken) && firstToken;
4575
- return node;
4576
- },
4544
+ polishParse: getCommonPolishSpecialExpressionParser('do'),
4545
+ validateParameterCount: function () { return undefined; },
4577
4546
  evaluate: function (node, contextStack, _a) {
4578
4547
  var e_1, _b;
4579
4548
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4633,7 +4602,7 @@ function combinate(arrays) {
4633
4602
  }
4634
4603
 
4635
4604
  var defnSpecialExpression = {
4636
- parse: function (tokenStream, parseState, firstToken, parsers) {
4605
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4637
4606
  var _a;
4638
4607
  var parseToken = parsers.parseToken;
4639
4608
  var functionName = parseToken(tokenStream, parseState);
@@ -4650,6 +4619,7 @@ var defnSpecialExpression = {
4650
4619
  };
4651
4620
  return node;
4652
4621
  },
4622
+ validateParameterCount: function () { return undefined; },
4653
4623
  evaluate: function (node, contextStack, _a) {
4654
4624
  var _b;
4655
4625
  var _c, _d;
@@ -4676,7 +4646,7 @@ var defnSpecialExpression = {
4676
4646
  },
4677
4647
  };
4678
4648
  var defnsSpecialExpression = {
4679
- parse: function (tokenStream, parseState, firstToken, parsers) {
4649
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4680
4650
  var parseToken = parsers.parseToken;
4681
4651
  var functionName = parseToken(tokenStream, parseState);
4682
4652
  var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
@@ -4691,6 +4661,7 @@ var defnsSpecialExpression = {
4691
4661
  };
4692
4662
  return node;
4693
4663
  },
4664
+ validateParameterCount: function () { return undefined; },
4694
4665
  evaluate: function (node, contextStack, _a) {
4695
4666
  var _b;
4696
4667
  var _c, _d;
@@ -4722,7 +4693,7 @@ var defnsSpecialExpression = {
4722
4693
  },
4723
4694
  };
4724
4695
  var fnSpecialExpression = {
4725
- parse: function (tokenStream, parseState, firstToken, parsers) {
4696
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4726
4697
  var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
4727
4698
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4728
4699
  var node = {
@@ -4734,6 +4705,7 @@ var fnSpecialExpression = {
4734
4705
  };
4735
4706
  return node;
4736
4707
  },
4708
+ validateParameterCount: function () { return undefined; },
4737
4709
  evaluate: function (node, contextStack, _a) {
4738
4710
  var _b;
4739
4711
  var _c;
@@ -4965,19 +4937,8 @@ function parseFunctionArguments(tokenStream, parseState, parsers) {
4965
4937
  }
4966
4938
 
4967
4939
  var ifSpecialExpression = {
4968
- parse: function (tokenStream, parseState, firstToken, _a) {
4969
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4970
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4971
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4972
- var node = {
4973
- t: AstNodeType.SpecialExpression,
4974
- n: 'if',
4975
- p: params,
4976
- token: getTokenDebugData(firstToken) && firstToken,
4977
- };
4978
- assertNumberOfParams({ min: 2, max: 3 }, node);
4979
- return node;
4980
- },
4940
+ polishParse: getCommonPolishSpecialExpressionParser('if'),
4941
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
4981
4942
  evaluate: function (node, contextStack, _a) {
4982
4943
  var _b;
4983
4944
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5000,7 +4961,7 @@ var ifSpecialExpression = {
5000
4961
  };
5001
4962
 
5002
4963
  var ifLetSpecialExpression = {
5003
- parse: function (tokenStream, parseState, firstToken, _a) {
4964
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5004
4965
  var _b, _c;
5005
4966
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5006
4967
  var bindings = parseBindings(tokenStream, parseState);
@@ -5016,9 +4977,9 @@ var ifLetSpecialExpression = {
5016
4977
  p: params,
5017
4978
  token: getTokenDebugData(firstToken) && firstToken,
5018
4979
  };
5019
- assertNumberOfParams({ min: 1, max: 2 }, node);
5020
4980
  return node;
5021
4981
  },
4982
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5022
4983
  evaluate: function (node, contextStack, _a) {
5023
4984
  var _b;
5024
4985
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5048,19 +5009,8 @@ var ifLetSpecialExpression = {
5048
5009
  };
5049
5010
 
5050
5011
  var ifNotSpecialExpression = {
5051
- parse: function (tokenStream, parseState, firstToken, _a) {
5052
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5053
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5054
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5055
- var node = {
5056
- t: AstNodeType.SpecialExpression,
5057
- n: 'if-not',
5058
- p: params,
5059
- token: getTokenDebugData(firstToken) && firstToken,
5060
- };
5061
- assertNumberOfParams({ min: 2, max: 3 }, node);
5062
- return node;
5063
- },
5012
+ polishParse: getCommonPolishSpecialExpressionParser('if-not'),
5013
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5064
5014
  evaluate: function (node, contextStack, _a) {
5065
5015
  var _b;
5066
5016
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5083,7 +5033,7 @@ var ifNotSpecialExpression = {
5083
5033
  };
5084
5034
 
5085
5035
  var letSpecialExpression = {
5086
- parse: function (tokenStream, parseState, firstToken, _a) {
5036
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5087
5037
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5088
5038
  var bindings = parseBindings(tokenStream, parseState);
5089
5039
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5097,6 +5047,7 @@ var letSpecialExpression = {
5097
5047
  };
5098
5048
  return node;
5099
5049
  },
5050
+ validateParameterCount: function () { return undefined; },
5100
5051
  evaluate: function (node, contextStack, _a) {
5101
5052
  var e_1, _b, e_2, _c;
5102
5053
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5154,7 +5105,7 @@ var letSpecialExpression = {
5154
5105
  };
5155
5106
 
5156
5107
  var loopSpecialExpression = {
5157
- parse: function (tokenStream, parseState, firstToken, _a) {
5108
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5158
5109
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket, parseBindings = _a.parseBindings;
5159
5110
  var bindings = parseBindings(tokenStream, parseState);
5160
5111
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5168,6 +5119,7 @@ var loopSpecialExpression = {
5168
5119
  };
5169
5120
  return node;
5170
5121
  },
5122
+ validateParameterCount: function () { return undefined; },
5171
5123
  evaluate: function (node, contextStack, _a) {
5172
5124
  var _b;
5173
5125
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5419,7 +5371,7 @@ function analyze$1(node, contextStack, findUnresolvedIdentifiers, builtin) {
5419
5371
  return result;
5420
5372
  }
5421
5373
  var forSpecialExpression = {
5422
- parse: function (tokenStream, parseState, firstToken, parsers) {
5374
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
5423
5375
  var parseTokensUntilClosingBracket = parsers.parseTokensUntilClosingBracket;
5424
5376
  var loopBindings = parseLoopBindings(tokenStream, parseState, parsers);
5425
5377
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5431,9 +5383,9 @@ var forSpecialExpression = {
5431
5383
  p: params,
5432
5384
  token: getTokenDebugData(firstToken) && firstToken,
5433
5385
  };
5434
- assertNumberOfParams(1, node);
5435
5386
  return node;
5436
5387
  },
5388
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5437
5389
  evaluate: function (node, contextStack, helpers) { return evaluateLoop(true, node, contextStack, helpers.evaluateAstNode); },
5438
5390
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
5439
5391
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
@@ -5441,7 +5393,7 @@ var forSpecialExpression = {
5441
5393
  },
5442
5394
  };
5443
5395
  var doseqSpecialExpression = {
5444
- parse: function (tokenStream, parseState, firstToken, parsers) {
5396
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
5445
5397
  var parseTokensUntilClosingBracket = parsers.parseTokensUntilClosingBracket;
5446
5398
  var loopBindings = parseLoopBindings(tokenStream, parseState, parsers);
5447
5399
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5453,9 +5405,9 @@ var doseqSpecialExpression = {
5453
5405
  p: params,
5454
5406
  token: getTokenDebugData(firstToken) && firstToken,
5455
5407
  };
5456
- assertNumberOfParams(1, node);
5457
5408
  return node;
5458
5409
  },
5410
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5459
5411
  evaluate: function (node, contextStack, helpers) {
5460
5412
  evaluateLoop(false, node, contextStack, helpers.evaluateAstNode);
5461
5413
  return null;
@@ -5467,18 +5419,8 @@ var doseqSpecialExpression = {
5467
5419
  };
5468
5420
 
5469
5421
  var orSpecialExpression = {
5470
- parse: function (tokenStream, parseState, firstToken, _a) {
5471
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5472
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5473
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5474
- var node = {
5475
- t: AstNodeType.SpecialExpression,
5476
- n: 'or',
5477
- p: params,
5478
- token: getTokenDebugData(firstToken) && firstToken,
5479
- };
5480
- return node;
5481
- },
5422
+ polishParse: getCommonPolishSpecialExpressionParser('or'),
5423
+ validateParameterCount: function () { return undefined; },
5482
5424
  evaluate: function (node, contextStack, _a) {
5483
5425
  var e_1, _b;
5484
5426
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5507,19 +5449,8 @@ var orSpecialExpression = {
5507
5449
  };
5508
5450
 
5509
5451
  var qqSpecialExpression = {
5510
- parse: function (tokenStream, parseState, firstToken, _a) {
5511
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5512
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5513
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5514
- var node = {
5515
- t: AstNodeType.SpecialExpression,
5516
- n: '??',
5517
- p: params,
5518
- token: getTokenDebugData(firstToken) && firstToken,
5519
- };
5520
- assertNumberOfParams({ min: 1, max: 2 }, node);
5521
- return node;
5522
- },
5452
+ polishParse: getCommonPolishSpecialExpressionParser('??'),
5453
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5523
5454
  evaluate: function (node, contextStack, _a) {
5524
5455
  var _b;
5525
5456
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5539,7 +5470,7 @@ var qqSpecialExpression = {
5539
5470
  };
5540
5471
 
5541
5472
  var recurSpecialExpression = {
5542
- parse: function (tokenStream, parseState, firstToken, _a) {
5473
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5543
5474
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5544
5475
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5545
5476
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -5551,6 +5482,7 @@ var recurSpecialExpression = {
5551
5482
  };
5552
5483
  return node;
5553
5484
  },
5485
+ validateParameterCount: function () { return undefined; },
5554
5486
  evaluate: function (node, contextStack, _a) {
5555
5487
  var evaluateAstNode = _a.evaluateAstNode;
5556
5488
  var params = node.p.map(function (paramNode) { return evaluateAstNode(paramNode, contextStack); });
@@ -5563,19 +5495,8 @@ var recurSpecialExpression = {
5563
5495
  };
5564
5496
 
5565
5497
  var throwSpecialExpression = {
5566
- parse: function (tokenStream, parseState, firstToken, _a) {
5567
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5568
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5569
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5570
- var node = {
5571
- t: AstNodeType.SpecialExpression,
5572
- n: 'throw',
5573
- p: params,
5574
- token: getTokenDebugData(firstToken) && firstToken,
5575
- };
5576
- assertNumberOfParams(1, node);
5577
- return node;
5578
- },
5498
+ polishParse: getCommonPolishSpecialExpressionParser('throw'),
5499
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5579
5500
  evaluate: function (node, contextStack, _a) {
5580
5501
  var _b, _c;
5581
5502
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5591,19 +5512,8 @@ var throwSpecialExpression = {
5591
5512
  };
5592
5513
 
5593
5514
  var timeSpecialExpression = {
5594
- parse: function (tokenStream, parseState, firstToken, _a) {
5595
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5596
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5597
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5598
- var node = {
5599
- t: AstNodeType.SpecialExpression,
5600
- n: 'time!',
5601
- p: params,
5602
- token: getTokenDebugData(firstToken) && firstToken,
5603
- };
5604
- assertNumberOfParams(1, node);
5605
- return node;
5606
- },
5515
+ polishParse: getCommonPolishSpecialExpressionParser('time!'),
5516
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5607
5517
  evaluate: function (node, contextStack, _a) {
5608
5518
  var evaluateAstNode = _a.evaluateAstNode;
5609
5519
  var param = node.p[0];
@@ -5621,7 +5531,7 @@ var timeSpecialExpression = {
5621
5531
  };
5622
5532
 
5623
5533
  var trySpecialExpression = {
5624
- parse: function (tokenStream, parseState, firstToken, _a) {
5534
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5625
5535
  var _b, _c, _d;
5626
5536
  var parseToken = _a.parseToken;
5627
5537
  var tryExpression = parseToken(tokenStream, parseState);
@@ -5644,9 +5554,9 @@ var trySpecialExpression = {
5644
5554
  e: error,
5645
5555
  token: getTokenDebugData(firstToken) && firstToken,
5646
5556
  };
5647
- assertNumberOfParams(1, node);
5648
5557
  return node;
5649
5558
  },
5559
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5650
5560
  evaluate: function (node, contextStack, _a) {
5651
5561
  var _b;
5652
5562
  var _c;
@@ -5676,19 +5586,8 @@ var trySpecialExpression = {
5676
5586
  };
5677
5587
 
5678
5588
  var whenSpecialExpression = {
5679
- parse: function (tokenStream, parseState, firstToken, _a) {
5680
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5681
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5682
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5683
- var node = {
5684
- t: AstNodeType.SpecialExpression,
5685
- n: 'when',
5686
- p: params,
5687
- token: getTokenDebugData(firstToken) && firstToken,
5688
- };
5689
- assertNumberOfParams({ min: 1 }, node);
5690
- return node;
5691
- },
5589
+ polishParse: getCommonPolishSpecialExpressionParser('when'),
5590
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5692
5591
  evaluate: function (node, contextStack, _a) {
5693
5592
  var e_1, _b;
5694
5593
  var _c;
@@ -5720,7 +5619,7 @@ var whenSpecialExpression = {
5720
5619
  };
5721
5620
 
5722
5621
  var whenFirstSpecialExpression = {
5723
- parse: function (tokenStream, parseState, firstToken, _a) {
5622
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5724
5623
  var _b, _c;
5725
5624
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5726
5625
  var bindings = parseBindings(tokenStream, parseState);
@@ -5738,6 +5637,7 @@ var whenFirstSpecialExpression = {
5738
5637
  };
5739
5638
  return node;
5740
5639
  },
5640
+ validateParameterCount: function () { return undefined; },
5741
5641
  evaluate: function (node, contextStack, _a) {
5742
5642
  var e_1, _b;
5743
5643
  var _c;
@@ -5781,7 +5681,7 @@ var whenFirstSpecialExpression = {
5781
5681
  };
5782
5682
 
5783
5683
  var whenLetSpecialExpression = {
5784
- parse: function (tokenStream, parseState, firstToken, _a) {
5684
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5785
5685
  var _b, _c;
5786
5686
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5787
5687
  var bindings = parseBindings(tokenStream, parseState);
@@ -5799,6 +5699,7 @@ var whenLetSpecialExpression = {
5799
5699
  };
5800
5700
  return node;
5801
5701
  },
5702
+ validateParameterCount: function () { return undefined; },
5802
5703
  evaluate: function (node, contextStack, _a) {
5803
5704
  var e_1, _b;
5804
5705
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5837,19 +5738,8 @@ var whenLetSpecialExpression = {
5837
5738
  };
5838
5739
 
5839
5740
  var whenNotSpecialExpression = {
5840
- parse: function (tokenStream, parseState, firstToken, _a) {
5841
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5842
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5843
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5844
- var node = {
5845
- t: AstNodeType.SpecialExpression,
5846
- n: 'when-not',
5847
- p: params,
5848
- token: getTokenDebugData(firstToken) && firstToken,
5849
- };
5850
- assertNumberOfParams({ min: 1 }, node);
5851
- return node;
5852
- },
5741
+ polishParse: getCommonPolishSpecialExpressionParser('when-not'),
5742
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5853
5743
  evaluate: function (node, contextStack, _a) {
5854
5744
  var e_1, _b;
5855
5745
  var _c;
@@ -7449,7 +7339,7 @@ var AlgebraicParser = /** @class */ (function () {
7449
7339
  };
7450
7340
  };
7451
7341
  AlgebraicParser.prototype.parseFunctionCall = function (symbol) {
7452
- var _a, _b;
7342
+ var _a, _b, _c;
7453
7343
  var params = [];
7454
7344
  this.advance();
7455
7345
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
@@ -7481,16 +7371,21 @@ var AlgebraicParser = /** @class */ (function () {
7481
7371
  case 'when':
7482
7372
  case 'when-not':
7483
7373
  case 'do':
7484
- case 'throw':
7485
- return {
7374
+ case 'time!':
7375
+ case 'throw': {
7376
+ var node_1 = {
7486
7377
  t: AstNodeType.SpecialExpression,
7487
7378
  n: name_1,
7488
7379
  p: params,
7489
7380
  token: getTokenDebugData(symbol.token) && symbol.token,
7490
7381
  };
7382
+ builtin.specialExpressions[node_1.n].validateParameterCount(node_1);
7383
+ return node_1;
7384
+ }
7385
+ case 'let':
7386
+ return this.parseLet(symbol, params);
7491
7387
  case 'def':
7492
7388
  case 'defs':
7493
- case 'let':
7494
7389
  case 'if-let':
7495
7390
  case 'when-let':
7496
7391
  case 'when-first':
@@ -7500,7 +7395,6 @@ var AlgebraicParser = /** @class */ (function () {
7500
7395
  case 'try':
7501
7396
  case 'recur':
7502
7397
  case 'loop':
7503
- case 'time!':
7504
7398
  case 'doseq':
7505
7399
  case 'for':
7506
7400
  throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
@@ -7508,7 +7402,12 @@ var AlgebraicParser = /** @class */ (function () {
7508
7402
  throw new Error("Unknown special expression: ".concat(name_1));
7509
7403
  }
7510
7404
  }
7511
- return createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7405
+ var node = createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7406
+ var builtinExpression = builtin.normalExpressions[node.n];
7407
+ if (builtinExpression) {
7408
+ (_c = builtinExpression.validate) === null || _c === void 0 ? void 0 : _c.call(builtinExpression, __assign(__assign({}, node), { p: withoutCommentNodes(node.p) }));
7409
+ }
7410
+ return node;
7512
7411
  }
7513
7412
  else {
7514
7413
  return {
@@ -7520,31 +7419,40 @@ var AlgebraicParser = /** @class */ (function () {
7520
7419
  }
7521
7420
  };
7522
7421
  AlgebraicParser.prototype.parseLambdaFunction = function () {
7523
- var _a;
7422
+ var _a, _b;
7524
7423
  var firstToken = this.peek();
7525
7424
  this.advance();
7526
- var spread = false;
7425
+ var rest = false;
7426
+ var letBindingObject;
7527
7427
  var args = [];
7528
7428
  var restArg;
7529
7429
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
7530
- if (isA_OperatorToken(this.peek(), '...')) {
7531
- if (spread) {
7532
- throw new LitsError('Multiple spread operators in lambda function', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7533
- }
7534
- this.advance();
7535
- spread = true;
7536
- }
7537
- var symbolToken = this.peek();
7538
- if (!isA_SymbolToken(symbolToken)) {
7539
- return null;
7430
+ if (letBindingObject) {
7431
+ throw new LitsError('Expected right parentheses', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7540
7432
  }
7541
- if (spread) {
7542
- restArg = symbolToken[1];
7433
+ if (isLBraceToken(this.peek())) {
7434
+ letBindingObject = this.parseObject();
7543
7435
  }
7544
7436
  else {
7545
- args.push(symbolToken[1]);
7437
+ if (isA_OperatorToken(this.peek(), '...')) {
7438
+ if (rest) {
7439
+ throw new LitsError('Multiple spread operators in lambda function', (_b = getTokenDebugData(this.peek())) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7440
+ }
7441
+ this.advance();
7442
+ rest = true;
7443
+ }
7444
+ var symbolToken = this.peek();
7445
+ if (!isA_SymbolToken(symbolToken)) {
7446
+ return null;
7447
+ }
7448
+ if (rest) {
7449
+ restArg = symbolToken[1];
7450
+ }
7451
+ else {
7452
+ args.push(symbolToken[1]);
7453
+ }
7454
+ this.advance();
7546
7455
  }
7547
- this.advance();
7548
7456
  if (!isA_OperatorToken(this.peek(), ',') && !isRParenToken(this.peek())) {
7549
7457
  return null;
7550
7458
  }
@@ -7560,6 +7468,7 @@ var AlgebraicParser = /** @class */ (function () {
7560
7468
  return null;
7561
7469
  }
7562
7470
  this.advance();
7471
+ var letBindings = letBindingObject ? arrayToPairs(letBindingObject.p) : [];
7563
7472
  var body = this.parseExpression();
7564
7473
  var arity = restArg !== undefined ? { min: args.length } : args.length;
7565
7474
  return {
@@ -7570,7 +7479,17 @@ var AlgebraicParser = /** @class */ (function () {
7570
7479
  as: {
7571
7480
  m: args,
7572
7481
  r: restArg,
7573
- b: [],
7482
+ b: letBindings.map(function (pair) {
7483
+ var key = pair[0];
7484
+ var value = pair[1];
7485
+ return {
7486
+ t: AstNodeType.Binding,
7487
+ n: key.v,
7488
+ v: value,
7489
+ p: [],
7490
+ token: getTokenDebugData(key.token) && key.token,
7491
+ };
7492
+ }),
7574
7493
  },
7575
7494
  b: [body],
7576
7495
  a: arity,
@@ -7634,6 +7553,35 @@ var AlgebraicParser = /** @class */ (function () {
7634
7553
  };
7635
7554
  return node;
7636
7555
  };
7556
+ AlgebraicParser.prototype.parseLet = function (nameSymbol, params) {
7557
+ var _a, _b;
7558
+ if (params.length !== 2) {
7559
+ throw new LitsError('let expects two arguments', (_a = getTokenDebugData(nameSymbol.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7560
+ }
7561
+ var letObject = params[0];
7562
+ if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
7563
+ throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7564
+ }
7565
+ var letBindings = arrayToPairs(letObject.p);
7566
+ var expression = params[1];
7567
+ return {
7568
+ t: AstNodeType.SpecialExpression,
7569
+ n: 'let',
7570
+ p: [expression],
7571
+ token: getTokenDebugData(nameSymbol.token) && nameSymbol.token,
7572
+ bs: letBindings.map(function (pair) {
7573
+ var key = pair[0];
7574
+ var value = pair[1];
7575
+ return {
7576
+ t: AstNodeType.Binding,
7577
+ n: key.v,
7578
+ v: value,
7579
+ p: [],
7580
+ token: getTokenDebugData(key.token) && key.token,
7581
+ };
7582
+ }),
7583
+ };
7584
+ };
7637
7585
  AlgebraicParser.prototype.isAtEnd = function () {
7638
7586
  return this.parseState.position >= this.tokenStream.tokens.length;
7639
7587
  };
@@ -7877,7 +7825,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7877
7825
  var firstToken = asLParenToken(tokenStream.tokens[parseState.position++]);
7878
7826
  var nameToken = asP_SymbolToken(tokenStream.tokens[parseState.position++]);
7879
7827
  var expressionName = nameToken[1];
7880
- var parse = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo).parse;
7828
+ var _b = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo), parse = _b.polishParse, validateParameterCount = _b.validateParameterCount;
7881
7829
  var node = parse(tokenStream, parseState, firstToken, {
7882
7830
  parseExpression: parseExpression,
7883
7831
  parseTokensUntilClosingBracket: parseTokensUntilClosingBracket,
@@ -7886,6 +7834,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7886
7834
  parseBindings: parseBindings,
7887
7835
  parseArgument: parseArgument,
7888
7836
  });
7837
+ validateParameterCount(node);
7889
7838
  return node;
7890
7839
  }
7891
7840
  function parsePolishToken(tokenStream, parseState) {
@@ -7975,7 +7924,11 @@ function parse(tokenStream) {
7975
7924
  }
7976
7925
  function removeUnnecessaryTokens(tokenStream) {
7977
7926
  var tokens = tokenStream.tokens.filter(function (token) {
7978
- if (isP_CommentToken(token) || isA_WhitespaceToken(token) || isP_WhitespaceToken(token)) {
7927
+ if (isP_CommentToken(token)
7928
+ || isA_CommentToken(token)
7929
+ || isA_MultiLineCommentToken(token)
7930
+ || isA_WhitespaceToken(token)
7931
+ || isP_WhitespaceToken(token)) {
7979
7932
  return false;
7980
7933
  }
7981
7934
  return true;
@@ -8290,7 +8243,6 @@ var algebraicReservedNamesRecord = {
8290
8243
  'null': { value: null },
8291
8244
  'def': { value: null, forbidden: true },
8292
8245
  'defs': { value: null, forbidden: true },
8293
- 'let': { value: null, forbidden: true },
8294
8246
  'if-let': { value: null, forbidden: true },
8295
8247
  'when-let': { value: null, forbidden: true },
8296
8248
  'when-first': { value: null, forbidden: true },