@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.
@@ -1,4 +1,4 @@
1
1
  export declare const polishIdentifierCharacterClass = "[\\w@%^?=!$<>+*/:-]";
2
2
  export declare const polishIdentifierFirstCharacterClass = "[a-zA-Z_@%^?=!$<>+*/-]";
3
- export declare const algebraicIdentifierCharacterClass = "[\\w$:!]";
3
+ export declare const algebraicIdentifierCharacterClass = "[\\w$:!?]";
4
4
  export declare const algebraicIdentifierFirstCharacterClass = "[a-zA-Z_$]";
@@ -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
  }
@@ -5,7 +5,7 @@ export declare const algebraicSimpleTokenTypes: readonly ["LBrace", "LBracket",
5
5
  export declare const algebraicOnlyValueTokenTypes: ["A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number"];
6
6
  export declare const algebraicValueTokenTypes: readonly ["String", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number"];
7
7
  export declare const algebraicTokenTypes: readonly ["LBrace", "LBracket", "LParen", "RBrace", "RBracket", "RParen", "AlgNotation", "PolNotation", "EndNotation", "String", "A_Whitespace", "A_Operator", "A_Symbol", "A_ReservedSymbol", "A_SingleLineComment", "A_MultiLineComment", "A_Number"];
8
- export declare const AlgebraicOperators: readonly ["!", "~", "=", ",", "=>", "...", ".", "**", "*", "/", "%", "+", "-", "<<", ">>", ">>>", "<", "<=", ">", ">=", "==", "!=", "&", "^", "|", "&&", "||", "??"];
8
+ export declare const AlgebraicOperators: readonly ["!", "~", "=", ",", "=>", "...", ".", "**", "*", "/", "%", "+", "-", "<<", ">>", ">>>", "++", "<", "<=", ">", ">=", "==", "!=", "&", "^", "|", "&&", "||", "??"];
9
9
  export type AlgebraicOperator = typeof AlgebraicOperators[number];
10
10
  export declare function isAlgebraicOperator(operator: string): operator is AlgebraicOperator;
11
11
  export declare function assertAlgebraicOperator(operator: string): asserts operator is AlgebraicOperator;
@@ -390,6 +390,7 @@ var AlgebraicOperators = [
390
390
  '<<', // left shift
391
391
  '>>', // signed right shift
392
392
  '>>>', // unsigned right shift
393
+ '++', // string concatenation
393
394
  '<', // less than
394
395
  '<=', // less than or equal
395
396
  '>', // greater than
@@ -3123,7 +3124,7 @@ var mathNormalExpression = {
3123
3124
  },
3124
3125
  };
3125
3126
 
3126
- var version = "2.0.7";
3127
+ var version = "2.0.9";
3127
3128
 
3128
3129
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3129
3130
  var xyRegexp = /[xy]/g;
@@ -7073,24 +7074,27 @@ function parseString(tokenStream, parseState) {
7073
7074
  };
7074
7075
  }
7075
7076
 
7076
- var exponentiationPrecedence = 8;
7077
+ var exponentiationPrecedence = 9;
7078
+ var placeholderRegexp$1 = /^\$([1-9]\d?)?$/;
7077
7079
  function getPrecedence(operator) {
7078
7080
  var operatorSign = operator[1];
7079
7081
  switch (operatorSign) {
7080
7082
  case '.': // accessor
7081
- return 9;
7083
+ return 10;
7082
7084
  case '**': // exponentiation
7083
7085
  return exponentiationPrecedence;
7084
7086
  case '*': // multiplication
7085
7087
  case '/': // division
7086
7088
  case '%': // remainder
7087
- return 7;
7089
+ return 8;
7088
7090
  case '+': // addition
7089
7091
  case '-': // subtraction
7090
- return 6;
7092
+ return 7;
7091
7093
  case '<<': // left shift
7092
7094
  case '>>': // signed right shift
7093
7095
  case '>>>': // unsigned right shift
7096
+ return 6;
7097
+ case '++': // string concatenation
7094
7098
  return 5;
7095
7099
  case '<': // less than
7096
7100
  case '<=': // less than or equal
@@ -7188,6 +7192,11 @@ function fromBinaryAlgebraicToAstNode(operator, left, right) {
7188
7192
  return createNamedNormalExpressionNode('bit-shift-right', [left, right], token);
7189
7193
  case '>>>':
7190
7194
  return createNamedNormalExpressionNode('unsigned-bit-shift-right', [left, right], token);
7195
+ case '++': {
7196
+ var leftString = createNamedNormalExpressionNode('str', [left], token);
7197
+ var rightString = createNamedNormalExpressionNode('str', [right], token);
7198
+ return createNamedNormalExpressionNode('str', [leftString, rightString], token);
7199
+ }
7191
7200
  case '<':
7192
7201
  return createNamedNormalExpressionNode('<', [left, right], token);
7193
7202
  case '<=':
@@ -7299,7 +7308,7 @@ var AlgebraicParser = /** @class */ (function () {
7299
7308
  // Parentheses
7300
7309
  if (isLParenToken(token)) {
7301
7310
  var positionBefore = this.parseState.position;
7302
- var lamdaFunction = this.parseLamdaFunction();
7311
+ var lamdaFunction = this.parseLambdaFunction();
7303
7312
  if (lamdaFunction) {
7304
7313
  return lamdaFunction;
7305
7314
  }
@@ -7320,6 +7329,9 @@ var AlgebraicParser = /** @class */ (function () {
7320
7329
  var operand = this.parseOperand();
7321
7330
  return fromUnaryAlgebraicToAstNode(token, operand);
7322
7331
  }
7332
+ else if (operatorName === '=>') {
7333
+ return this.parseShorthandLamdaFunction();
7334
+ }
7323
7335
  else {
7324
7336
  throw new Error("Unknown unary operator: ".concat(operatorName));
7325
7337
  }
@@ -7466,6 +7478,8 @@ var AlgebraicParser = /** @class */ (function () {
7466
7478
  case 'or':
7467
7479
  case 'when':
7468
7480
  case 'when-not':
7481
+ case 'do':
7482
+ case 'throw':
7469
7483
  return {
7470
7484
  t: AstNodeType.SpecialExpression,
7471
7485
  n: name_1,
@@ -7482,13 +7496,11 @@ var AlgebraicParser = /** @class */ (function () {
7482
7496
  case 'defn':
7483
7497
  case 'defns':
7484
7498
  case 'try':
7485
- case 'throw':
7486
7499
  case 'recur':
7487
7500
  case 'loop':
7488
7501
  case 'time!':
7489
7502
  case 'doseq':
7490
7503
  case 'for':
7491
- case 'do':
7492
7504
  throw new Error("Special expression ".concat(name_1, " is not available in algebraic notation"));
7493
7505
  default:
7494
7506
  throw new Error("Unknown special expression: ".concat(name_1));
@@ -7505,7 +7517,7 @@ var AlgebraicParser = /** @class */ (function () {
7505
7517
  };
7506
7518
  }
7507
7519
  };
7508
- AlgebraicParser.prototype.parseLamdaFunction = function () {
7520
+ AlgebraicParser.prototype.parseLambdaFunction = function () {
7509
7521
  var _a;
7510
7522
  var firstToken = this.peek();
7511
7523
  this.advance();
@@ -7564,6 +7576,62 @@ var AlgebraicParser = /** @class */ (function () {
7564
7576
  token: getTokenDebugData(firstToken) && firstToken,
7565
7577
  };
7566
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
+ };
7567
7635
  AlgebraicParser.prototype.isAtEnd = function () {
7568
7636
  return this.parseState.position >= this.tokenStream.tokens.length;
7569
7637
  };
@@ -7921,7 +7989,7 @@ function parseToken(tokenStream, parseState) {
7921
7989
  }
7922
7990
 
7923
7991
  var polishIdentifierCharacterClass = '[\\w@%^?=!$<>+*/:-]';
7924
- var algebraicIdentifierCharacterClass = '[\\w$:!]';
7992
+ var algebraicIdentifierCharacterClass = '[\\w$:!?]';
7925
7993
  var algebraicIdentifierFirstCharacterClass = '[a-zA-Z_$]';
7926
7994
 
7927
7995
  var NO_MATCH = [0];
@@ -8228,13 +8296,11 @@ var algebraicReservedNamesRecord = {
8228
8296
  'defn': { value: null, forbidden: true },
8229
8297
  'defns': { value: null, forbidden: true },
8230
8298
  'try': { value: null, forbidden: true },
8231
- 'throw': { value: null, forbidden: true },
8232
8299
  'recur': { value: null, forbidden: true },
8233
8300
  'loop': { value: null, forbidden: true },
8234
8301
  'time!': { value: null, forbidden: true },
8235
8302
  'doseq': { value: null, forbidden: true },
8236
8303
  'for': { value: null, forbidden: true },
8237
- 'do': { value: null, forbidden: true },
8238
8304
  };
8239
8305
 
8240
8306
  var identifierRegExp = new RegExp(algebraicIdentifierCharacterClass);