@mojir/lits 2.0.4 → 2.0.6

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.
@@ -3125,7 +3125,7 @@ var mathNormalExpression = {
3125
3125
  },
3126
3126
  };
3127
3127
 
3128
- var version = "2.0.4";
3128
+ var version = "2.0.6";
3129
3129
 
3130
3130
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3131
3131
  var xyRegexp = /[xy]/g;
@@ -7347,14 +7347,22 @@ var AlgebraicParser = /** @class */ (function () {
7347
7347
  return parseReservedSymbol(this.tokenStream, this.parseState);
7348
7348
  case 'PolNotation': {
7349
7349
  this.parseState.algebraic = false;
7350
- var astNode = void 0;
7350
+ var astNodes = [];
7351
7351
  this.advance();
7352
7352
  do {
7353
- astNode = this.parseState.parseToken(this.tokenStream, this.parseState);
7353
+ astNodes.push(this.parseState.parseToken(this.tokenStream, this.parseState));
7354
7354
  } while (!isEndNotationToken(this.peek()));
7355
7355
  this.advance();
7356
7356
  this.parseState.algebraic = true;
7357
- return astNode;
7357
+ if (astNodes.length === 1) {
7358
+ return astNodes[0];
7359
+ }
7360
+ return {
7361
+ t: AstNodeType.SpecialExpression,
7362
+ n: 'do',
7363
+ p: astNodes,
7364
+ token: getTokenDebugData(token) && token,
7365
+ };
7358
7366
  }
7359
7367
  case 'AlgNotation': {
7360
7368
  this.advance();
@@ -7849,13 +7857,21 @@ function parsePolishToken(tokenStream, parseState) {
7849
7857
  return node;
7850
7858
  }
7851
7859
  case 'PolNotation': {
7852
- var node = void 0;
7860
+ var astNodes = [];
7853
7861
  parseState.position += 1;
7854
7862
  do {
7855
- node = parsePolishToken(tokenStream, parseState);
7863
+ astNodes.push(parsePolishToken(tokenStream, parseState));
7856
7864
  } while (!isEndNotationToken(asToken(tokenStream.tokens[parseState.position])));
7857
7865
  parseState.position += 1;
7858
- return node;
7866
+ if (astNodes.length === 1) {
7867
+ return astNodes[0];
7868
+ }
7869
+ return {
7870
+ t: AstNodeType.SpecialExpression,
7871
+ n: 'do',
7872
+ p: astNodes,
7873
+ token: astNodes[0].token,
7874
+ };
7859
7875
  }
7860
7876
  case 'P_CollectionAccessor':
7861
7877
  case 'P_Modifier':
@@ -8775,10 +8791,9 @@ var Lits = /** @class */ (function () {
8775
8791
  return analyze(ast, params);
8776
8792
  };
8777
8793
  Lits.prototype.tokenize = function (program, tokenizeParams) {
8778
- var _a, _b;
8779
8794
  if (tokenizeParams === void 0) { tokenizeParams = {}; }
8780
- var debug = (_a = tokenizeParams.debug) !== null && _a !== void 0 ? _a : this.debug;
8781
- var algebraic = (_b = tokenizeParams.algebraic) !== null && _b !== void 0 ? _b : this.algebraic;
8795
+ var debug = this.debug;
8796
+ var algebraic = this.algebraic;
8782
8797
  return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8783
8798
  };
8784
8799
  Lits.prototype.parse = function (tokenStream) {
@@ -8798,12 +8813,7 @@ var Lits = /** @class */ (function () {
8798
8813
  var _a;
8799
8814
  if (params === void 0) { params = {}; }
8800
8815
  var fnName = 'FN_2eb7b316-471c-5bfa-90cb-d3dfd9164a59';
8801
- var paramsString = fnParams
8802
- .map(function (_, index) {
8803
- return "".concat(fnName, "_").concat(index);
8804
- })
8805
- .join(' ');
8806
- var program = "(".concat(fnName, " ").concat(paramsString, ")");
8816
+ var program = this.generateApplyFunctionCall(fnName, fnParams);
8807
8817
  var ast = this.generateAst(program, params);
8808
8818
  var hostValues = fnParams.reduce(function (result, param, index) {
8809
8819
  result["".concat(fnName, "_").concat(index)] = param;
@@ -8812,20 +8822,26 @@ var Lits = /** @class */ (function () {
8812
8822
  params.values = __assign(__assign({}, params.values), hostValues);
8813
8823
  return this.evaluate(ast, params);
8814
8824
  };
8825
+ Lits.prototype.generateApplyFunctionCall = function (fnName, fnParams) {
8826
+ var paramsString = fnParams
8827
+ .map(function (_, index) {
8828
+ return "".concat(fnName, "_").concat(index);
8829
+ })
8830
+ .join(this.algebraic ? ', ' : ' ');
8831
+ return this.algebraic ? "".concat(fnName, "(").concat(paramsString, ")") : "(".concat(fnName, " ").concat(paramsString, ")");
8832
+ };
8815
8833
  Lits.prototype.generateAst = function (program, params) {
8816
- var _a, _b, _c;
8834
+ var _a;
8817
8835
  if (this.astCache) {
8818
8836
  var cachedAst = this.astCache.get(program);
8819
8837
  if (cachedAst)
8820
8838
  return cachedAst;
8821
8839
  }
8822
8840
  var tokenStream = this.tokenize(program, {
8823
- debug: (_a = params.debug) !== null && _a !== void 0 ? _a : this.debug,
8824
8841
  filePath: params.filePath,
8825
- algebraic: (_b = params.algebraic) !== null && _b !== void 0 ? _b : this.algebraic,
8826
8842
  });
8827
8843
  var ast = this.parse(tokenStream);
8828
- (_c = this.astCache) === null || _c === void 0 ? void 0 : _c.set(program, ast);
8844
+ (_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
8829
8845
  return ast;
8830
8846
  };
8831
8847
  return Lits;