@mojir/lits 2.0.20 → 2.0.22

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.
@@ -40,7 +40,9 @@ export declare class Lits {
40
40
  run(program: string, params?: LitsParams): unknown;
41
41
  context(program: string, params?: LitsParams): Context;
42
42
  analyze(program: string, params?: LitsParams): Analysis;
43
- tokenize(program: string, tokenizeParams?: Pick<TokenizeParams, 'filePath'>): TokenStream;
43
+ tokenize(program: string, tokenizeParams?: Pick<TokenizeParams, 'filePath'> & {
44
+ minify?: boolean;
45
+ }): TokenStream;
44
46
  parse(tokenStream: TokenStream): Ast;
45
47
  evaluate(ast: Ast, params: LitsParams): Any;
46
48
  transform(tokenStream: TokenStream, transformer: (name: string) => string): TokenStream;
@@ -0,0 +1,4 @@
1
+ import type { TokenStream } from './interface';
2
+ export declare function minifyTokenStream(tokenStream: TokenStream, { removeWhiteSpace }: {
3
+ removeWhiteSpace: boolean;
4
+ }): TokenStream;
@@ -6103,6 +6103,28 @@ function analyze(ast, params) {
6103
6103
  };
6104
6104
  }
6105
6105
 
6106
+ function minifyTokenStream(tokenStream, _a) {
6107
+ var removeWhiteSpace = _a.removeWhiteSpace;
6108
+ var tokens = tokenStream.tokens
6109
+ .filter(function (token) {
6110
+ if (isP_CommentToken(token)
6111
+ || isA_CommentToken(token)
6112
+ || isA_MultiLineCommentToken(token)
6113
+ || (removeWhiteSpace && isA_WhitespaceToken(token))
6114
+ || (removeWhiteSpace && isP_WhitespaceToken(token))) {
6115
+ return false;
6116
+ }
6117
+ return true;
6118
+ })
6119
+ .map(function (token) {
6120
+ if (isA_WhitespaceToken(token) || isP_WhitespaceToken(token)) {
6121
+ return __assign(__assign({}, token), { value: ' ' });
6122
+ }
6123
+ return token;
6124
+ });
6125
+ return __assign(__assign({}, tokenStream), { tokens: tokens });
6126
+ }
6127
+
6106
6128
  function parseSymbol(tokenStream, parseState) {
6107
6129
  var _a;
6108
6130
  var tkn = asToken(tokenStream.tokens[parseState.position++]);
@@ -7621,7 +7643,7 @@ function parsePolishToken(tokenStream, parseState) {
7621
7643
  }
7622
7644
 
7623
7645
  function parse(tokenStream) {
7624
- tokenStream = removeUnnecessaryTokens(tokenStream);
7646
+ tokenStream = minifyTokenStream(tokenStream, { removeWhiteSpace: true });
7625
7647
  var algebraic = tokenStream.algebraic;
7626
7648
  var ast = {
7627
7649
  b: [],
@@ -7642,19 +7664,6 @@ function parse(tokenStream) {
7642
7664
  }
7643
7665
  return ast;
7644
7666
  }
7645
- function removeUnnecessaryTokens(tokenStream) {
7646
- var tokens = tokenStream.tokens.filter(function (token) {
7647
- if (isP_CommentToken(token)
7648
- || isA_CommentToken(token)
7649
- || isA_MultiLineCommentToken(token)
7650
- || isA_WhitespaceToken(token)
7651
- || isP_WhitespaceToken(token)) {
7652
- return false;
7653
- }
7654
- return true;
7655
- });
7656
- return __assign(__assign({}, tokenStream), { tokens: tokens });
7657
- }
7658
7667
  function parseToken(tokenStream, parseState) {
7659
7668
  return parsePolishToken(tokenStream, parseState);
7660
7669
  }
@@ -8481,7 +8490,8 @@ var Lits = /** @class */ (function () {
8481
8490
  if (tokenizeParams === void 0) { tokenizeParams = {}; }
8482
8491
  var debug = this.debug;
8483
8492
  var algebraic = this.algebraic;
8484
- return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8493
+ var tokenStream = tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
8494
+ return tokenizeParams.minify ? minifyTokenStream(tokenStream, { removeWhiteSpace: false }) : tokenStream;
8485
8495
  };
8486
8496
  Lits.prototype.parse = function (tokenStream) {
8487
8497
  return parse(tokenStream);