@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.
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.8";
95
+ var version = "2.0.9";
96
96
 
97
97
  var AstNodeType;
98
98
  (function (AstNodeType) {
@@ -7081,6 +7081,7 @@ function parseString(tokenStream, parseState) {
7081
7081
  }
7082
7082
 
7083
7083
  var exponentiationPrecedence = 9;
7084
+ var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
7084
7085
  function getPrecedence(operator) {
7085
7086
  var operatorSign = operator[1];
7086
7087
  switch (operatorSign) {
@@ -7313,7 +7314,7 @@ var AlgebraicParser = /** @class */ (function () {
7313
7314
  // Parentheses
7314
7315
  if (isLParenToken(token)) {
7315
7316
  var positionBefore = this.parseState.position;
7316
- var lamdaFunction = this.parseLamdaFunction();
7317
+ var lamdaFunction = this.parseLambdaFunction();
7317
7318
  if (lamdaFunction) {
7318
7319
  return lamdaFunction;
7319
7320
  }
@@ -7334,6 +7335,9 @@ var AlgebraicParser = /** @class */ (function () {
7334
7335
  var operand = this.parseOperand();
7335
7336
  return fromUnaryAlgebraicToAstNode(token, operand);
7336
7337
  }
7338
+ else if (operatorName === '=>') {
7339
+ return this.parseShorthandLamdaFunction();
7340
+ }
7337
7341
  else {
7338
7342
  throw new Error("Unknown unary operator: ".concat(operatorName));
7339
7343
  }
@@ -7519,7 +7523,7 @@ var AlgebraicParser = /** @class */ (function () {
7519
7523
  };
7520
7524
  }
7521
7525
  };
7522
- AlgebraicParser.prototype.parseLamdaFunction = function () {
7526
+ AlgebraicParser.prototype.parseLambdaFunction = function () {
7523
7527
  var _a;
7524
7528
  var firstToken = this.peek();
7525
7529
  this.advance();
@@ -7578,6 +7582,62 @@ var AlgebraicParser = /** @class */ (function () {
7578
7582
  token: getTokenDebugData(firstToken) && firstToken,
7579
7583
  };
7580
7584
  };
7585
+ AlgebraicParser.prototype.parseShorthandLamdaFunction = function () {
7586
+ var _a, _b, _c, _d;
7587
+ var firstToken = this.peek();
7588
+ this.advance();
7589
+ var startPos = this.parseState.position;
7590
+ var exprNode = this.parseExpression();
7591
+ var endPos = this.parseState.position - 1;
7592
+ var arity = 0;
7593
+ var percent1 = 'NOT_SET'; // referring to argument bindings. % = NAKED, %1, %2, %3, etc = WITH_1
7594
+ for (var pos = startPos; pos <= endPos; pos += 1) {
7595
+ var tkn = this.tokenStream.tokens[pos];
7596
+ if (isA_SymbolToken(tkn)) {
7597
+ var match = placeholderRegexp$1.exec(tkn[1]);
7598
+ if (match) {
7599
+ var number = (_a = match[1]) !== null && _a !== void 0 ? _a : '1';
7600
+ if (number === '1') {
7601
+ var mixedPercent1 = (!match[1] && percent1 === 'WITH_1') || (match[1] && percent1 === 'NAKED');
7602
+ if (mixedPercent1)
7603
+ throw new LitsError('Please make up your mind, either use $ or $1', (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7604
+ percent1 = match[1] ? 'WITH_1' : 'NAKED';
7605
+ }
7606
+ arity = Math.max(arity, Number(number));
7607
+ if (arity > 20)
7608
+ throw new LitsError('Can\'t specify more than 20 arguments', (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
7609
+ }
7610
+ }
7611
+ if (isA_OperatorToken(tkn, '=>')) {
7612
+ throw new LitsError('Nested shortcut functions are not allowed', (_d = getTokenDebugData(firstToken)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo);
7613
+ }
7614
+ }
7615
+ var mandatoryArguments = [];
7616
+ for (var i = 1; i <= arity; i += 1) {
7617
+ if (i === 1 && percent1 === 'NAKED')
7618
+ mandatoryArguments.push('$');
7619
+ else
7620
+ mandatoryArguments.push("$".concat(i));
7621
+ }
7622
+ var args = {
7623
+ b: [],
7624
+ m: mandatoryArguments,
7625
+ };
7626
+ var node = {
7627
+ t: AstNodeType.SpecialExpression,
7628
+ n: 'fn',
7629
+ p: [],
7630
+ o: [
7631
+ {
7632
+ as: args,
7633
+ b: [exprNode],
7634
+ a: args.m.length,
7635
+ },
7636
+ ],
7637
+ token: getTokenDebugData(firstToken) && firstToken,
7638
+ };
7639
+ return node;
7640
+ };
7581
7641
  AlgebraicParser.prototype.isAtEnd = function () {
7582
7642
  return this.parseState.position >= this.tokenStream.tokens.length;
7583
7643
  };
@@ -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
  }
package/dist/index.esm.js CHANGED
@@ -3161,7 +3161,7 @@ var mathNormalExpression = {
3161
3161
  },
3162
3162
  };
3163
3163
 
3164
- var version = "2.0.8";
3164
+ var version = "2.0.9";
3165
3165
 
3166
3166
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3167
3167
  var xyRegexp = /[xy]/g;
@@ -7113,6 +7113,7 @@ function parseString(tokenStream, parseState) {
7113
7113
  }
7114
7114
 
7115
7115
  var exponentiationPrecedence = 9;
7116
+ var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
7116
7117
  function getPrecedence(operator) {
7117
7118
  var operatorSign = operator[1];
7118
7119
  switch (operatorSign) {
@@ -7345,7 +7346,7 @@ var AlgebraicParser = /** @class */ (function () {
7345
7346
  // Parentheses
7346
7347
  if (isLParenToken(token)) {
7347
7348
  var positionBefore = this.parseState.position;
7348
- var lamdaFunction = this.parseLamdaFunction();
7349
+ var lamdaFunction = this.parseLambdaFunction();
7349
7350
  if (lamdaFunction) {
7350
7351
  return lamdaFunction;
7351
7352
  }
@@ -7366,6 +7367,9 @@ var AlgebraicParser = /** @class */ (function () {
7366
7367
  var operand = this.parseOperand();
7367
7368
  return fromUnaryAlgebraicToAstNode(token, operand);
7368
7369
  }
7370
+ else if (operatorName === '=>') {
7371
+ return this.parseShorthandLamdaFunction();
7372
+ }
7369
7373
  else {
7370
7374
  throw new Error("Unknown unary operator: ".concat(operatorName));
7371
7375
  }
@@ -7551,7 +7555,7 @@ var AlgebraicParser = /** @class */ (function () {
7551
7555
  };
7552
7556
  }
7553
7557
  };
7554
- AlgebraicParser.prototype.parseLamdaFunction = function () {
7558
+ AlgebraicParser.prototype.parseLambdaFunction = function () {
7555
7559
  var _a;
7556
7560
  var firstToken = this.peek();
7557
7561
  this.advance();
@@ -7610,6 +7614,62 @@ var AlgebraicParser = /** @class */ (function () {
7610
7614
  token: getTokenDebugData(firstToken) && firstToken,
7611
7615
  };
7612
7616
  };
7617
+ AlgebraicParser.prototype.parseShorthandLamdaFunction = function () {
7618
+ var _a, _b, _c, _d;
7619
+ var firstToken = this.peek();
7620
+ this.advance();
7621
+ var startPos = this.parseState.position;
7622
+ var exprNode = this.parseExpression();
7623
+ var endPos = this.parseState.position - 1;
7624
+ var arity = 0;
7625
+ var percent1 = 'NOT_SET'; // referring to argument bindings. % = NAKED, %1, %2, %3, etc = WITH_1
7626
+ for (var pos = startPos; pos <= endPos; pos += 1) {
7627
+ var tkn = this.tokenStream.tokens[pos];
7628
+ if (isA_SymbolToken(tkn)) {
7629
+ var match = placeholderRegexp$1.exec(tkn[1]);
7630
+ if (match) {
7631
+ var number = (_a = match[1]) !== null && _a !== void 0 ? _a : '1';
7632
+ if (number === '1') {
7633
+ var mixedPercent1 = (!match[1] && percent1 === 'WITH_1') || (match[1] && percent1 === 'NAKED');
7634
+ if (mixedPercent1)
7635
+ throw new LitsError('Please make up your mind, either use $ or $1', (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7636
+ percent1 = match[1] ? 'WITH_1' : 'NAKED';
7637
+ }
7638
+ arity = Math.max(arity, Number(number));
7639
+ if (arity > 20)
7640
+ throw new LitsError('Can\'t specify more than 20 arguments', (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
7641
+ }
7642
+ }
7643
+ if (isA_OperatorToken(tkn, '=>')) {
7644
+ throw new LitsError('Nested shortcut functions are not allowed', (_d = getTokenDebugData(firstToken)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo);
7645
+ }
7646
+ }
7647
+ var mandatoryArguments = [];
7648
+ for (var i = 1; i <= arity; i += 1) {
7649
+ if (i === 1 && percent1 === 'NAKED')
7650
+ mandatoryArguments.push('$');
7651
+ else
7652
+ mandatoryArguments.push("$".concat(i));
7653
+ }
7654
+ var args = {
7655
+ b: [],
7656
+ m: mandatoryArguments,
7657
+ };
7658
+ var node = {
7659
+ t: AstNodeType.SpecialExpression,
7660
+ n: 'fn',
7661
+ p: [],
7662
+ o: [
7663
+ {
7664
+ as: args,
7665
+ b: [exprNode],
7666
+ a: args.m.length,
7667
+ },
7668
+ ],
7669
+ token: getTokenDebugData(firstToken) && firstToken,
7670
+ };
7671
+ return node;
7672
+ };
7613
7673
  AlgebraicParser.prototype.isAtEnd = function () {
7614
7674
  return this.parseState.position >= this.tokenStream.tokens.length;
7615
7675
  };