@mojir/lits 2.0.8 → 2.0.9

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.
@@ -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.9";
3128
3128
 
3129
3129
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3130
3130
  var xyRegexp = /[xy]/g;
@@ -7075,6 +7075,7 @@ function parseString(tokenStream, parseState) {
7075
7075
  }
7076
7076
 
7077
7077
  var exponentiationPrecedence = 9;
7078
+ var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
7078
7079
  function getPrecedence(operator) {
7079
7080
  var operatorSign = operator[1];
7080
7081
  switch (operatorSign) {
@@ -7307,7 +7308,7 @@ var AlgebraicParser = /** @class */ (function () {
7307
7308
  // Parentheses
7308
7309
  if (isLParenToken(token)) {
7309
7310
  var positionBefore = this.parseState.position;
7310
- var lamdaFunction = this.parseLamdaFunction();
7311
+ var lamdaFunction = this.parseLambdaFunction();
7311
7312
  if (lamdaFunction) {
7312
7313
  return lamdaFunction;
7313
7314
  }
@@ -7328,6 +7329,9 @@ var AlgebraicParser = /** @class */ (function () {
7328
7329
  var operand = this.parseOperand();
7329
7330
  return fromUnaryAlgebraicToAstNode(token, operand);
7330
7331
  }
7332
+ else if (operatorName === '=>') {
7333
+ return this.parseShorthandLamdaFunction();
7334
+ }
7331
7335
  else {
7332
7336
  throw new Error("Unknown unary operator: ".concat(operatorName));
7333
7337
  }
@@ -7513,7 +7517,7 @@ var AlgebraicParser = /** @class */ (function () {
7513
7517
  };
7514
7518
  }
7515
7519
  };
7516
- AlgebraicParser.prototype.parseLamdaFunction = function () {
7520
+ AlgebraicParser.prototype.parseLambdaFunction = function () {
7517
7521
  var _a;
7518
7522
  var firstToken = this.peek();
7519
7523
  this.advance();
@@ -7572,6 +7576,62 @@ var AlgebraicParser = /** @class */ (function () {
7572
7576
  token: getTokenDebugData(firstToken) && firstToken,
7573
7577
  };
7574
7578
  };
7579
+ AlgebraicParser.prototype.parseShorthandLamdaFunction = function () {
7580
+ var _a, _b, _c, _d;
7581
+ var firstToken = this.peek();
7582
+ this.advance();
7583
+ var startPos = this.parseState.position;
7584
+ var exprNode = this.parseExpression();
7585
+ var endPos = this.parseState.position - 1;
7586
+ var arity = 0;
7587
+ var percent1 = 'NOT_SET'; // referring to argument bindings. % = NAKED, %1, %2, %3, etc = WITH_1
7588
+ for (var pos = startPos; pos <= endPos; pos += 1) {
7589
+ var tkn = this.tokenStream.tokens[pos];
7590
+ if (isA_SymbolToken(tkn)) {
7591
+ var match = placeholderRegexp$1.exec(tkn[1]);
7592
+ if (match) {
7593
+ var number = (_a = match[1]) !== null && _a !== void 0 ? _a : '1';
7594
+ if (number === '1') {
7595
+ var mixedPercent1 = (!match[1] && percent1 === 'WITH_1') || (match[1] && percent1 === 'NAKED');
7596
+ if (mixedPercent1)
7597
+ throw new LitsError('Please make up your mind, either use $ or $1', (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7598
+ percent1 = match[1] ? 'WITH_1' : 'NAKED';
7599
+ }
7600
+ arity = Math.max(arity, Number(number));
7601
+ if (arity > 20)
7602
+ throw new LitsError('Can\'t specify more than 20 arguments', (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
7603
+ }
7604
+ }
7605
+ if (isA_OperatorToken(tkn, '=>')) {
7606
+ throw new LitsError('Nested shortcut functions are not allowed', (_d = getTokenDebugData(firstToken)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo);
7607
+ }
7608
+ }
7609
+ var mandatoryArguments = [];
7610
+ for (var i = 1; i <= arity; i += 1) {
7611
+ if (i === 1 && percent1 === 'NAKED')
7612
+ mandatoryArguments.push('$');
7613
+ else
7614
+ mandatoryArguments.push("$".concat(i));
7615
+ }
7616
+ var args = {
7617
+ b: [],
7618
+ m: mandatoryArguments,
7619
+ };
7620
+ var node = {
7621
+ t: AstNodeType.SpecialExpression,
7622
+ n: 'fn',
7623
+ p: [],
7624
+ o: [
7625
+ {
7626
+ as: args,
7627
+ b: [exprNode],
7628
+ a: args.m.length,
7629
+ },
7630
+ ],
7631
+ token: getTokenDebugData(firstToken) && firstToken,
7632
+ };
7633
+ return node;
7634
+ };
7575
7635
  AlgebraicParser.prototype.isAtEnd = function () {
7576
7636
  return this.parseState.position >= this.tokenStream.tokens.length;
7577
7637
  };