@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/cli/cli.js +36 -20
- package/dist/cli/src/Lits/Lits.d.ts +2 -3
- package/dist/cli/src/tokenizer/interface.d.ts +2 -2
- package/dist/index.esm.js +36 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +36 -20
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +36 -20
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/Lits/Lits.d.ts +2 -3
- package/dist/src/tokenizer/interface.d.ts +2 -2
- package/dist/testFramework.esm.js +36 -20
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +36 -20
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
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.
|
|
95
|
+
var version = "2.0.6";
|
|
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
|
|
7354
|
+
var astNodes = [];
|
|
7355
7355
|
this.advance();
|
|
7356
7356
|
do {
|
|
7357
|
-
|
|
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
|
-
|
|
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();
|
|
@@ -7853,13 +7861,21 @@ function parsePolishToken(tokenStream, parseState) {
|
|
|
7853
7861
|
return node;
|
|
7854
7862
|
}
|
|
7855
7863
|
case 'PolNotation': {
|
|
7856
|
-
var
|
|
7864
|
+
var astNodes = [];
|
|
7857
7865
|
parseState.position += 1;
|
|
7858
7866
|
do {
|
|
7859
|
-
|
|
7867
|
+
astNodes.push(parsePolishToken(tokenStream, parseState));
|
|
7860
7868
|
} while (!isEndNotationToken(asToken(tokenStream.tokens[parseState.position])));
|
|
7861
7869
|
parseState.position += 1;
|
|
7862
|
-
|
|
7870
|
+
if (astNodes.length === 1) {
|
|
7871
|
+
return astNodes[0];
|
|
7872
|
+
}
|
|
7873
|
+
return {
|
|
7874
|
+
t: AstNodeType.SpecialExpression,
|
|
7875
|
+
n: 'do',
|
|
7876
|
+
p: astNodes,
|
|
7877
|
+
token: astNodes[0].token,
|
|
7878
|
+
};
|
|
7863
7879
|
}
|
|
7864
7880
|
case 'P_CollectionAccessor':
|
|
7865
7881
|
case 'P_Modifier':
|
|
@@ -8780,10 +8796,9 @@ var Lits = /** @class */ (function () {
|
|
|
8780
8796
|
return analyze(ast, params);
|
|
8781
8797
|
};
|
|
8782
8798
|
Lits.prototype.tokenize = function (program, tokenizeParams) {
|
|
8783
|
-
var _a, _b;
|
|
8784
8799
|
if (tokenizeParams === void 0) { tokenizeParams = {}; }
|
|
8785
|
-
var debug =
|
|
8786
|
-
var algebraic =
|
|
8800
|
+
var debug = this.debug;
|
|
8801
|
+
var algebraic = this.algebraic;
|
|
8787
8802
|
return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
|
|
8788
8803
|
};
|
|
8789
8804
|
Lits.prototype.parse = function (tokenStream) {
|
|
@@ -8803,12 +8818,7 @@ var Lits = /** @class */ (function () {
|
|
|
8803
8818
|
var _a;
|
|
8804
8819
|
if (params === void 0) { params = {}; }
|
|
8805
8820
|
var fnName = 'FN_2eb7b316-471c-5bfa-90cb-d3dfd9164a59';
|
|
8806
|
-
var
|
|
8807
|
-
.map(function (_, index) {
|
|
8808
|
-
return "".concat(fnName, "_").concat(index);
|
|
8809
|
-
})
|
|
8810
|
-
.join(' ');
|
|
8811
|
-
var program = "(".concat(fnName, " ").concat(paramsString, ")");
|
|
8821
|
+
var program = this.generateApplyFunctionCall(fnName, fnParams);
|
|
8812
8822
|
var ast = this.generateAst(program, params);
|
|
8813
8823
|
var hostValues = fnParams.reduce(function (result, param, index) {
|
|
8814
8824
|
result["".concat(fnName, "_").concat(index)] = param;
|
|
@@ -8817,20 +8827,26 @@ var Lits = /** @class */ (function () {
|
|
|
8817
8827
|
params.values = __assign(__assign({}, params.values), hostValues);
|
|
8818
8828
|
return this.evaluate(ast, params);
|
|
8819
8829
|
};
|
|
8830
|
+
Lits.prototype.generateApplyFunctionCall = function (fnName, fnParams) {
|
|
8831
|
+
var paramsString = fnParams
|
|
8832
|
+
.map(function (_, index) {
|
|
8833
|
+
return "".concat(fnName, "_").concat(index);
|
|
8834
|
+
})
|
|
8835
|
+
.join(this.algebraic ? ', ' : ' ');
|
|
8836
|
+
return this.algebraic ? "".concat(fnName, "(").concat(paramsString, ")") : "(".concat(fnName, " ").concat(paramsString, ")");
|
|
8837
|
+
};
|
|
8820
8838
|
Lits.prototype.generateAst = function (program, params) {
|
|
8821
|
-
var _a
|
|
8839
|
+
var _a;
|
|
8822
8840
|
if (this.astCache) {
|
|
8823
8841
|
var cachedAst = this.astCache.get(program);
|
|
8824
8842
|
if (cachedAst)
|
|
8825
8843
|
return cachedAst;
|
|
8826
8844
|
}
|
|
8827
8845
|
var tokenStream = this.tokenize(program, {
|
|
8828
|
-
debug: (_a = params.debug) !== null && _a !== void 0 ? _a : this.debug,
|
|
8829
8846
|
filePath: params.filePath,
|
|
8830
|
-
algebraic: (_b = params.algebraic) !== null && _b !== void 0 ? _b : this.algebraic,
|
|
8831
8847
|
});
|
|
8832
8848
|
var ast = this.parse(tokenStream);
|
|
8833
|
-
(
|
|
8849
|
+
(_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
|
|
8834
8850
|
return ast;
|
|
8835
8851
|
};
|
|
8836
8852
|
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 {};
|
package/dist/index.esm.js
CHANGED
|
@@ -3160,7 +3160,7 @@ var mathNormalExpression = {
|
|
|
3160
3160
|
},
|
|
3161
3161
|
};
|
|
3162
3162
|
|
|
3163
|
-
var version = "2.0.
|
|
3163
|
+
var version = "2.0.6";
|
|
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
|
|
7386
|
+
var astNodes = [];
|
|
7387
7387
|
this.advance();
|
|
7388
7388
|
do {
|
|
7389
|
-
|
|
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
|
-
|
|
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();
|
|
@@ -7885,13 +7893,21 @@ function parsePolishToken(tokenStream, parseState) {
|
|
|
7885
7893
|
return node;
|
|
7886
7894
|
}
|
|
7887
7895
|
case 'PolNotation': {
|
|
7888
|
-
var
|
|
7896
|
+
var astNodes = [];
|
|
7889
7897
|
parseState.position += 1;
|
|
7890
7898
|
do {
|
|
7891
|
-
|
|
7899
|
+
astNodes.push(parsePolishToken(tokenStream, parseState));
|
|
7892
7900
|
} while (!isEndNotationToken(asToken(tokenStream.tokens[parseState.position])));
|
|
7893
7901
|
parseState.position += 1;
|
|
7894
|
-
|
|
7902
|
+
if (astNodes.length === 1) {
|
|
7903
|
+
return astNodes[0];
|
|
7904
|
+
}
|
|
7905
|
+
return {
|
|
7906
|
+
t: AstNodeType.SpecialExpression,
|
|
7907
|
+
n: 'do',
|
|
7908
|
+
p: astNodes,
|
|
7909
|
+
token: astNodes[0].token,
|
|
7910
|
+
};
|
|
7895
7911
|
}
|
|
7896
7912
|
case 'P_CollectionAccessor':
|
|
7897
7913
|
case 'P_Modifier':
|
|
@@ -8812,10 +8828,9 @@ var Lits = /** @class */ (function () {
|
|
|
8812
8828
|
return analyze(ast, params);
|
|
8813
8829
|
};
|
|
8814
8830
|
Lits.prototype.tokenize = function (program, tokenizeParams) {
|
|
8815
|
-
var _a, _b;
|
|
8816
8831
|
if (tokenizeParams === void 0) { tokenizeParams = {}; }
|
|
8817
|
-
var debug =
|
|
8818
|
-
var algebraic =
|
|
8832
|
+
var debug = this.debug;
|
|
8833
|
+
var algebraic = this.algebraic;
|
|
8819
8834
|
return tokenize(program, __assign(__assign({}, tokenizeParams), { debug: debug, algebraic: algebraic }));
|
|
8820
8835
|
};
|
|
8821
8836
|
Lits.prototype.parse = function (tokenStream) {
|
|
@@ -8835,12 +8850,7 @@ var Lits = /** @class */ (function () {
|
|
|
8835
8850
|
var _a;
|
|
8836
8851
|
if (params === void 0) { params = {}; }
|
|
8837
8852
|
var fnName = 'FN_2eb7b316-471c-5bfa-90cb-d3dfd9164a59';
|
|
8838
|
-
var
|
|
8839
|
-
.map(function (_, index) {
|
|
8840
|
-
return "".concat(fnName, "_").concat(index);
|
|
8841
|
-
})
|
|
8842
|
-
.join(' ');
|
|
8843
|
-
var program = "(".concat(fnName, " ").concat(paramsString, ")");
|
|
8853
|
+
var program = this.generateApplyFunctionCall(fnName, fnParams);
|
|
8844
8854
|
var ast = this.generateAst(program, params);
|
|
8845
8855
|
var hostValues = fnParams.reduce(function (result, param, index) {
|
|
8846
8856
|
result["".concat(fnName, "_").concat(index)] = param;
|
|
@@ -8849,20 +8859,26 @@ var Lits = /** @class */ (function () {
|
|
|
8849
8859
|
params.values = __assign(__assign({}, params.values), hostValues);
|
|
8850
8860
|
return this.evaluate(ast, params);
|
|
8851
8861
|
};
|
|
8862
|
+
Lits.prototype.generateApplyFunctionCall = function (fnName, fnParams) {
|
|
8863
|
+
var paramsString = fnParams
|
|
8864
|
+
.map(function (_, index) {
|
|
8865
|
+
return "".concat(fnName, "_").concat(index);
|
|
8866
|
+
})
|
|
8867
|
+
.join(this.algebraic ? ', ' : ' ');
|
|
8868
|
+
return this.algebraic ? "".concat(fnName, "(").concat(paramsString, ")") : "(".concat(fnName, " ").concat(paramsString, ")");
|
|
8869
|
+
};
|
|
8852
8870
|
Lits.prototype.generateAst = function (program, params) {
|
|
8853
|
-
var _a
|
|
8871
|
+
var _a;
|
|
8854
8872
|
if (this.astCache) {
|
|
8855
8873
|
var cachedAst = this.astCache.get(program);
|
|
8856
8874
|
if (cachedAst)
|
|
8857
8875
|
return cachedAst;
|
|
8858
8876
|
}
|
|
8859
8877
|
var tokenStream = this.tokenize(program, {
|
|
8860
|
-
debug: (_a = params.debug) !== null && _a !== void 0 ? _a : this.debug,
|
|
8861
8878
|
filePath: params.filePath,
|
|
8862
|
-
algebraic: (_b = params.algebraic) !== null && _b !== void 0 ? _b : this.algebraic,
|
|
8863
8879
|
});
|
|
8864
8880
|
var ast = this.parse(tokenStream);
|
|
8865
|
-
(
|
|
8881
|
+
(_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
|
|
8866
8882
|
return ast;
|
|
8867
8883
|
};
|
|
8868
8884
|
return Lits;
|