@mojir/lits 2.1.15 → 2.1.17
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 +110 -4
- package/dist/cli/src/AutoCompleter/AutoCompleter.d.ts +17 -0
- package/dist/cli/src/Lits/Lits.d.ts +2 -0
- package/dist/index.esm.js +106 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +106 -0
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/AutoCompleter/AutoCompleter.d.ts +17 -0
- package/dist/src/Lits/Lits.d.ts +2 -0
- package/dist/testFramework.esm.js +106 -0
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +106 -0
- package/dist/testFramework.js.map +1 -1
- package/package.json +2 -2
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.1.
|
|
95
|
+
var version = "2.1.17";
|
|
96
96
|
|
|
97
97
|
function getCodeMarker(sourceCodeInfo) {
|
|
98
98
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -14822,6 +14822,102 @@ var Parser = /** @class */ (function () {
|
|
|
14822
14822
|
return Parser;
|
|
14823
14823
|
}());
|
|
14824
14824
|
|
|
14825
|
+
var autoCompleteTokenTypes = [
|
|
14826
|
+
'Operator',
|
|
14827
|
+
'ReservedSymbol',
|
|
14828
|
+
'Symbol',
|
|
14829
|
+
];
|
|
14830
|
+
var litsCommands = new Set(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false));
|
|
14831
|
+
// TODO: replace with get suggestions function
|
|
14832
|
+
var AutoCompleter = /** @class */ (function () {
|
|
14833
|
+
function AutoCompleter(tokenStream, params) {
|
|
14834
|
+
this.searchPrefix = '';
|
|
14835
|
+
this.suggestions = [];
|
|
14836
|
+
this.suggestionIndex = null;
|
|
14837
|
+
if (!tokenStream) {
|
|
14838
|
+
return;
|
|
14839
|
+
}
|
|
14840
|
+
var lastToken = tokenStream.tokens.at(-1);
|
|
14841
|
+
if (!lastToken) {
|
|
14842
|
+
return;
|
|
14843
|
+
}
|
|
14844
|
+
var _a = __read(lastToken, 2), tokenType = _a[0], tokenValue = _a[1];
|
|
14845
|
+
if (!autoCompleteTokenTypes.includes(tokenType)) {
|
|
14846
|
+
return;
|
|
14847
|
+
}
|
|
14848
|
+
this.searchPrefix = tokenValue.toLowerCase();
|
|
14849
|
+
this.generateSuggestions(params);
|
|
14850
|
+
}
|
|
14851
|
+
AutoCompleter.prototype.getNextSuggestion = function () {
|
|
14852
|
+
if (this.suggestions.length === 0) {
|
|
14853
|
+
return null;
|
|
14854
|
+
}
|
|
14855
|
+
if (this.suggestionIndex === null) {
|
|
14856
|
+
this.suggestionIndex = 0;
|
|
14857
|
+
}
|
|
14858
|
+
else {
|
|
14859
|
+
this.suggestionIndex += 1;
|
|
14860
|
+
if (this.suggestionIndex >= this.suggestions.length) {
|
|
14861
|
+
this.suggestionIndex = 0;
|
|
14862
|
+
}
|
|
14863
|
+
}
|
|
14864
|
+
return {
|
|
14865
|
+
suggestion: this.suggestions[this.suggestionIndex],
|
|
14866
|
+
searchPattern: this.searchPrefix,
|
|
14867
|
+
};
|
|
14868
|
+
};
|
|
14869
|
+
AutoCompleter.prototype.getPreviousSuggestion = function () {
|
|
14870
|
+
if (this.suggestions.length === 0) {
|
|
14871
|
+
return null;
|
|
14872
|
+
}
|
|
14873
|
+
if (this.suggestionIndex === null) {
|
|
14874
|
+
this.suggestionIndex = this.suggestions.length - 1;
|
|
14875
|
+
}
|
|
14876
|
+
else {
|
|
14877
|
+
this.suggestionIndex -= 1;
|
|
14878
|
+
if (this.suggestionIndex < 0) {
|
|
14879
|
+
this.suggestionIndex = this.suggestions.length - 1;
|
|
14880
|
+
}
|
|
14881
|
+
}
|
|
14882
|
+
return {
|
|
14883
|
+
suggestion: this.suggestions[this.suggestionIndex],
|
|
14884
|
+
searchPattern: this.searchPrefix,
|
|
14885
|
+
};
|
|
14886
|
+
};
|
|
14887
|
+
AutoCompleter.prototype.getSuggestions = function () {
|
|
14888
|
+
return __spreadArray([], __read(this.suggestions), false);
|
|
14889
|
+
};
|
|
14890
|
+
AutoCompleter.prototype.getSearchPrefix = function () {
|
|
14891
|
+
return this.searchPrefix;
|
|
14892
|
+
};
|
|
14893
|
+
AutoCompleter.prototype.generateSuggestions = function (params) {
|
|
14894
|
+
var _this = this;
|
|
14895
|
+
var _a, _b, _c, _d;
|
|
14896
|
+
var suggestions = new Set();
|
|
14897
|
+
litsCommands.forEach(function (name) {
|
|
14898
|
+
if (name.toLowerCase().startsWith(_this.searchPrefix)) {
|
|
14899
|
+
suggestions.add(name);
|
|
14900
|
+
}
|
|
14901
|
+
});
|
|
14902
|
+
Object.keys((_a = params.globalContext) !== null && _a !== void 0 ? _a : {})
|
|
14903
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14904
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14905
|
+
(_b = params.contexts) === null || _b === void 0 ? void 0 : _b.forEach(function (context) {
|
|
14906
|
+
Object.keys(context)
|
|
14907
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14908
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14909
|
+
});
|
|
14910
|
+
Object.keys((_c = params.jsFunctions) !== null && _c !== void 0 ? _c : {})
|
|
14911
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14912
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14913
|
+
Object.keys((_d = params.values) !== null && _d !== void 0 ? _d : {})
|
|
14914
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14915
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14916
|
+
this.suggestions = __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
|
|
14917
|
+
};
|
|
14918
|
+
return AutoCompleter;
|
|
14919
|
+
}());
|
|
14920
|
+
|
|
14825
14921
|
var Cache = /** @class */ (function () {
|
|
14826
14922
|
function Cache(maxSize) {
|
|
14827
14923
|
this.cache = {};
|
|
@@ -14997,6 +15093,16 @@ var Lits = /** @class */ (function () {
|
|
|
14997
15093
|
(_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
|
|
14998
15094
|
return ast;
|
|
14999
15095
|
};
|
|
15096
|
+
Lits.prototype.getAutoCompleter = function (partialProgram, params) {
|
|
15097
|
+
if (params === void 0) { params = {}; }
|
|
15098
|
+
try {
|
|
15099
|
+
var tokenStream = this.tokenize(partialProgram);
|
|
15100
|
+
return new AutoCompleter(tokenStream, params);
|
|
15101
|
+
}
|
|
15102
|
+
catch (_a) {
|
|
15103
|
+
return new AutoCompleter(null, params);
|
|
15104
|
+
}
|
|
15105
|
+
};
|
|
15000
15106
|
return Lits;
|
|
15001
15107
|
}());
|
|
15002
15108
|
|
|
@@ -32426,10 +32532,10 @@ class ExpressionParser {
|
|
|
32426
32532
|
* @returns A string containing the symbolic representation
|
|
32427
32533
|
*/
|
|
32428
32534
|
function prettyPi(num, config = {}) {
|
|
32429
|
-
if (isNaN(num)) {
|
|
32430
|
-
return "NaN";
|
|
32431
|
-
}
|
|
32432
32535
|
if (!isFinite(num)) {
|
|
32536
|
+
if (isNaN(num)) {
|
|
32537
|
+
return "NaN";
|
|
32538
|
+
}
|
|
32433
32539
|
return num > 0 ? "∞" : "-∞";
|
|
32434
32540
|
}
|
|
32435
32541
|
setConfig(config);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ContextParams } from '../Lits/Lits';
|
|
2
|
+
import type { TokenStream } from '../tokenizer/tokenize';
|
|
3
|
+
export type AutoCompleteSuggestion = {
|
|
4
|
+
suggestion: string;
|
|
5
|
+
searchPattern: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class AutoCompleter {
|
|
8
|
+
private searchPrefix;
|
|
9
|
+
private suggestions;
|
|
10
|
+
private suggestionIndex;
|
|
11
|
+
constructor(tokenStream: TokenStream | null, params: ContextParams);
|
|
12
|
+
getNextSuggestion(): AutoCompleteSuggestion | null;
|
|
13
|
+
getPreviousSuggestion(): AutoCompleteSuggestion | null;
|
|
14
|
+
getSuggestions(): string[];
|
|
15
|
+
getSearchPrefix(): string;
|
|
16
|
+
private generateSuggestions;
|
|
17
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { Context } from '../evaluator/interface';
|
|
|
2
2
|
import type { Any } from '../interface';
|
|
3
3
|
import type { Ast, LitsFunction } from '../parser/types';
|
|
4
4
|
import type { TokenStream } from '../tokenizer/tokenize';
|
|
5
|
+
import { AutoCompleter } from '../AutoCompleter/AutoCompleter';
|
|
5
6
|
import { Cache } from './Cache';
|
|
6
7
|
export interface LitsRuntimeInfo {
|
|
7
8
|
astCache: Cache | null;
|
|
@@ -46,5 +47,6 @@ export declare class Lits {
|
|
|
46
47
|
apply(fn: LitsFunction, fnParams: unknown[], params?: ContextParams): Any;
|
|
47
48
|
private generateApplyFunctionCall;
|
|
48
49
|
private generateAst;
|
|
50
|
+
getAutoCompleter(partialProgram: string, params?: ContextParams): AutoCompleter;
|
|
49
51
|
}
|
|
50
52
|
export {};
|
package/dist/index.esm.js
CHANGED
|
@@ -14859,6 +14859,102 @@ var Parser = /** @class */ (function () {
|
|
|
14859
14859
|
return Parser;
|
|
14860
14860
|
}());
|
|
14861
14861
|
|
|
14862
|
+
var autoCompleteTokenTypes = [
|
|
14863
|
+
'Operator',
|
|
14864
|
+
'ReservedSymbol',
|
|
14865
|
+
'Symbol',
|
|
14866
|
+
];
|
|
14867
|
+
var litsCommands = new Set(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false));
|
|
14868
|
+
// TODO: replace with get suggestions function
|
|
14869
|
+
var AutoCompleter = /** @class */ (function () {
|
|
14870
|
+
function AutoCompleter(tokenStream, params) {
|
|
14871
|
+
this.searchPrefix = '';
|
|
14872
|
+
this.suggestions = [];
|
|
14873
|
+
this.suggestionIndex = null;
|
|
14874
|
+
if (!tokenStream) {
|
|
14875
|
+
return;
|
|
14876
|
+
}
|
|
14877
|
+
var lastToken = tokenStream.tokens.at(-1);
|
|
14878
|
+
if (!lastToken) {
|
|
14879
|
+
return;
|
|
14880
|
+
}
|
|
14881
|
+
var _a = __read(lastToken, 2), tokenType = _a[0], tokenValue = _a[1];
|
|
14882
|
+
if (!autoCompleteTokenTypes.includes(tokenType)) {
|
|
14883
|
+
return;
|
|
14884
|
+
}
|
|
14885
|
+
this.searchPrefix = tokenValue.toLowerCase();
|
|
14886
|
+
this.generateSuggestions(params);
|
|
14887
|
+
}
|
|
14888
|
+
AutoCompleter.prototype.getNextSuggestion = function () {
|
|
14889
|
+
if (this.suggestions.length === 0) {
|
|
14890
|
+
return null;
|
|
14891
|
+
}
|
|
14892
|
+
if (this.suggestionIndex === null) {
|
|
14893
|
+
this.suggestionIndex = 0;
|
|
14894
|
+
}
|
|
14895
|
+
else {
|
|
14896
|
+
this.suggestionIndex += 1;
|
|
14897
|
+
if (this.suggestionIndex >= this.suggestions.length) {
|
|
14898
|
+
this.suggestionIndex = 0;
|
|
14899
|
+
}
|
|
14900
|
+
}
|
|
14901
|
+
return {
|
|
14902
|
+
suggestion: this.suggestions[this.suggestionIndex],
|
|
14903
|
+
searchPattern: this.searchPrefix,
|
|
14904
|
+
};
|
|
14905
|
+
};
|
|
14906
|
+
AutoCompleter.prototype.getPreviousSuggestion = function () {
|
|
14907
|
+
if (this.suggestions.length === 0) {
|
|
14908
|
+
return null;
|
|
14909
|
+
}
|
|
14910
|
+
if (this.suggestionIndex === null) {
|
|
14911
|
+
this.suggestionIndex = this.suggestions.length - 1;
|
|
14912
|
+
}
|
|
14913
|
+
else {
|
|
14914
|
+
this.suggestionIndex -= 1;
|
|
14915
|
+
if (this.suggestionIndex < 0) {
|
|
14916
|
+
this.suggestionIndex = this.suggestions.length - 1;
|
|
14917
|
+
}
|
|
14918
|
+
}
|
|
14919
|
+
return {
|
|
14920
|
+
suggestion: this.suggestions[this.suggestionIndex],
|
|
14921
|
+
searchPattern: this.searchPrefix,
|
|
14922
|
+
};
|
|
14923
|
+
};
|
|
14924
|
+
AutoCompleter.prototype.getSuggestions = function () {
|
|
14925
|
+
return __spreadArray([], __read(this.suggestions), false);
|
|
14926
|
+
};
|
|
14927
|
+
AutoCompleter.prototype.getSearchPrefix = function () {
|
|
14928
|
+
return this.searchPrefix;
|
|
14929
|
+
};
|
|
14930
|
+
AutoCompleter.prototype.generateSuggestions = function (params) {
|
|
14931
|
+
var _this = this;
|
|
14932
|
+
var _a, _b, _c, _d;
|
|
14933
|
+
var suggestions = new Set();
|
|
14934
|
+
litsCommands.forEach(function (name) {
|
|
14935
|
+
if (name.toLowerCase().startsWith(_this.searchPrefix)) {
|
|
14936
|
+
suggestions.add(name);
|
|
14937
|
+
}
|
|
14938
|
+
});
|
|
14939
|
+
Object.keys((_a = params.globalContext) !== null && _a !== void 0 ? _a : {})
|
|
14940
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14941
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14942
|
+
(_b = params.contexts) === null || _b === void 0 ? void 0 : _b.forEach(function (context) {
|
|
14943
|
+
Object.keys(context)
|
|
14944
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14945
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14946
|
+
});
|
|
14947
|
+
Object.keys((_c = params.jsFunctions) !== null && _c !== void 0 ? _c : {})
|
|
14948
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14949
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14950
|
+
Object.keys((_d = params.values) !== null && _d !== void 0 ? _d : {})
|
|
14951
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14952
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14953
|
+
this.suggestions = __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
|
|
14954
|
+
};
|
|
14955
|
+
return AutoCompleter;
|
|
14956
|
+
}());
|
|
14957
|
+
|
|
14862
14958
|
var Cache = /** @class */ (function () {
|
|
14863
14959
|
function Cache(maxSize) {
|
|
14864
14960
|
this.cache = {};
|
|
@@ -15034,6 +15130,16 @@ var Lits = /** @class */ (function () {
|
|
|
15034
15130
|
(_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
|
|
15035
15131
|
return ast;
|
|
15036
15132
|
};
|
|
15133
|
+
Lits.prototype.getAutoCompleter = function (partialProgram, params) {
|
|
15134
|
+
if (params === void 0) { params = {}; }
|
|
15135
|
+
try {
|
|
15136
|
+
var tokenStream = this.tokenize(partialProgram);
|
|
15137
|
+
return new AutoCompleter(tokenStream, params);
|
|
15138
|
+
}
|
|
15139
|
+
catch (_a) {
|
|
15140
|
+
return new AutoCompleter(null, params);
|
|
15141
|
+
}
|
|
15142
|
+
};
|
|
15037
15143
|
return Lits;
|
|
15038
15144
|
}());
|
|
15039
15145
|
|