@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.
package/dist/index.js CHANGED
@@ -3162,7 +3162,7 @@ var mathNormalExpression = {
3162
3162
  },
3163
3163
  };
3164
3164
 
3165
- var version = "2.0.4";
3165
+ var version = "2.0.6";
3166
3166
 
3167
3167
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3168
3168
  var xyRegexp = /[xy]/g;
@@ -7385,14 +7385,22 @@ var AlgebraicParser = /** @class */ (function () {
7385
7385
  return parseReservedSymbol(this.tokenStream, this.parseState);
7386
7386
  case 'PolNotation': {
7387
7387
  this.parseState.algebraic = false;
7388
- var astNode = void 0;
7388
+ var astNodes = [];
7389
7389
  this.advance();
7390
7390
  do {
7391
- astNode = this.parseState.parseToken(this.tokenStream, this.parseState);
7391
+ astNodes.push(this.parseState.parseToken(this.tokenStream, this.parseState));
7392
7392
  } while (!isEndNotationToken(this.peek()));
7393
7393
  this.advance();
7394
7394
  this.parseState.algebraic = true;
7395
- return astNode;
7395
+ if (astNodes.length === 1) {
7396
+ return astNodes[0];
7397
+ }
7398
+ return {
7399
+ t: exports.AstNodeType.SpecialExpression,
7400
+ n: 'do',
7401
+ p: astNodes,
7402
+ token: getTokenDebugData(token) && token,
7403
+ };
7396
7404
  }
7397
7405
  case 'AlgNotation': {
7398
7406
  this.advance();
@@ -7887,13 +7895,21 @@ function parsePolishToken(tokenStream, parseState) {
7887
7895
  return node;
7888
7896
  }
7889
7897
  case 'PolNotation': {
7890
- var node = void 0;
7898
+ var astNodes = [];
7891
7899
  parseState.position += 1;
7892
7900
  do {
7893
- node = parsePolishToken(tokenStream, parseState);
7901
+ astNodes.push(parsePolishToken(tokenStream, parseState));
7894
7902
  } while (!isEndNotationToken(asToken(tokenStream.tokens[parseState.position])));
7895
7903
  parseState.position += 1;
7896
- return node;
7904
+ if (astNodes.length === 1) {
7905
+ return astNodes[0];
7906
+ }
7907
+ return {
7908
+ t: exports.AstNodeType.SpecialExpression,
7909
+ n: 'do',
7910
+ p: astNodes,
7911
+ token: astNodes[0].token,
7912
+ };
7897
7913
  }
7898
7914
  case 'P_CollectionAccessor':
7899
7915
  case 'P_Modifier':
@@ -8814,10 +8830,9 @@ var Lits = /** @class */ (function () {
8814
8830
  return analyze(ast, params);
8815
8831
  };
8816
8832
  Lits.prototype.tokenize = function (program, tokenizeParams) {
8817
- var _a, _b;
8818
8833
  if (tokenizeParams === void 0) { tokenizeParams = {}; }
8819
- var debug = (_a = tokenizeParams.debug) !== null && _a !== void 0 ? _a : this.debug;
8820
- var algebraic = (_b = tokenizeParams.algebraic) !== null && _b !== void 0 ? _b : this.algebraic;
8834
+ var debug = this.debug;
8835
+ var algebraic = this.algebraic;
8821
8836
  return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8822
8837
  };
8823
8838
  Lits.prototype.parse = function (tokenStream) {
@@ -8837,12 +8852,7 @@ var Lits = /** @class */ (function () {
8837
8852
  var _a;
8838
8853
  if (params === void 0) { params = {}; }
8839
8854
  var fnName = 'FN_2eb7b316-471c-5bfa-90cb-d3dfd9164a59';
8840
- var paramsString = fnParams
8841
- .map(function (_, index) {
8842
- return "".concat(fnName, "_").concat(index);
8843
- })
8844
- .join(' ');
8845
- var program = "(".concat(fnName, " ").concat(paramsString, ")");
8855
+ var program = this.generateApplyFunctionCall(fnName, fnParams);
8846
8856
  var ast = this.generateAst(program, params);
8847
8857
  var hostValues = fnParams.reduce(function (result, param, index) {
8848
8858
  result["".concat(fnName, "_").concat(index)] = param;
@@ -8851,20 +8861,26 @@ var Lits = /** @class */ (function () {
8851
8861
  params.values = __assign(__assign({}, params.values), hostValues);
8852
8862
  return this.evaluate(ast, params);
8853
8863
  };
8864
+ Lits.prototype.generateApplyFunctionCall = function (fnName, fnParams) {
8865
+ var paramsString = fnParams
8866
+ .map(function (_, index) {
8867
+ return "".concat(fnName, "_").concat(index);
8868
+ })
8869
+ .join(this.algebraic ? ', ' : ' ');
8870
+ return this.algebraic ? "".concat(fnName, "(").concat(paramsString, ")") : "(".concat(fnName, " ").concat(paramsString, ")");
8871
+ };
8854
8872
  Lits.prototype.generateAst = function (program, params) {
8855
- var _a, _b, _c;
8873
+ var _a;
8856
8874
  if (this.astCache) {
8857
8875
  var cachedAst = this.astCache.get(program);
8858
8876
  if (cachedAst)
8859
8877
  return cachedAst;
8860
8878
  }
8861
8879
  var tokenStream = this.tokenize(program, {
8862
- debug: (_a = params.debug) !== null && _a !== void 0 ? _a : this.debug,
8863
8880
  filePath: params.filePath,
8864
- algebraic: (_b = params.algebraic) !== null && _b !== void 0 ? _b : this.algebraic,
8865
8881
  });
8866
8882
  var ast = this.parse(tokenStream);
8867
- (_c = this.astCache) === null || _c === void 0 ? void 0 : _c.set(program, ast);
8883
+ (_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
8868
8884
  return ast;
8869
8885
  };
8870
8886
  return Lits;