@mojir/lits 2.0.7 → 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/index.js CHANGED
@@ -392,6 +392,7 @@ var AlgebraicOperators = [
392
392
  '<<', // left shift
393
393
  '>>', // signed right shift
394
394
  '>>>', // unsigned right shift
395
+ '++', // string concatenation
395
396
  '<', // less than
396
397
  '<=', // less than or equal
397
398
  '>', // greater than
@@ -3162,7 +3163,7 @@ var mathNormalExpression = {
3162
3163
  },
3163
3164
  };
3164
3165
 
3165
- var version = "2.0.7";
3166
+ var version = "2.0.9";
3166
3167
 
3167
3168
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3168
3169
  var xyRegexp = /[xy]/g;
@@ -7113,24 +7114,27 @@ function parseString(tokenStream, parseState) {
7113
7114
  };
7114
7115
  }
7115
7116
 
7116
- var exponentiationPrecedence = 8;
7117
+ var exponentiationPrecedence = 9;
7118
+ var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
7117
7119
  function getPrecedence(operator) {
7118
7120
  var operatorSign = operator[1];
7119
7121
  switch (operatorSign) {
7120
7122
  case '.': // accessor
7121
- return 9;
7123
+ return 10;
7122
7124
  case '**': // exponentiation
7123
7125
  return exponentiationPrecedence;
7124
7126
  case '*': // multiplication
7125
7127
  case '/': // division
7126
7128
  case '%': // remainder
7127
- return 7;
7129
+ return 8;
7128
7130
  case '+': // addition
7129
7131
  case '-': // subtraction
7130
- return 6;
7132
+ return 7;
7131
7133
  case '<<': // left shift
7132
7134
  case '>>': // signed right shift
7133
7135
  case '>>>': // unsigned right shift
7136
+ return 6;
7137
+ case '++': // string concatenation
7134
7138
  return 5;
7135
7139
  case '<': // less than
7136
7140
  case '<=': // less than or equal
@@ -7228,6 +7232,11 @@ function fromBinaryAlgebraicToAstNode(operator, left, right) {
7228
7232
  return createNamedNormalExpressionNode('bit-shift-right', [left, right], token);
7229
7233
  case '>>>':
7230
7234
  return createNamedNormalExpressionNode('unsigned-bit-shift-right', [left, right], token);
7235
+ case '++': {
7236
+ var leftString = createNamedNormalExpressionNode('str', [left], token);
7237
+ var rightString = createNamedNormalExpressionNode('str', [right], token);
7238
+ return createNamedNormalExpressionNode('str', [leftString, rightString], token);
7239
+ }
7231
7240
  case '<':
7232
7241
  return createNamedNormalExpressionNode('<', [left, right], token);
7233
7242
  case '<=':
@@ -7339,7 +7348,7 @@ var AlgebraicParser = /** @class */ (function () {
7339
7348
  // Parentheses
7340
7349
  if (isLParenToken(token)) {
7341
7350
  var positionBefore = this.parseState.position;
7342
- var lamdaFunction = this.parseLamdaFunction();
7351
+ var lamdaFunction = this.parseLambdaFunction();
7343
7352
  if (lamdaFunction) {
7344
7353
  return lamdaFunction;
7345
7354
  }
@@ -7360,6 +7369,9 @@ var AlgebraicParser = /** @class */ (function () {
7360
7369
  var operand = this.parseOperand();
7361
7370
  return fromUnaryAlgebraicToAstNode(token, operand);
7362
7371
  }
7372
+ else if (operatorName === '=>') {
7373
+ return this.parseShorthandLamdaFunction();
7374
+ }
7363
7375
  else {
7364
7376
  throw new Error("Unknown unary operator: ".concat(operatorName));
7365
7377
  }
@@ -7506,6 +7518,8 @@ var AlgebraicParser = /** @class */ (function () {
7506
7518
  case 'or':
7507
7519
  case 'when':
7508
7520
  case 'when-not':
7521
+ case 'do':
7522
+ case 'throw':
7509
7523
  return {
7510
7524
  t: exports.AstNodeType.SpecialExpression,
7511
7525
  n: name_1,
@@ -7522,13 +7536,11 @@ var AlgebraicParser = /** @class */ (function () {
7522
7536
  case 'defn':
7523
7537
  case 'defns':
7524
7538
  case 'try':
7525
- case 'throw':
7526
7539
  case 'recur':
7527
7540
  case 'loop':
7528
7541
  case 'time!':
7529
7542
  case 'doseq':
7530
7543
  case 'for':
7531
- case 'do':
7532
7544
  throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
7533
7545
  default:
7534
7546
  throw new Error("Unknown special expression: ".concat(name_1));
@@ -7545,7 +7557,7 @@ var AlgebraicParser = /** @class */ (function () {
7545
7557
  };
7546
7558
  }
7547
7559
  };
7548
- AlgebraicParser.prototype.parseLamdaFunction = function () {
7560
+ AlgebraicParser.prototype.parseLambdaFunction = function () {
7549
7561
  var _a;
7550
7562
  var firstToken = this.peek();
7551
7563
  this.advance();
@@ -7604,6 +7616,62 @@ var AlgebraicParser = /** @class */ (function () {
7604
7616
  token: getTokenDebugData(firstToken) && firstToken,
7605
7617
  };
7606
7618
  };
7619
+ AlgebraicParser.prototype.parseShorthandLamdaFunction = function () {
7620
+ var _a, _b, _c, _d;
7621
+ var firstToken = this.peek();
7622
+ this.advance();
7623
+ var startPos = this.parseState.position;
7624
+ var exprNode = this.parseExpression();
7625
+ var endPos = this.parseState.position - 1;
7626
+ var arity = 0;
7627
+ var percent1 = 'NOT_SET'; // referring to argument bindings. % = NAKED, %1, %2, %3, etc = WITH_1
7628
+ for (var pos = startPos; pos <= endPos; pos += 1) {
7629
+ var tkn = this.tokenStream.tokens[pos];
7630
+ if (isA_SymbolToken(tkn)) {
7631
+ var match = placeholderRegexp$1.exec(tkn[1]);
7632
+ if (match) {
7633
+ var number = (_a = match[1]) !== null && _a !== void 0 ? _a : '1';
7634
+ if (number === '1') {
7635
+ var mixedPercent1 = (!match[1] && percent1 === 'WITH_1') || (match[1] && percent1 === 'NAKED');
7636
+ if (mixedPercent1)
7637
+ throw new LitsError('Please make up your mind, either use $ or $1', (_b = getTokenDebugData(firstToken)) === null || _b === void 0 ? void 0 : _b.sourceCodeInfo);
7638
+ percent1 = match[1] ? 'WITH_1' : 'NAKED';
7639
+ }
7640
+ arity = Math.max(arity, Number(number));
7641
+ if (arity > 20)
7642
+ throw new LitsError('Can\'t specify more than 20 arguments', (_c = getTokenDebugData(firstToken)) === null || _c === void 0 ? void 0 : _c.sourceCodeInfo);
7643
+ }
7644
+ }
7645
+ if (isA_OperatorToken(tkn, '=>')) {
7646
+ throw new LitsError('Nested shortcut functions are not allowed', (_d = getTokenDebugData(firstToken)) === null || _d === void 0 ? void 0 : _d.sourceCodeInfo);
7647
+ }
7648
+ }
7649
+ var mandatoryArguments = [];
7650
+ for (var i = 1; i <= arity; i += 1) {
7651
+ if (i === 1 && percent1 === 'NAKED')
7652
+ mandatoryArguments.push('$');
7653
+ else
7654
+ mandatoryArguments.push("$".concat(i));
7655
+ }
7656
+ var args = {
7657
+ b: [],
7658
+ m: mandatoryArguments,
7659
+ };
7660
+ var node = {
7661
+ t: exports.AstNodeType.SpecialExpression,
7662
+ n: 'fn',
7663
+ p: [],
7664
+ o: [
7665
+ {
7666
+ as: args,
7667
+ b: [exprNode],
7668
+ a: args.m.length,
7669
+ },
7670
+ ],
7671
+ token: getTokenDebugData(firstToken) && firstToken,
7672
+ };
7673
+ return node;
7674
+ };
7607
7675
  AlgebraicParser.prototype.isAtEnd = function () {
7608
7676
  return this.parseState.position >= this.tokenStream.tokens.length;
7609
7677
  };
@@ -7962,7 +8030,7 @@ function parseToken(tokenStream, parseState) {
7962
8030
 
7963
8031
  var polishIdentifierCharacterClass = '[\\w@%^?=!$<>+*/:-]';
7964
8032
  var polishIdentifierFirstCharacterClass = '[a-zA-Z_@%^?=!$<>+*/-]';
7965
- var algebraicIdentifierCharacterClass = '[\\w$:!]';
8033
+ var algebraicIdentifierCharacterClass = '[\\w$:!?]';
7966
8034
  var algebraicIdentifierFirstCharacterClass = '[a-zA-Z_$]';
7967
8035
 
7968
8036
  var NO_MATCH = [0];
@@ -8269,13 +8337,11 @@ var algebraicReservedNamesRecord = {
8269
8337
  'defn': { value: null, forbidden: true },
8270
8338
  'defns': { value: null, forbidden: true },
8271
8339
  'try': { value: null, forbidden: true },
8272
- 'throw': { value: null, forbidden: true },
8273
8340
  'recur': { value: null, forbidden: true },
8274
8341
  'loop': { value: null, forbidden: true },
8275
8342
  'time!': { value: null, forbidden: true },
8276
8343
  'doseq': { value: null, forbidden: true },
8277
8344
  'for': { value: null, forbidden: true },
8278
- 'do': { value: null, forbidden: true },
8279
8345
  };
8280
8346
 
8281
8347
  var identifierRegExp = new RegExp(algebraicIdentifierCharacterClass);