@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.
package/dist/cli/cli.js CHANGED
@@ -92,7 +92,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
92
92
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
93
93
  };
94
94
 
95
- var version = "2.0.9";
95
+ var version = "2.0.11";
96
96
 
97
97
  var AstNodeType;
98
98
  (function (AstNodeType) {
@@ -420,6 +420,12 @@ function isA_SymbolToken(token) {
420
420
  function isA_ReservedSymbolToken(token) {
421
421
  return (token === null || token === void 0 ? void 0 : token[0]) === 'A_ReservedSymbol';
422
422
  }
423
+ function isA_CommentToken(token) {
424
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'A_SingleLineComment';
425
+ }
426
+ function isA_MultiLineCommentToken(token) {
427
+ return (token === null || token === void 0 ? void 0 : token[0]) === 'A_MultiLineComment';
428
+ }
423
429
  function isA_OperatorToken(token, operatorName) {
424
430
  if ((token === null || token === void 0 ? void 0 : token[0]) !== 'A_Operator') {
425
431
  return false;
@@ -4332,7 +4338,7 @@ var functionalNormalExpression = {
4332
4338
  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);
4333
4339
 
4334
4340
  var andSpecialExpression = {
4335
- parse: function (tokenStream, parseState, firstToken, _a) {
4341
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4336
4342
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4337
4343
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4338
4344
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -4344,6 +4350,7 @@ var andSpecialExpression = {
4344
4350
  };
4345
4351
  return node;
4346
4352
  },
4353
+ validateParameterCount: function () { return undefined; },
4347
4354
  evaluate: function (node, contextStack, _a) {
4348
4355
  var e_1, _b;
4349
4356
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4371,42 +4378,30 @@ var andSpecialExpression = {
4371
4378
  },
4372
4379
  };
4373
4380
 
4374
- var commentSpecialExpression = {
4375
- parse: function (tokenStream, parseState, firstToken, _a) {
4376
- var parseToken = _a.parseToken;
4377
- var node = {
4378
- t: AstNodeType.SpecialExpression,
4379
- n: 'comment',
4380
- p: [],
4381
- token: undefined,
4382
- };
4383
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4384
- while (!isRParenToken(tkn)) {
4385
- node.p.push(parseToken(tokenStream, parseState));
4386
- tkn = asToken(tokenStream.tokens[parseState.position]);
4387
- }
4388
- parseState.position += 1;
4389
- node.token = getTokenDebugData(firstToken) && firstToken;
4390
- return node;
4391
- },
4392
- evaluate: function () { return null; },
4393
- findUnresolvedIdentifiers: function () { return new Set(); },
4394
- };
4395
-
4396
- var condSpecialExpression = {
4397
- parse: function (tokenStream, parseState, firstToken, _a) {
4381
+ function getCommonPolishSpecialExpressionParser(name) {
4382
+ return function (tokenStream, parseState, firstToken, _a) {
4398
4383
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4399
4384
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4400
4385
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4401
- var node = {
4386
+ return {
4402
4387
  t: AstNodeType.SpecialExpression,
4403
- n: 'cond',
4388
+ n: name,
4404
4389
  p: params,
4405
4390
  token: getTokenDebugData(firstToken) && firstToken,
4406
4391
  };
4407
- assertEvenNumberOfParams(node);
4408
- return node;
4409
- },
4392
+ };
4393
+ }
4394
+
4395
+ var commentSpecialExpression = {
4396
+ polishParse: getCommonPolishSpecialExpressionParser('comment'),
4397
+ validateParameterCount: function () { return undefined; },
4398
+ evaluate: function () { return null; },
4399
+ findUnresolvedIdentifiers: function () { return new Set(); },
4400
+ };
4401
+
4402
+ var condSpecialExpression = {
4403
+ polishParse: getCommonPolishSpecialExpressionParser('cond'),
4404
+ validateParameterCount: function (node) { return assertEvenNumberOfParams(node); },
4410
4405
  evaluate: function (node, contextStack, _a) {
4411
4406
  var e_1, _b;
4412
4407
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4435,19 +4430,8 @@ var condSpecialExpression = {
4435
4430
  };
4436
4431
 
4437
4432
  var declaredSpecialExpression = {
4438
- parse: function (tokenStream, parseState, firstToken, _a) {
4439
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4440
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4441
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4442
- var node = {
4443
- t: AstNodeType.SpecialExpression,
4444
- n: 'declared?',
4445
- p: params,
4446
- token: getTokenDebugData(firstToken) && firstToken,
4447
- };
4448
- assertNumberOfParams(1, node);
4449
- return node;
4450
- },
4433
+ polishParse: getCommonPolishSpecialExpressionParser('declared?'),
4434
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
4451
4435
  evaluate: function (node, contextStack) {
4452
4436
  var lookUpResult = contextStack.lookUp(node.p[0]);
4453
4437
  return lookUpResult !== null;
@@ -4481,7 +4465,7 @@ function assertNameNotDefined(name, contextStack, builtin, sourceCodeInfo) {
4481
4465
  }
4482
4466
 
4483
4467
  var defSpecialExpression = {
4484
- parse: function (tokenStream, parseState, firstToken, _a) {
4468
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4485
4469
  var _b;
4486
4470
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4487
4471
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -4493,9 +4477,9 @@ var defSpecialExpression = {
4493
4477
  token: getTokenDebugData(firstToken) && firstToken,
4494
4478
  };
4495
4479
  assertSymbolNode(node.p[0], (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
4496
- assertNumberOfParams(2, node);
4497
4480
  return node;
4498
4481
  },
4482
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4499
4483
  evaluate: function (node, contextStack, _a) {
4500
4484
  var _b;
4501
4485
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4521,7 +4505,7 @@ var defSpecialExpression = {
4521
4505
  };
4522
4506
 
4523
4507
  var defsSpecialExpression = {
4524
- parse: function (tokenStream, parseState, firstToken, _a) {
4508
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
4525
4509
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4526
4510
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4527
4511
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -4531,9 +4515,9 @@ var defsSpecialExpression = {
4531
4515
  p: params,
4532
4516
  token: getTokenDebugData(firstToken) && firstToken,
4533
4517
  };
4534
- assertNumberOfParams(2, node);
4535
4518
  return node;
4536
4519
  },
4520
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4537
4521
  evaluate: function (node, contextStack, _a) {
4538
4522
  var _b, _c;
4539
4523
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4561,23 +4545,8 @@ var defsSpecialExpression = {
4561
4545
  };
4562
4546
 
4563
4547
  var doSpecialExpression = {
4564
- parse: function (tokenStream, parseState, firstToken, _a) {
4565
- var parseToken = _a.parseToken;
4566
- var node = {
4567
- t: AstNodeType.SpecialExpression,
4568
- n: 'do',
4569
- p: [],
4570
- token: undefined,
4571
- };
4572
- var tkn = asToken(tokenStream.tokens[parseState.position]);
4573
- while (!isRParenToken(tkn)) {
4574
- node.p.push(parseToken(tokenStream, parseState));
4575
- tkn = asToken(tokenStream.tokens[parseState.position]);
4576
- }
4577
- parseState.position += 1;
4578
- node.token = getTokenDebugData(firstToken) && firstToken;
4579
- return node;
4580
- },
4548
+ polishParse: getCommonPolishSpecialExpressionParser('do'),
4549
+ validateParameterCount: function () { return undefined; },
4581
4550
  evaluate: function (node, contextStack, _a) {
4582
4551
  var e_1, _b;
4583
4552
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4637,7 +4606,7 @@ function combinate(arrays) {
4637
4606
  }
4638
4607
 
4639
4608
  var defnSpecialExpression = {
4640
- parse: function (tokenStream, parseState, firstToken, parsers) {
4609
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4641
4610
  var _a;
4642
4611
  var parseToken = parsers.parseToken;
4643
4612
  var functionName = parseToken(tokenStream, parseState);
@@ -4654,6 +4623,7 @@ var defnSpecialExpression = {
4654
4623
  };
4655
4624
  return node;
4656
4625
  },
4626
+ validateParameterCount: function () { return undefined; },
4657
4627
  evaluate: function (node, contextStack, _a) {
4658
4628
  var _b;
4659
4629
  var _c, _d;
@@ -4680,7 +4650,7 @@ var defnSpecialExpression = {
4680
4650
  },
4681
4651
  };
4682
4652
  var defnsSpecialExpression = {
4683
- parse: function (tokenStream, parseState, firstToken, parsers) {
4653
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4684
4654
  var parseToken = parsers.parseToken;
4685
4655
  var functionName = parseToken(tokenStream, parseState);
4686
4656
  var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
@@ -4695,6 +4665,7 @@ var defnsSpecialExpression = {
4695
4665
  };
4696
4666
  return node;
4697
4667
  },
4668
+ validateParameterCount: function () { return undefined; },
4698
4669
  evaluate: function (node, contextStack, _a) {
4699
4670
  var _b;
4700
4671
  var _c, _d;
@@ -4726,7 +4697,7 @@ var defnsSpecialExpression = {
4726
4697
  },
4727
4698
  };
4728
4699
  var fnSpecialExpression = {
4729
- parse: function (tokenStream, parseState, firstToken, parsers) {
4700
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
4730
4701
  var functionOverloades = parseFunctionOverloades(tokenStream, parseState, parsers);
4731
4702
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4732
4703
  var node = {
@@ -4738,6 +4709,7 @@ var fnSpecialExpression = {
4738
4709
  };
4739
4710
  return node;
4740
4711
  },
4712
+ validateParameterCount: function () { return undefined; },
4741
4713
  evaluate: function (node, contextStack, _a) {
4742
4714
  var _b;
4743
4715
  var _c;
@@ -4969,19 +4941,8 @@ function parseFunctionArguments(tokenStream, parseState, parsers) {
4969
4941
  }
4970
4942
 
4971
4943
  var ifSpecialExpression = {
4972
- parse: function (tokenStream, parseState, firstToken, _a) {
4973
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4974
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4975
- assertRParenToken(tokenStream.tokens[parseState.position++]);
4976
- var node = {
4977
- t: AstNodeType.SpecialExpression,
4978
- n: 'if',
4979
- p: params,
4980
- token: getTokenDebugData(firstToken) && firstToken,
4981
- };
4982
- assertNumberOfParams({ min: 2, max: 3 }, node);
4983
- return node;
4984
- },
4944
+ polishParse: getCommonPolishSpecialExpressionParser('if'),
4945
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
4985
4946
  evaluate: function (node, contextStack, _a) {
4986
4947
  var _b;
4987
4948
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5004,7 +4965,7 @@ var ifSpecialExpression = {
5004
4965
  };
5005
4966
 
5006
4967
  var ifLetSpecialExpression = {
5007
- parse: function (tokenStream, parseState, firstToken, _a) {
4968
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5008
4969
  var _b, _c;
5009
4970
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5010
4971
  var bindings = parseBindings(tokenStream, parseState);
@@ -5020,9 +4981,9 @@ var ifLetSpecialExpression = {
5020
4981
  p: params,
5021
4982
  token: getTokenDebugData(firstToken) && firstToken,
5022
4983
  };
5023
- assertNumberOfParams({ min: 1, max: 2 }, node);
5024
4984
  return node;
5025
4985
  },
4986
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5026
4987
  evaluate: function (node, contextStack, _a) {
5027
4988
  var _b;
5028
4989
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5052,19 +5013,8 @@ var ifLetSpecialExpression = {
5052
5013
  };
5053
5014
 
5054
5015
  var ifNotSpecialExpression = {
5055
- parse: function (tokenStream, parseState, firstToken, _a) {
5056
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5057
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5058
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5059
- var node = {
5060
- t: AstNodeType.SpecialExpression,
5061
- n: 'if-not',
5062
- p: params,
5063
- token: getTokenDebugData(firstToken) && firstToken,
5064
- };
5065
- assertNumberOfParams({ min: 2, max: 3 }, node);
5066
- return node;
5067
- },
5016
+ polishParse: getCommonPolishSpecialExpressionParser('if-not'),
5017
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5068
5018
  evaluate: function (node, contextStack, _a) {
5069
5019
  var _b;
5070
5020
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5087,7 +5037,7 @@ var ifNotSpecialExpression = {
5087
5037
  };
5088
5038
 
5089
5039
  var letSpecialExpression = {
5090
- parse: function (tokenStream, parseState, firstToken, _a) {
5040
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5091
5041
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5092
5042
  var bindings = parseBindings(tokenStream, parseState);
5093
5043
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5101,6 +5051,7 @@ var letSpecialExpression = {
5101
5051
  };
5102
5052
  return node;
5103
5053
  },
5054
+ validateParameterCount: function () { return undefined; },
5104
5055
  evaluate: function (node, contextStack, _a) {
5105
5056
  var e_1, _b, e_2, _c;
5106
5057
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5158,7 +5109,7 @@ var letSpecialExpression = {
5158
5109
  };
5159
5110
 
5160
5111
  var loopSpecialExpression = {
5161
- parse: function (tokenStream, parseState, firstToken, _a) {
5112
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5162
5113
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket, parseBindings = _a.parseBindings;
5163
5114
  var bindings = parseBindings(tokenStream, parseState);
5164
5115
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5172,6 +5123,7 @@ var loopSpecialExpression = {
5172
5123
  };
5173
5124
  return node;
5174
5125
  },
5126
+ validateParameterCount: function () { return undefined; },
5175
5127
  evaluate: function (node, contextStack, _a) {
5176
5128
  var _b;
5177
5129
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5423,7 +5375,7 @@ function analyze$1(node, contextStack, findUnresolvedIdentifiers, builtin) {
5423
5375
  return result;
5424
5376
  }
5425
5377
  var forSpecialExpression = {
5426
- parse: function (tokenStream, parseState, firstToken, parsers) {
5378
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
5427
5379
  var parseTokensUntilClosingBracket = parsers.parseTokensUntilClosingBracket;
5428
5380
  var loopBindings = parseLoopBindings(tokenStream, parseState, parsers);
5429
5381
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5435,9 +5387,9 @@ var forSpecialExpression = {
5435
5387
  p: params,
5436
5388
  token: getTokenDebugData(firstToken) && firstToken,
5437
5389
  };
5438
- assertNumberOfParams(1, node);
5439
5390
  return node;
5440
5391
  },
5392
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5441
5393
  evaluate: function (node, contextStack, helpers) { return evaluateLoop(true, node, contextStack, helpers.evaluateAstNode); },
5442
5394
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
5443
5395
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
@@ -5445,7 +5397,7 @@ var forSpecialExpression = {
5445
5397
  },
5446
5398
  };
5447
5399
  var doseqSpecialExpression = {
5448
- parse: function (tokenStream, parseState, firstToken, parsers) {
5400
+ polishParse: function (tokenStream, parseState, firstToken, parsers) {
5449
5401
  var parseTokensUntilClosingBracket = parsers.parseTokensUntilClosingBracket;
5450
5402
  var loopBindings = parseLoopBindings(tokenStream, parseState, parsers);
5451
5403
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
@@ -5457,9 +5409,9 @@ var doseqSpecialExpression = {
5457
5409
  p: params,
5458
5410
  token: getTokenDebugData(firstToken) && firstToken,
5459
5411
  };
5460
- assertNumberOfParams(1, node);
5461
5412
  return node;
5462
5413
  },
5414
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5463
5415
  evaluate: function (node, contextStack, helpers) {
5464
5416
  evaluateLoop(false, node, contextStack, helpers.evaluateAstNode);
5465
5417
  return null;
@@ -5471,18 +5423,8 @@ var doseqSpecialExpression = {
5471
5423
  };
5472
5424
 
5473
5425
  var orSpecialExpression = {
5474
- parse: function (tokenStream, parseState, firstToken, _a) {
5475
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5476
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5477
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5478
- var node = {
5479
- t: AstNodeType.SpecialExpression,
5480
- n: 'or',
5481
- p: params,
5482
- token: getTokenDebugData(firstToken) && firstToken,
5483
- };
5484
- return node;
5485
- },
5426
+ polishParse: getCommonPolishSpecialExpressionParser('or'),
5427
+ validateParameterCount: function () { return undefined; },
5486
5428
  evaluate: function (node, contextStack, _a) {
5487
5429
  var e_1, _b;
5488
5430
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5511,19 +5453,8 @@ var orSpecialExpression = {
5511
5453
  };
5512
5454
 
5513
5455
  var qqSpecialExpression = {
5514
- parse: function (tokenStream, parseState, firstToken, _a) {
5515
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5516
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5517
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5518
- var node = {
5519
- t: AstNodeType.SpecialExpression,
5520
- n: '??',
5521
- p: params,
5522
- token: getTokenDebugData(firstToken) && firstToken,
5523
- };
5524
- assertNumberOfParams({ min: 1, max: 2 }, node);
5525
- return node;
5526
- },
5456
+ polishParse: getCommonPolishSpecialExpressionParser('??'),
5457
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5527
5458
  evaluate: function (node, contextStack, _a) {
5528
5459
  var _b;
5529
5460
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5543,7 +5474,7 @@ var qqSpecialExpression = {
5543
5474
  };
5544
5475
 
5545
5476
  var recurSpecialExpression = {
5546
- parse: function (tokenStream, parseState, firstToken, _a) {
5477
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5547
5478
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5548
5479
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5549
5480
  assertRParenToken(tokenStream.tokens[parseState.position++]);
@@ -5555,6 +5486,7 @@ var recurSpecialExpression = {
5555
5486
  };
5556
5487
  return node;
5557
5488
  },
5489
+ validateParameterCount: function () { return undefined; },
5558
5490
  evaluate: function (node, contextStack, _a) {
5559
5491
  var evaluateAstNode = _a.evaluateAstNode;
5560
5492
  var params = node.p.map(function (paramNode) { return evaluateAstNode(paramNode, contextStack); });
@@ -5567,19 +5499,8 @@ var recurSpecialExpression = {
5567
5499
  };
5568
5500
 
5569
5501
  var throwSpecialExpression = {
5570
- parse: function (tokenStream, parseState, firstToken, _a) {
5571
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5572
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5573
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5574
- var node = {
5575
- t: AstNodeType.SpecialExpression,
5576
- n: 'throw',
5577
- p: params,
5578
- token: getTokenDebugData(firstToken) && firstToken,
5579
- };
5580
- assertNumberOfParams(1, node);
5581
- return node;
5582
- },
5502
+ polishParse: getCommonPolishSpecialExpressionParser('throw'),
5503
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5583
5504
  evaluate: function (node, contextStack, _a) {
5584
5505
  var _b, _c;
5585
5506
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5595,19 +5516,8 @@ var throwSpecialExpression = {
5595
5516
  };
5596
5517
 
5597
5518
  var timeSpecialExpression = {
5598
- parse: function (tokenStream, parseState, firstToken, _a) {
5599
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5600
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5601
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5602
- var node = {
5603
- t: AstNodeType.SpecialExpression,
5604
- n: 'time!',
5605
- p: params,
5606
- token: getTokenDebugData(firstToken) && firstToken,
5607
- };
5608
- assertNumberOfParams(1, node);
5609
- return node;
5610
- },
5519
+ polishParse: getCommonPolishSpecialExpressionParser('time!'),
5520
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5611
5521
  evaluate: function (node, contextStack, _a) {
5612
5522
  var evaluateAstNode = _a.evaluateAstNode;
5613
5523
  var param = node.p[0];
@@ -5625,7 +5535,7 @@ var timeSpecialExpression = {
5625
5535
  };
5626
5536
 
5627
5537
  var trySpecialExpression = {
5628
- parse: function (tokenStream, parseState, firstToken, _a) {
5538
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5629
5539
  var _b, _c, _d;
5630
5540
  var parseToken = _a.parseToken;
5631
5541
  var tryExpression = parseToken(tokenStream, parseState);
@@ -5648,9 +5558,9 @@ var trySpecialExpression = {
5648
5558
  e: error,
5649
5559
  token: getTokenDebugData(firstToken) && firstToken,
5650
5560
  };
5651
- assertNumberOfParams(1, node);
5652
5561
  return node;
5653
5562
  },
5563
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5654
5564
  evaluate: function (node, contextStack, _a) {
5655
5565
  var _b;
5656
5566
  var _c;
@@ -5680,19 +5590,8 @@ var trySpecialExpression = {
5680
5590
  };
5681
5591
 
5682
5592
  var whenSpecialExpression = {
5683
- parse: function (tokenStream, parseState, firstToken, _a) {
5684
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5685
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5686
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5687
- var node = {
5688
- t: AstNodeType.SpecialExpression,
5689
- n: 'when',
5690
- p: params,
5691
- token: getTokenDebugData(firstToken) && firstToken,
5692
- };
5693
- assertNumberOfParams({ min: 1 }, node);
5694
- return node;
5695
- },
5593
+ polishParse: getCommonPolishSpecialExpressionParser('when'),
5594
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5696
5595
  evaluate: function (node, contextStack, _a) {
5697
5596
  var e_1, _b;
5698
5597
  var _c;
@@ -5724,7 +5623,7 @@ var whenSpecialExpression = {
5724
5623
  };
5725
5624
 
5726
5625
  var whenFirstSpecialExpression = {
5727
- parse: function (tokenStream, parseState, firstToken, _a) {
5626
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5728
5627
  var _b, _c;
5729
5628
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5730
5629
  var bindings = parseBindings(tokenStream, parseState);
@@ -5742,6 +5641,7 @@ var whenFirstSpecialExpression = {
5742
5641
  };
5743
5642
  return node;
5744
5643
  },
5644
+ validateParameterCount: function () { return undefined; },
5745
5645
  evaluate: function (node, contextStack, _a) {
5746
5646
  var e_1, _b;
5747
5647
  var _c;
@@ -5785,7 +5685,7 @@ var whenFirstSpecialExpression = {
5785
5685
  };
5786
5686
 
5787
5687
  var whenLetSpecialExpression = {
5788
- parse: function (tokenStream, parseState, firstToken, _a) {
5688
+ polishParse: function (tokenStream, parseState, firstToken, _a) {
5789
5689
  var _b, _c;
5790
5690
  var parseBindings = _a.parseBindings, parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5791
5691
  var bindings = parseBindings(tokenStream, parseState);
@@ -5803,6 +5703,7 @@ var whenLetSpecialExpression = {
5803
5703
  };
5804
5704
  return node;
5805
5705
  },
5706
+ validateParameterCount: function () { return undefined; },
5806
5707
  evaluate: function (node, contextStack, _a) {
5807
5708
  var e_1, _b;
5808
5709
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5841,19 +5742,8 @@ var whenLetSpecialExpression = {
5841
5742
  };
5842
5743
 
5843
5744
  var whenNotSpecialExpression = {
5844
- parse: function (tokenStream, parseState, firstToken, _a) {
5845
- var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
5846
- var params = parseTokensUntilClosingBracket(tokenStream, parseState);
5847
- assertRParenToken(tokenStream.tokens[parseState.position++]);
5848
- var node = {
5849
- t: AstNodeType.SpecialExpression,
5850
- n: 'when-not',
5851
- p: params,
5852
- token: getTokenDebugData(firstToken) && firstToken,
5853
- };
5854
- assertNumberOfParams({ min: 1 }, node);
5855
- return node;
5856
- },
5745
+ polishParse: getCommonPolishSpecialExpressionParser('when-not'),
5746
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5857
5747
  evaluate: function (node, contextStack, _a) {
5858
5748
  var e_1, _b;
5859
5749
  var _c;
@@ -7453,7 +7343,7 @@ var AlgebraicParser = /** @class */ (function () {
7453
7343
  };
7454
7344
  };
7455
7345
  AlgebraicParser.prototype.parseFunctionCall = function (symbol) {
7456
- var _a, _b;
7346
+ var _a, _b, _c;
7457
7347
  var params = [];
7458
7348
  this.advance();
7459
7349
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
@@ -7485,16 +7375,21 @@ var AlgebraicParser = /** @class */ (function () {
7485
7375
  case 'when':
7486
7376
  case 'when-not':
7487
7377
  case 'do':
7488
- case 'throw':
7489
- return {
7378
+ case 'time!':
7379
+ case 'throw': {
7380
+ var node_1 = {
7490
7381
  t: AstNodeType.SpecialExpression,
7491
7382
  n: name_1,
7492
7383
  p: params,
7493
7384
  token: getTokenDebugData(symbol.token) && symbol.token,
7494
7385
  };
7386
+ builtin.specialExpressions[node_1.n].validateParameterCount(node_1);
7387
+ return node_1;
7388
+ }
7389
+ case 'let':
7390
+ return this.parseLet(symbol, params);
7495
7391
  case 'def':
7496
7392
  case 'defs':
7497
- case 'let':
7498
7393
  case 'if-let':
7499
7394
  case 'when-let':
7500
7395
  case 'when-first':
@@ -7504,7 +7399,6 @@ var AlgebraicParser = /** @class */ (function () {
7504
7399
  case 'try':
7505
7400
  case 'recur':
7506
7401
  case 'loop':
7507
- case 'time!':
7508
7402
  case 'doseq':
7509
7403
  case 'for':
7510
7404
  throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
@@ -7512,7 +7406,12 @@ var AlgebraicParser = /** @class */ (function () {
7512
7406
  throw new Error("Unknown special expression: ".concat(name_1));
7513
7407
  }
7514
7408
  }
7515
- return createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7409
+ var node = createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7410
+ var builtinExpression = builtin.normalExpressions[node.n];
7411
+ if (builtinExpression) {
7412
+ (_c = builtinExpression.validate) === null || _c === void 0 ? void 0 : _c.call(builtinExpression, __assign(__assign({}, node), { p: withoutCommentNodes(node.p) }));
7413
+ }
7414
+ return node;
7516
7415
  }
7517
7416
  else {
7518
7417
  return {
@@ -7524,31 +7423,40 @@ var AlgebraicParser = /** @class */ (function () {
7524
7423
  }
7525
7424
  };
7526
7425
  AlgebraicParser.prototype.parseLambdaFunction = function () {
7527
- var _a;
7426
+ var _a, _b;
7528
7427
  var firstToken = this.peek();
7529
7428
  this.advance();
7530
- var spread = false;
7429
+ var rest = false;
7430
+ var letBindingObject;
7531
7431
  var args = [];
7532
7432
  var restArg;
7533
7433
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
7534
- if (isA_OperatorToken(this.peek(), '...')) {
7535
- if (spread) {
7536
- throw new LitsError('Multiple spread operators in lambda function', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7537
- }
7538
- this.advance();
7539
- spread = true;
7540
- }
7541
- var symbolToken = this.peek();
7542
- if (!isA_SymbolToken(symbolToken)) {
7543
- return null;
7434
+ if (letBindingObject) {
7435
+ throw new LitsError('Expected right parentheses', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7544
7436
  }
7545
- if (spread) {
7546
- restArg = symbolToken[1];
7437
+ if (isLBraceToken(this.peek())) {
7438
+ letBindingObject = this.parseObject();
7547
7439
  }
7548
7440
  else {
7549
- args.push(symbolToken[1]);
7441
+ if (isA_OperatorToken(this.peek(), '...')) {
7442
+ if (rest) {
7443
+ throw new LitsError('Multiple spread operators in lambda function', (_b = getTokenDebugData(this.peek())) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7444
+ }
7445
+ this.advance();
7446
+ rest = true;
7447
+ }
7448
+ var symbolToken = this.peek();
7449
+ if (!isA_SymbolToken(symbolToken)) {
7450
+ return null;
7451
+ }
7452
+ if (rest) {
7453
+ restArg = symbolToken[1];
7454
+ }
7455
+ else {
7456
+ args.push(symbolToken[1]);
7457
+ }
7458
+ this.advance();
7550
7459
  }
7551
- this.advance();
7552
7460
  if (!isA_OperatorToken(this.peek(), ',') && !isRParenToken(this.peek())) {
7553
7461
  return null;
7554
7462
  }
@@ -7564,6 +7472,7 @@ var AlgebraicParser = /** @class */ (function () {
7564
7472
  return null;
7565
7473
  }
7566
7474
  this.advance();
7475
+ var letBindings = letBindingObject ? arrayToPairs(letBindingObject.p) : [];
7567
7476
  var body = this.parseExpression();
7568
7477
  var arity = restArg !== undefined ? { min: args.length } : args.length;
7569
7478
  return {
@@ -7574,7 +7483,17 @@ var AlgebraicParser = /** @class */ (function () {
7574
7483
  as: {
7575
7484
  m: args,
7576
7485
  r: restArg,
7577
- b: [],
7486
+ b: letBindings.map(function (pair) {
7487
+ var key = pair[0];
7488
+ var value = pair[1];
7489
+ return {
7490
+ t: AstNodeType.Binding,
7491
+ n: key.v,
7492
+ v: value,
7493
+ p: [],
7494
+ token: getTokenDebugData(key.token) && key.token,
7495
+ };
7496
+ }),
7578
7497
  },
7579
7498
  b: [body],
7580
7499
  a: arity,
@@ -7638,6 +7557,35 @@ var AlgebraicParser = /** @class */ (function () {
7638
7557
  };
7639
7558
  return node;
7640
7559
  };
7560
+ AlgebraicParser.prototype.parseLet = function (nameSymbol, params) {
7561
+ var _a, _b;
7562
+ if (params.length !== 2) {
7563
+ throw new LitsError('let expects two arguments', (_a = getTokenDebugData(nameSymbol.token)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7564
+ }
7565
+ var letObject = params[0];
7566
+ if (letObject.t !== AstNodeType.NormalExpression || letObject.n !== 'object') {
7567
+ throw new LitsError('let expects an object as first argument', (_b = getTokenDebugData(letObject.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7568
+ }
7569
+ var letBindings = arrayToPairs(letObject.p);
7570
+ var expression = params[1];
7571
+ return {
7572
+ t: AstNodeType.SpecialExpression,
7573
+ n: 'let',
7574
+ p: [expression],
7575
+ token: getTokenDebugData(nameSymbol.token) && nameSymbol.token,
7576
+ bs: letBindings.map(function (pair) {
7577
+ var key = pair[0];
7578
+ var value = pair[1];
7579
+ return {
7580
+ t: AstNodeType.Binding,
7581
+ n: key.v,
7582
+ v: value,
7583
+ p: [],
7584
+ token: getTokenDebugData(key.token) && key.token,
7585
+ };
7586
+ }),
7587
+ };
7588
+ };
7641
7589
  AlgebraicParser.prototype.isAtEnd = function () {
7642
7590
  return this.parseState.position >= this.tokenStream.tokens.length;
7643
7591
  };
@@ -7881,7 +7829,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7881
7829
  var firstToken = asLParenToken(tokenStream.tokens[parseState.position++]);
7882
7830
  var nameToken = asP_SymbolToken(tokenStream.tokens[parseState.position++]);
7883
7831
  var expressionName = nameToken[1];
7884
- var parse = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo).parse;
7832
+ var _b = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo), parse = _b.polishParse, validateParameterCount = _b.validateParameterCount;
7885
7833
  var node = parse(tokenStream, parseState, firstToken, {
7886
7834
  parseExpression: parseExpression,
7887
7835
  parseTokensUntilClosingBracket: parseTokensUntilClosingBracket,
@@ -7890,6 +7838,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7890
7838
  parseBindings: parseBindings,
7891
7839
  parseArgument: parseArgument,
7892
7840
  });
7841
+ validateParameterCount(node);
7893
7842
  return node;
7894
7843
  }
7895
7844
  function parsePolishToken(tokenStream, parseState) {
@@ -7979,7 +7928,11 @@ function parse(tokenStream) {
7979
7928
  }
7980
7929
  function removeUnnecessaryTokens(tokenStream) {
7981
7930
  var tokens = tokenStream.tokens.filter(function (token) {
7982
- if (isP_CommentToken(token) || isA_WhitespaceToken(token) || isP_WhitespaceToken(token)) {
7931
+ if (isP_CommentToken(token)
7932
+ || isA_CommentToken(token)
7933
+ || isA_MultiLineCommentToken(token)
7934
+ || isA_WhitespaceToken(token)
7935
+ || isP_WhitespaceToken(token)) {
7983
7936
  return false;
7984
7937
  }
7985
7938
  return true;
@@ -8295,7 +8248,6 @@ var algebraicReservedNamesRecord = {
8295
8248
  'null': { value: null },
8296
8249
  'def': { value: null, forbidden: true },
8297
8250
  'defs': { value: null, forbidden: true },
8298
- 'let': { value: null, forbidden: true },
8299
8251
  'if-let': { value: null, forbidden: true },
8300
8252
  'when-let': { value: null, forbidden: true },
8301
8253
  'when-first': { value: null, forbidden: true },