@mojir/lits 2.0.3 → 2.0.5

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.3";
95
+ var version = "2.0.5";
96
96
 
97
97
  var AstNodeType;
98
98
  (function (AstNodeType) {
@@ -7351,14 +7351,22 @@ var AlgebraicParser = /** @class */ (function () {
7351
7351
  return parseReservedSymbol(this.tokenStream, this.parseState);
7352
7352
  case 'PolNotation': {
7353
7353
  this.parseState.algebraic = false;
7354
- var astNode = void 0;
7354
+ var astNodes = [];
7355
7355
  this.advance();
7356
7356
  do {
7357
- astNode = this.parseState.parseToken(this.tokenStream, this.parseState);
7357
+ astNodes.push(this.parseState.parseToken(this.tokenStream, this.parseState));
7358
7358
  } while (!isEndNotationToken(this.peek()));
7359
7359
  this.advance();
7360
7360
  this.parseState.algebraic = true;
7361
- return astNode;
7361
+ if (astNodes.length === 1) {
7362
+ return astNodes[0];
7363
+ }
7364
+ return {
7365
+ t: AstNodeType.SpecialExpression,
7366
+ n: 'do',
7367
+ p: astNodes,
7368
+ token: getTokenDebugData(token) && token,
7369
+ };
7362
7370
  }
7363
7371
  case 'AlgNotation': {
7364
7372
  this.advance();
@@ -7912,7 +7920,7 @@ function parseToken(tokenStream, parseState) {
7912
7920
 
7913
7921
  var polishIdentifierCharacterClass = '[\\w@%^?=!$<>+*/:-]';
7914
7922
  var polishIdentifierFirstCharacterClass = '[a-zA-Z_@%^?=!$<>+*/-]';
7915
- var algebraicIdentifierCharacterClass = '[\\w$:]';
7923
+ var algebraicIdentifierCharacterClass = '[\\w$:!]';
7916
7924
  var algebraicIdentifierFirstCharacterClass = '[a-zA-Z_$]';
7917
7925
 
7918
7926
  var NO_MATCH = [0];
@@ -8780,10 +8788,9 @@ var Lits = /** @class */ (function () {
8780
8788
  return analyze(ast, params);
8781
8789
  };
8782
8790
  Lits.prototype.tokenize = function (program, tokenizeParams) {
8783
- var _a, _b;
8784
8791
  if (tokenizeParams === void 0) { tokenizeParams = {}; }
8785
- var debug = (_a = tokenizeParams.debug) !== null && _a !== void 0 ? _a : this.debug;
8786
- var algebraic = (_b = tokenizeParams.algebraic) !== null && _b !== void 0 ? _b : this.algebraic;
8792
+ var debug = this.debug;
8793
+ var algebraic = this.algebraic;
8787
8794
  return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8788
8795
  };
8789
8796
  Lits.prototype.parse = function (tokenStream) {
@@ -8803,12 +8810,7 @@ var Lits = /** @class */ (function () {
8803
8810
  var _a;
8804
8811
  if (params === void 0) { params = {}; }
8805
8812
  var fnName = 'FN_2eb7b316-471c-5bfa-90cb-d3dfd9164a59';
8806
- var paramsString = fnParams
8807
- .map(function (_, index) {
8808
- return "".concat(fnName, "_").concat(index);
8809
- })
8810
- .join(' ');
8811
- var program = "(".concat(fnName, " ").concat(paramsString, ")");
8813
+ var program = this.generateApplyFunctionCall(fnName, fnParams);
8812
8814
  var ast = this.generateAst(program, params);
8813
8815
  var hostValues = fnParams.reduce(function (result, param, index) {
8814
8816
  result["".concat(fnName, "_").concat(index)] = param;
@@ -8817,20 +8819,26 @@ var Lits = /** @class */ (function () {
8817
8819
  params.values = __assign(__assign({}, params.values), hostValues);
8818
8820
  return this.evaluate(ast, params);
8819
8821
  };
8822
+ Lits.prototype.generateApplyFunctionCall = function (fnName, fnParams) {
8823
+ var paramsString = fnParams
8824
+ .map(function (_, index) {
8825
+ return "".concat(fnName, "_").concat(index);
8826
+ })
8827
+ .join(this.algebraic ? ', ' : ' ');
8828
+ return this.algebraic ? "".concat(fnName, "(").concat(paramsString, ")") : "(".concat(fnName, " ").concat(paramsString, ")");
8829
+ };
8820
8830
  Lits.prototype.generateAst = function (program, params) {
8821
- var _a, _b, _c;
8831
+ var _a;
8822
8832
  if (this.astCache) {
8823
8833
  var cachedAst = this.astCache.get(program);
8824
8834
  if (cachedAst)
8825
8835
  return cachedAst;
8826
8836
  }
8827
8837
  var tokenStream = this.tokenize(program, {
8828
- debug: (_a = params.debug) !== null && _a !== void 0 ? _a : this.debug,
8829
8838
  filePath: params.filePath,
8830
- algebraic: (_b = params.algebraic) !== null && _b !== void 0 ? _b : this.algebraic,
8831
8839
  });
8832
8840
  var ast = this.parse(tokenStream);
8833
- (_c = this.astCache) === null || _c === void 0 ? void 0 : _c.set(program, ast);
8841
+ (_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
8834
8842
  return ast;
8835
8843
  };
8836
8844
  return Lits;
@@ -23,8 +23,6 @@ export interface LitsParams {
23
23
  lazyValues?: Record<string, LazyValue>;
24
24
  jsFunctions?: Record<string, JsFunction>;
25
25
  filePath?: string;
26
- debug?: boolean;
27
- algebraic?: boolean;
28
26
  }
29
27
  interface LitsConfig {
30
28
  initialCache?: Record<string, Ast>;
@@ -42,12 +40,13 @@ export declare class Lits {
42
40
  run(program: string, params?: LitsParams): unknown;
43
41
  context(program: string, params?: LitsParams): Context;
44
42
  analyze(program: string, params?: LitsParams): Analysis;
45
- tokenize(program: string, tokenizeParams?: TokenizeParams): TokenStream;
43
+ tokenize(program: string, tokenizeParams?: Pick<TokenizeParams, 'filePath'>): TokenStream;
46
44
  parse(tokenStream: TokenStream): Ast;
47
45
  evaluate(ast: Ast, params: LitsParams): Any;
48
46
  transform(tokenStream: TokenStream, transformer: (name: string) => string): TokenStream;
49
47
  untokenize(tokenStream: TokenStream): string;
50
48
  apply(fn: LitsFunction, fnParams: unknown[], params?: LitsParams): Any;
49
+ private generateApplyFunctionCall;
51
50
  private generateAst;
52
51
  }
53
52
  export {};
@@ -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_$]";
@@ -16,7 +16,7 @@ export interface TokenStream {
16
16
  filePath?: string;
17
17
  }
18
18
  export interface TokenizeParams {
19
- debug?: boolean;
19
+ debug: boolean;
20
+ algebraic: boolean;
20
21
  filePath?: string;
21
- algebraic?: boolean;
22
22
  }
package/dist/index.esm.js CHANGED
@@ -3160,7 +3160,7 @@ var mathNormalExpression = {
3160
3160
  },
3161
3161
  };
3162
3162
 
3163
- var version = "2.0.3";
3163
+ var version = "2.0.5";
3164
3164
 
3165
3165
  var uuidTemplate = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
3166
3166
  var xyRegexp = /[xy]/g;
@@ -7383,14 +7383,22 @@ var AlgebraicParser = /** @class */ (function () {
7383
7383
  return parseReservedSymbol(this.tokenStream, this.parseState);
7384
7384
  case 'PolNotation': {
7385
7385
  this.parseState.algebraic = false;
7386
- var astNode = void 0;
7386
+ var astNodes = [];
7387
7387
  this.advance();
7388
7388
  do {
7389
- astNode = this.parseState.parseToken(this.tokenStream, this.parseState);
7389
+ astNodes.push(this.parseState.parseToken(this.tokenStream, this.parseState));
7390
7390
  } while (!isEndNotationToken(this.peek()));
7391
7391
  this.advance();
7392
7392
  this.parseState.algebraic = true;
7393
- return astNode;
7393
+ if (astNodes.length === 1) {
7394
+ return astNodes[0];
7395
+ }
7396
+ return {
7397
+ t: AstNodeType.SpecialExpression,
7398
+ n: 'do',
7399
+ p: astNodes,
7400
+ token: getTokenDebugData(token) && token,
7401
+ };
7394
7402
  }
7395
7403
  case 'AlgNotation': {
7396
7404
  this.advance();
@@ -7944,7 +7952,7 @@ function parseToken(tokenStream, parseState) {
7944
7952
 
7945
7953
  var polishIdentifierCharacterClass = '[\\w@%^?=!$<>+*/:-]';
7946
7954
  var polishIdentifierFirstCharacterClass = '[a-zA-Z_@%^?=!$<>+*/-]';
7947
- var algebraicIdentifierCharacterClass = '[\\w$:]';
7955
+ var algebraicIdentifierCharacterClass = '[\\w$:!]';
7948
7956
  var algebraicIdentifierFirstCharacterClass = '[a-zA-Z_$]';
7949
7957
 
7950
7958
  var NO_MATCH = [0];
@@ -8812,10 +8820,9 @@ var Lits = /** @class */ (function () {
8812
8820
  return analyze(ast, params);
8813
8821
  };
8814
8822
  Lits.prototype.tokenize = function (program, tokenizeParams) {
8815
- var _a, _b;
8816
8823
  if (tokenizeParams === void 0) { tokenizeParams = {}; }
8817
- var debug = (_a = tokenizeParams.debug) !== null && _a !== void 0 ? _a : this.debug;
8818
- var algebraic = (_b = tokenizeParams.algebraic) !== null && _b !== void 0 ? _b : this.algebraic;
8824
+ var debug = this.debug;
8825
+ var algebraic = this.algebraic;
8819
8826
  return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8820
8827
  };
8821
8828
  Lits.prototype.parse = function (tokenStream) {
@@ -8835,12 +8842,7 @@ var Lits = /** @class */ (function () {
8835
8842
  var _a;
8836
8843
  if (params === void 0) { params = {}; }
8837
8844
  var fnName = 'FN_2eb7b316-471c-5bfa-90cb-d3dfd9164a59';
8838
- var paramsString = fnParams
8839
- .map(function (_, index) {
8840
- return "".concat(fnName, "_").concat(index);
8841
- })
8842
- .join(' ');
8843
- var program = "(".concat(fnName, " ").concat(paramsString, ")");
8845
+ var program = this.generateApplyFunctionCall(fnName, fnParams);
8844
8846
  var ast = this.generateAst(program, params);
8845
8847
  var hostValues = fnParams.reduce(function (result, param, index) {
8846
8848
  result["".concat(fnName, "_").concat(index)] = param;
@@ -8849,20 +8851,26 @@ var Lits = /** @class */ (function () {
8849
8851
  params.values = __assign(__assign({}, params.values), hostValues);
8850
8852
  return this.evaluate(ast, params);
8851
8853
  };
8854
+ Lits.prototype.generateApplyFunctionCall = function (fnName, fnParams) {
8855
+ var paramsString = fnParams
8856
+ .map(function (_, index) {
8857
+ return "".concat(fnName, "_").concat(index);
8858
+ })
8859
+ .join(this.algebraic ? ', ' : ' ');
8860
+ return this.algebraic ? "".concat(fnName, "(").concat(paramsString, ")") : "(".concat(fnName, " ").concat(paramsString, ")");
8861
+ };
8852
8862
  Lits.prototype.generateAst = function (program, params) {
8853
- var _a, _b, _c;
8863
+ var _a;
8854
8864
  if (this.astCache) {
8855
8865
  var cachedAst = this.astCache.get(program);
8856
8866
  if (cachedAst)
8857
8867
  return cachedAst;
8858
8868
  }
8859
8869
  var tokenStream = this.tokenize(program, {
8860
- debug: (_a = params.debug) !== null && _a !== void 0 ? _a : this.debug,
8861
8870
  filePath: params.filePath,
8862
- algebraic: (_b = params.algebraic) !== null && _b !== void 0 ? _b : this.algebraic,
8863
8871
  });
8864
8872
  var ast = this.parse(tokenStream);
8865
- (_c = this.astCache) === null || _c === void 0 ? void 0 : _c.set(program, ast);
8873
+ (_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
8866
8874
  return ast;
8867
8875
  };
8868
8876
  return Lits;