@mojir/lits 2.0.8 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,8 +29,11 @@ declare const specialExpressions: {
29
29
  readonly '??': import("./interface").BuiltinSpecialExpression<import("../interface").Any, import("./specialExpressions/qq").QqNode>;
30
30
  };
31
31
  export type SpecialExpressionName = keyof typeof specialExpressions;
32
+ export type CommonSpecialExpressionName = keyof Pick<typeof specialExpressions, '??' | '??' | 'and' | 'comment' | 'cond' | 'declared?' | 'do' | 'if' | 'if-not' | 'or' | 'time!' | 'when' | 'when-not' | 'throw'>;
32
33
  export type BuiltinSpecialExpressions = typeof specialExpressions;
33
34
  export type BuiltinSpecialExpression = typeof specialExpressions[SpecialExpressionName];
35
+ export type BuiltinCommonSpecialExpression = typeof specialExpressions[CommonSpecialExpressionName];
36
+ export type GenericCommonSpecialExpressionNode<T extends CommonSpecialExpressionName> = ReturnType<typeof specialExpressions[T]['parse']>;
34
37
  export type SpecialExpressionNode = ReturnType<typeof specialExpressions[SpecialExpressionName]['parse']>;
35
38
  export declare const builtin: Builtin;
36
39
  export declare const normalExpressionKeys: string[];
@@ -9,10 +9,11 @@ import type { BuiltinSpecialExpressions, SpecialExpressionNode } from '.';
9
9
  export type NormalExpressionEvaluator<T> = (params: Arr, sourceCodeInfo: SourceCodeInfo | undefined, contextStack: ContextStack, { executeFunction }: {
10
10
  executeFunction: ExecuteFunction;
11
11
  }) => T;
12
- type ValidateNode = (node: NormalExpressionNode) => void;
12
+ type ValidateNormalExpressionNode = (node: NormalExpressionNode) => void;
13
+ type ValidateSpecialExpressionNode = (node: SpecialExpressionNode) => void;
13
14
  interface BuiltinNormalExpression<T> {
14
15
  evaluate: NormalExpressionEvaluator<T>;
15
- validate?: ValidateNode;
16
+ validate?: ValidateNormalExpressionNode;
16
17
  }
17
18
  export interface ParserHelpers {
18
19
  parseExpression: ParseExpression;
@@ -30,6 +31,7 @@ interface EvaluateHelpers {
30
31
  export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
31
32
  parse: (tokenStream: TokenStream, parseState: ParseState, firstToken: Token, parsers: ParserHelpers) => N;
32
33
  evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T;
34
+ validateParameterCount: ValidateSpecialExpressionNode;
33
35
  findUnresolvedIdentifiers: (node: N, contextStack: ContextStack, params: {
34
36
  findUnresolvedIdentifiers: FindUnresolvedIdentifiers;
35
37
  builtin: Builtin;
@@ -0,0 +1,4 @@
1
+ import type { CommonSpecialExpressionName, GenericCommonSpecialExpressionNode } from '..';
2
+ import type { Any } from '../../interface';
3
+ import type { BuiltinSpecialExpression } from '../interface';
4
+ export declare function getCommonParser<T extends CommonSpecialExpressionName>(name: T): BuiltinSpecialExpression<Any, GenericCommonSpecialExpressionNode<T>>['parse'];
@@ -11,7 +11,8 @@ export declare class AlgebraicParser {
11
11
  private parseObject;
12
12
  private parseArray;
13
13
  private parseFunctionCall;
14
- parseLamdaFunction(): AstNode | null;
14
+ parseLambdaFunction(): AstNode | null;
15
+ private parseShorthandLamdaFunction;
15
16
  private isAtEnd;
16
17
  private peek;
17
18
  }
@@ -3124,7 +3124,7 @@ var mathNormalExpression = {
3124
3124
  },
3125
3125
  };
3126
3126
 
3127
- var version = "2.0.8";
3127
+ var version = "2.0.10";
3128
3128
 
3129
3129
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3130
3130
  var xyRegexp = /[xy]/g;
@@ -4339,6 +4339,7 @@ var andSpecialExpression = {
4339
4339
  };
4340
4340
  return node;
4341
4341
  },
4342
+ validateParameterCount: function () { return undefined; },
4342
4343
  evaluate: function (node, contextStack, _a) {
4343
4344
  var e_1, _b;
4344
4345
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4366,42 +4367,30 @@ var andSpecialExpression = {
4366
4367
  },
4367
4368
  };
4368
4369
 
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) {
4370
+ function getCommonParser(name) {
4371
+ return function (tokenStream, parseState, firstToken, _a) {
4393
4372
  var parseTokensUntilClosingBracket = _a.parseTokensUntilClosingBracket;
4394
4373
  var params = parseTokensUntilClosingBracket(tokenStream, parseState);
4395
4374
  assertRParenToken(tokenStream.tokens[parseState.position++]);
4396
- var node = {
4375
+ return {
4397
4376
  t: AstNodeType.SpecialExpression,
4398
- n: 'cond',
4377
+ n: name,
4399
4378
  p: params,
4400
4379
  token: getTokenDebugData(firstToken) && firstToken,
4401
4380
  };
4402
- assertEvenNumberOfParams(node);
4403
- return node;
4404
- },
4381
+ };
4382
+ }
4383
+
4384
+ var commentSpecialExpression = {
4385
+ parse: getCommonParser('comment'),
4386
+ validateParameterCount: function () { return undefined; },
4387
+ evaluate: function () { return null; },
4388
+ findUnresolvedIdentifiers: function () { return new Set(); },
4389
+ };
4390
+
4391
+ var condSpecialExpression = {
4392
+ parse: getCommonParser('cond'),
4393
+ validateParameterCount: function (node) { return assertEvenNumberOfParams(node); },
4405
4394
  evaluate: function (node, contextStack, _a) {
4406
4395
  var e_1, _b;
4407
4396
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4430,19 +4419,8 @@ var condSpecialExpression = {
4430
4419
  };
4431
4420
 
4432
4421
  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
- },
4422
+ parse: getCommonParser('declared?'),
4423
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
4446
4424
  evaluate: function (node, contextStack) {
4447
4425
  var lookUpResult = contextStack.lookUp(node.p[0]);
4448
4426
  return lookUpResult !== null;
@@ -4487,9 +4465,9 @@ var defSpecialExpression = {
4487
4465
  token: getTokenDebugData(firstToken) && firstToken,
4488
4466
  };
4489
4467
  assertSymbolNode(node.p[0], (_b = getTokenDebugData(node.token)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
4490
- assertNumberOfParams(2, node);
4491
4468
  return node;
4492
4469
  },
4470
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4493
4471
  evaluate: function (node, contextStack, _a) {
4494
4472
  var _b;
4495
4473
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4525,9 +4503,9 @@ var defsSpecialExpression = {
4525
4503
  p: params,
4526
4504
  token: getTokenDebugData(firstToken) && firstToken,
4527
4505
  };
4528
- assertNumberOfParams(2, node);
4529
4506
  return node;
4530
4507
  },
4508
+ validateParameterCount: function (node) { return assertNumberOfParams(2, node); },
4531
4509
  evaluate: function (node, contextStack, _a) {
4532
4510
  var _b, _c;
4533
4511
  var evaluateAstNode = _a.evaluateAstNode, builtin = _a.builtin;
@@ -4555,23 +4533,8 @@ var defsSpecialExpression = {
4555
4533
  };
4556
4534
 
4557
4535
  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
- },
4536
+ parse: getCommonParser('do'),
4537
+ validateParameterCount: function () { return undefined; },
4575
4538
  evaluate: function (node, contextStack, _a) {
4576
4539
  var e_1, _b;
4577
4540
  var evaluateAstNode = _a.evaluateAstNode;
@@ -4648,6 +4611,7 @@ var defnSpecialExpression = {
4648
4611
  };
4649
4612
  return node;
4650
4613
  },
4614
+ validateParameterCount: function () { return undefined; },
4651
4615
  evaluate: function (node, contextStack, _a) {
4652
4616
  var _b;
4653
4617
  var _c, _d;
@@ -4689,6 +4653,7 @@ var defnsSpecialExpression = {
4689
4653
  };
4690
4654
  return node;
4691
4655
  },
4656
+ validateParameterCount: function () { return undefined; },
4692
4657
  evaluate: function (node, contextStack, _a) {
4693
4658
  var _b;
4694
4659
  var _c, _d;
@@ -4732,6 +4697,7 @@ var fnSpecialExpression = {
4732
4697
  };
4733
4698
  return node;
4734
4699
  },
4700
+ validateParameterCount: function () { return undefined; },
4735
4701
  evaluate: function (node, contextStack, _a) {
4736
4702
  var _b;
4737
4703
  var _c;
@@ -4963,19 +4929,8 @@ function parseFunctionArguments(tokenStream, parseState, parsers) {
4963
4929
  }
4964
4930
 
4965
4931
  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
- },
4932
+ parse: getCommonParser('if'),
4933
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
4979
4934
  evaluate: function (node, contextStack, _a) {
4980
4935
  var _b;
4981
4936
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5014,9 +4969,9 @@ var ifLetSpecialExpression = {
5014
4969
  p: params,
5015
4970
  token: getTokenDebugData(firstToken) && firstToken,
5016
4971
  };
5017
- assertNumberOfParams({ min: 1, max: 2 }, node);
5018
4972
  return node;
5019
4973
  },
4974
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5020
4975
  evaluate: function (node, contextStack, _a) {
5021
4976
  var _b;
5022
4977
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5046,19 +5001,8 @@ var ifLetSpecialExpression = {
5046
5001
  };
5047
5002
 
5048
5003
  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
- },
5004
+ parse: getCommonParser('if-not'),
5005
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 2, max: 3 }, node); },
5062
5006
  evaluate: function (node, contextStack, _a) {
5063
5007
  var _b;
5064
5008
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5095,6 +5039,7 @@ var letSpecialExpression = {
5095
5039
  };
5096
5040
  return node;
5097
5041
  },
5042
+ validateParameterCount: function () { return undefined; },
5098
5043
  evaluate: function (node, contextStack, _a) {
5099
5044
  var e_1, _b, e_2, _c;
5100
5045
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5166,6 +5111,7 @@ var loopSpecialExpression = {
5166
5111
  };
5167
5112
  return node;
5168
5113
  },
5114
+ validateParameterCount: function () { return undefined; },
5169
5115
  evaluate: function (node, contextStack, _a) {
5170
5116
  var _b;
5171
5117
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5429,9 +5375,9 @@ var forSpecialExpression = {
5429
5375
  p: params,
5430
5376
  token: getTokenDebugData(firstToken) && firstToken,
5431
5377
  };
5432
- assertNumberOfParams(1, node);
5433
5378
  return node;
5434
5379
  },
5380
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5435
5381
  evaluate: function (node, contextStack, helpers) { return evaluateLoop(true, node, contextStack, helpers.evaluateAstNode); },
5436
5382
  findUnresolvedIdentifiers: function (node, contextStack, _a) {
5437
5383
  var findUnresolvedIdentifiers = _a.findUnresolvedIdentifiers, builtin = _a.builtin;
@@ -5451,9 +5397,9 @@ var doseqSpecialExpression = {
5451
5397
  p: params,
5452
5398
  token: getTokenDebugData(firstToken) && firstToken,
5453
5399
  };
5454
- assertNumberOfParams(1, node);
5455
5400
  return node;
5456
5401
  },
5402
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5457
5403
  evaluate: function (node, contextStack, helpers) {
5458
5404
  evaluateLoop(false, node, contextStack, helpers.evaluateAstNode);
5459
5405
  return null;
@@ -5465,18 +5411,8 @@ var doseqSpecialExpression = {
5465
5411
  };
5466
5412
 
5467
5413
  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
- },
5414
+ parse: getCommonParser('or'),
5415
+ validateParameterCount: function () { return undefined; },
5480
5416
  evaluate: function (node, contextStack, _a) {
5481
5417
  var e_1, _b;
5482
5418
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5505,19 +5441,8 @@ var orSpecialExpression = {
5505
5441
  };
5506
5442
 
5507
5443
  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
- },
5444
+ parse: getCommonParser('??'),
5445
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1, max: 2 }, node); },
5521
5446
  evaluate: function (node, contextStack, _a) {
5522
5447
  var _b;
5523
5448
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5549,6 +5474,7 @@ var recurSpecialExpression = {
5549
5474
  };
5550
5475
  return node;
5551
5476
  },
5477
+ validateParameterCount: function () { return undefined; },
5552
5478
  evaluate: function (node, contextStack, _a) {
5553
5479
  var evaluateAstNode = _a.evaluateAstNode;
5554
5480
  var params = node.p.map(function (paramNode) { return evaluateAstNode(paramNode, contextStack); });
@@ -5561,19 +5487,8 @@ var recurSpecialExpression = {
5561
5487
  };
5562
5488
 
5563
5489
  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
- },
5490
+ parse: getCommonParser('throw'),
5491
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5577
5492
  evaluate: function (node, contextStack, _a) {
5578
5493
  var _b, _c;
5579
5494
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5589,19 +5504,8 @@ var throwSpecialExpression = {
5589
5504
  };
5590
5505
 
5591
5506
  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
- },
5507
+ parse: getCommonParser('time!'),
5508
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5605
5509
  evaluate: function (node, contextStack, _a) {
5606
5510
  var evaluateAstNode = _a.evaluateAstNode;
5607
5511
  var param = node.p[0];
@@ -5642,9 +5546,9 @@ var trySpecialExpression = {
5642
5546
  e: error,
5643
5547
  token: getTokenDebugData(firstToken) && firstToken,
5644
5548
  };
5645
- assertNumberOfParams(1, node);
5646
5549
  return node;
5647
5550
  },
5551
+ validateParameterCount: function (node) { return assertNumberOfParams(1, node); },
5648
5552
  evaluate: function (node, contextStack, _a) {
5649
5553
  var _b;
5650
5554
  var _c;
@@ -5674,19 +5578,8 @@ var trySpecialExpression = {
5674
5578
  };
5675
5579
 
5676
5580
  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
- },
5581
+ parse: getCommonParser('when'),
5582
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5690
5583
  evaluate: function (node, contextStack, _a) {
5691
5584
  var e_1, _b;
5692
5585
  var _c;
@@ -5736,6 +5629,7 @@ var whenFirstSpecialExpression = {
5736
5629
  };
5737
5630
  return node;
5738
5631
  },
5632
+ validateParameterCount: function () { return undefined; },
5739
5633
  evaluate: function (node, contextStack, _a) {
5740
5634
  var e_1, _b;
5741
5635
  var _c;
@@ -5797,6 +5691,7 @@ var whenLetSpecialExpression = {
5797
5691
  };
5798
5692
  return node;
5799
5693
  },
5694
+ validateParameterCount: function () { return undefined; },
5800
5695
  evaluate: function (node, contextStack, _a) {
5801
5696
  var e_1, _b;
5802
5697
  var evaluateAstNode = _a.evaluateAstNode;
@@ -5835,19 +5730,8 @@ var whenLetSpecialExpression = {
5835
5730
  };
5836
5731
 
5837
5732
  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
- },
5733
+ parse: getCommonParser('when-not'),
5734
+ validateParameterCount: function (node) { return assertNumberOfParams({ min: 1 }, node); },
5851
5735
  evaluate: function (node, contextStack, _a) {
5852
5736
  var e_1, _b;
5853
5737
  var _c;
@@ -7075,6 +6959,7 @@ function parseString(tokenStream, parseState) {
7075
6959
  }
7076
6960
 
7077
6961
  var exponentiationPrecedence = 9;
6962
+ var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
7078
6963
  function getPrecedence(operator) {
7079
6964
  var operatorSign = operator[1];
7080
6965
  switch (operatorSign) {
@@ -7307,7 +7192,7 @@ var AlgebraicParser = /** @class */ (function () {
7307
7192
  // Parentheses
7308
7193
  if (isLParenToken(token)) {
7309
7194
  var positionBefore = this.parseState.position;
7310
- var lamdaFunction = this.parseLamdaFunction();
7195
+ var lamdaFunction = this.parseLambdaFunction();
7311
7196
  if (lamdaFunction) {
7312
7197
  return lamdaFunction;
7313
7198
  }
@@ -7328,6 +7213,9 @@ var AlgebraicParser = /** @class */ (function () {
7328
7213
  var operand = this.parseOperand();
7329
7214
  return fromUnaryAlgebraicToAstNode(token, operand);
7330
7215
  }
7216
+ else if (operatorName === '=>') {
7217
+ return this.parseShorthandLamdaFunction();
7218
+ }
7331
7219
  else {
7332
7220
  throw new Error("Unknown unary operator: ".concat(operatorName));
7333
7221
  }
@@ -7443,7 +7331,7 @@ var AlgebraicParser = /** @class */ (function () {
7443
7331
  };
7444
7332
  };
7445
7333
  AlgebraicParser.prototype.parseFunctionCall = function (symbol) {
7446
- var _a, _b;
7334
+ var _a, _b, _c;
7447
7335
  var params = [];
7448
7336
  this.advance();
7449
7337
  while (!this.isAtEnd() && !isRParenToken(this.peek())) {
@@ -7475,13 +7363,17 @@ var AlgebraicParser = /** @class */ (function () {
7475
7363
  case 'when':
7476
7364
  case 'when-not':
7477
7365
  case 'do':
7478
- case 'throw':
7479
- return {
7366
+ case 'time!':
7367
+ case 'throw': {
7368
+ var node_1 = {
7480
7369
  t: AstNodeType.SpecialExpression,
7481
7370
  n: name_1,
7482
7371
  p: params,
7483
7372
  token: getTokenDebugData(symbol.token) && symbol.token,
7484
7373
  };
7374
+ builtin.specialExpressions[node_1.n].validateParameterCount(node_1);
7375
+ return node_1;
7376
+ }
7485
7377
  case 'def':
7486
7378
  case 'defs':
7487
7379
  case 'let':
@@ -7494,7 +7386,6 @@ var AlgebraicParser = /** @class */ (function () {
7494
7386
  case 'try':
7495
7387
  case 'recur':
7496
7388
  case 'loop':
7497
- case 'time!':
7498
7389
  case 'doseq':
7499
7390
  case 'for':
7500
7391
  throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
@@ -7502,7 +7393,12 @@ var AlgebraicParser = /** @class */ (function () {
7502
7393
  throw new Error("Unknown special expression: ".concat(name_1));
7503
7394
  }
7504
7395
  }
7505
- return createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7396
+ var node = createNamedNormalExpressionNode(symbol.v, params, symbol.token);
7397
+ var builtinExpression = builtin.normalExpressions[node.n];
7398
+ if (builtinExpression) {
7399
+ (_c = builtinExpression.validate) === null || _c === void 0 ? void 0 : _c.call(builtinExpression, __assign(__assign({}, node), { p: withoutCommentNodes(node.p) }));
7400
+ }
7401
+ return node;
7506
7402
  }
7507
7403
  else {
7508
7404
  return {
@@ -7513,7 +7409,7 @@ var AlgebraicParser = /** @class */ (function () {
7513
7409
  };
7514
7410
  }
7515
7411
  };
7516
- AlgebraicParser.prototype.parseLamdaFunction = function () {
7412
+ AlgebraicParser.prototype.parseLambdaFunction = function () {
7517
7413
  var _a;
7518
7414
  var firstToken = this.peek();
7519
7415
  this.advance();
@@ -7572,6 +7468,62 @@ var AlgebraicParser = /** @class */ (function () {
7572
7468
  token: getTokenDebugData(firstToken) && firstToken,
7573
7469
  };
7574
7470
  };
7471
+ AlgebraicParser.prototype.parseShorthandLamdaFunction = function () {
7472
+ var _a, _b, _c, _d;
7473
+ var firstToken = this.peek();
7474
+ this.advance();
7475
+ var startPos = this.parseState.position;
7476
+ var exprNode = this.parseExpression();
7477
+ var endPos = this.parseState.position - 1;
7478
+ var arity = 0;
7479
+ var percent1 = 'NOT_SET'; // referring to argument bindings. % = NAKED, %1, %2, %3, etc = WITH_1
7480
+ for (var pos = startPos; pos <= endPos; pos += 1) {
7481
+ var tkn = this.tokenStream.tokens[pos];
7482
+ if (isA_SymbolToken(tkn)) {
7483
+ var match = placeholderRegexp$1.exec(tkn[1]);
7484
+ if (match) {
7485
+ var number = (_a = match[1]) !== null && _a !== void 0 ? _a : '1';
7486
+ if (number === '1') {
7487
+ var mixedPercent1 = (!match[1] && percent1 === 'WITH_1') || (match[1] && percent1 === 'NAKED');
7488
+ if (mixedPercent1)
7489
+ throw new LitsError('Please make up your mind, either use $ or $1', (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7490
+ percent1 = match[1] ? 'WITH_1' : 'NAKED';
7491
+ }
7492
+ arity = Math.max(arity, Number(number));
7493
+ if (arity > 20)
7494
+ throw new LitsError('Can\'t specify more than 20 arguments', (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
7495
+ }
7496
+ }
7497
+ if (isA_OperatorToken(tkn, '=>')) {
7498
+ throw new LitsError('Nested shortcut functions are not allowed', (_d = getTokenDebugData(firstToken)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo);
7499
+ }
7500
+ }
7501
+ var mandatoryArguments = [];
7502
+ for (var i = 1; i <= arity; i += 1) {
7503
+ if (i === 1 && percent1 === 'NAKED')
7504
+ mandatoryArguments.push('$');
7505
+ else
7506
+ mandatoryArguments.push("$".concat(i));
7507
+ }
7508
+ var args = {
7509
+ b: [],
7510
+ m: mandatoryArguments,
7511
+ };
7512
+ var node = {
7513
+ t: AstNodeType.SpecialExpression,
7514
+ n: 'fn',
7515
+ p: [],
7516
+ o: [
7517
+ {
7518
+ as: args,
7519
+ b: [exprNode],
7520
+ a: args.m.length,
7521
+ },
7522
+ ],
7523
+ token: getTokenDebugData(firstToken) && firstToken,
7524
+ };
7525
+ return node;
7526
+ };
7575
7527
  AlgebraicParser.prototype.isAtEnd = function () {
7576
7528
  return this.parseState.position >= this.tokenStream.tokens.length;
7577
7529
  };
@@ -7815,7 +7767,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7815
7767
  var firstToken = asLParenToken(tokenStream.tokens[parseState.position++]);
7816
7768
  var nameToken = asP_SymbolToken(tokenStream.tokens[parseState.position++]);
7817
7769
  var expressionName = nameToken[1];
7818
- var parse = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo).parse;
7770
+ var _b = asNonUndefined(builtin.specialExpressions[expressionName], (_a = getTokenDebugData(nameToken)) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo), parse = _b.parse, validateParameterCount = _b.validateParameterCount;
7819
7771
  var node = parse(tokenStream, parseState, firstToken, {
7820
7772
  parseExpression: parseExpression,
7821
7773
  parseTokensUntilClosingBracket: parseTokensUntilClosingBracket,
@@ -7824,6 +7776,7 @@ function parseSpecialExpression(tokenStream, parseState) {
7824
7776
  parseBindings: parseBindings,
7825
7777
  parseArgument: parseArgument,
7826
7778
  });
7779
+ validateParameterCount(node);
7827
7780
  return node;
7828
7781
  }
7829
7782
  function parsePolishToken(tokenStream, parseState) {