@mojir/lits 2.1.19 → 2.1.21
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 +50 -42
- package/dist/cli/src/AutoCompleter/AutoCompleter.d.ts +13 -7
- package/dist/cli/src/Lits/Lits.d.ts +1 -1
- package/dist/cli/src/tokenizer/reservedNames.d.ts +1 -39
- package/dist/cli/src/tokenizer/token.d.ts +5 -5
- package/dist/index.esm.js +49 -41
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +49 -41
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +49 -41
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/AutoCompleter/AutoCompleter.d.ts +13 -7
- package/dist/src/Lits/Lits.d.ts +1 -1
- package/dist/src/tokenizer/reservedNames.d.ts +1 -39
- package/dist/src/tokenizer/token.d.ts +5 -5
- package/dist/testFramework.esm.js +49 -41
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +49 -41
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import type { ContextParams } from '../Lits/Lits';
|
|
2
|
-
import type { TokenStream } from '../tokenizer/tokenize';
|
|
1
|
+
import type { ContextParams, Lits } from '../Lits/Lits';
|
|
3
2
|
export type AutoCompleteSuggestion = {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
program: string;
|
|
4
|
+
position: number;
|
|
6
5
|
};
|
|
7
6
|
export declare class AutoCompleter {
|
|
8
|
-
|
|
7
|
+
readonly originalProgram: string;
|
|
8
|
+
readonly originalPosition: number;
|
|
9
|
+
private prefixProgram;
|
|
10
|
+
private suffixProgram;
|
|
11
|
+
private searchString;
|
|
9
12
|
private suggestions;
|
|
10
13
|
private suggestionIndex;
|
|
11
|
-
constructor(
|
|
14
|
+
constructor(originalProgram: string, originalPosition: number, lits: Lits, params: ContextParams);
|
|
12
15
|
getNextSuggestion(): AutoCompleteSuggestion | null;
|
|
13
16
|
getPreviousSuggestion(): AutoCompleteSuggestion | null;
|
|
17
|
+
private getAutoCompleteSuggestionResult;
|
|
18
|
+
private getNextSuggestionSymbol;
|
|
19
|
+
private getPreviousSuggestionSymbol;
|
|
14
20
|
getSuggestions(): string[];
|
|
15
|
-
|
|
21
|
+
getSearchString(): string;
|
|
16
22
|
private generateSuggestions;
|
|
17
23
|
}
|
package/dist/src/Lits/Lits.d.ts
CHANGED
|
@@ -47,6 +47,6 @@ export declare class Lits {
|
|
|
47
47
|
apply(fn: LitsFunction, fnParams: unknown[], params?: ContextParams): Any;
|
|
48
48
|
private generateApplyFunctionCall;
|
|
49
49
|
private generateAst;
|
|
50
|
-
getAutoCompleter(
|
|
50
|
+
getAutoCompleter(program: string, position: number, params?: ContextParams): AutoCompleter;
|
|
51
51
|
}
|
|
52
52
|
export {};
|
|
@@ -58,44 +58,6 @@ export declare const reservedSymbolRecord: {
|
|
|
58
58
|
readonly as: null;
|
|
59
59
|
readonly _: null;
|
|
60
60
|
};
|
|
61
|
-
export declare const validReservedSymbolRecord: {
|
|
62
|
-
readonly E: number;
|
|
63
|
-
readonly '-E': number;
|
|
64
|
-
readonly ε: number;
|
|
65
|
-
readonly '-\u03B5': number;
|
|
66
|
-
readonly PI: number;
|
|
67
|
-
readonly '-PI': number;
|
|
68
|
-
readonly π: number;
|
|
69
|
-
readonly '-\u03C0': number;
|
|
70
|
-
readonly PHI: number;
|
|
71
|
-
readonly '-PHI': number;
|
|
72
|
-
readonly φ: number;
|
|
73
|
-
readonly '-\u03C6': number;
|
|
74
|
-
readonly POSITIVE_INFINITY: number;
|
|
75
|
-
readonly '\u221E': number;
|
|
76
|
-
readonly NEGATIVE_INFINITY: number;
|
|
77
|
-
readonly '-\u221E': number;
|
|
78
|
-
readonly MAX_SAFE_INTEGER: number;
|
|
79
|
-
readonly MIN_SAFE_INTEGER: number;
|
|
80
|
-
readonly MAX_VALUE: number;
|
|
81
|
-
readonly MIN_VALUE: number;
|
|
82
|
-
readonly NaN: number;
|
|
83
|
-
readonly true: true;
|
|
84
|
-
readonly false: false;
|
|
85
|
-
readonly null: null;
|
|
86
|
-
readonly else: null;
|
|
87
|
-
readonly case: null;
|
|
88
|
-
readonly each: null;
|
|
89
|
-
readonly in: null;
|
|
90
|
-
readonly when: null;
|
|
91
|
-
readonly while: null;
|
|
92
|
-
readonly catch: null;
|
|
93
|
-
readonly function: null;
|
|
94
|
-
readonly export: null;
|
|
95
|
-
readonly as: null;
|
|
96
|
-
readonly _: null;
|
|
97
|
-
};
|
|
98
|
-
export type ValidReservedSymbol = keyof typeof validReservedSymbolRecord;
|
|
99
61
|
export type ReservedSymbol = keyof typeof reservedSymbolRecord;
|
|
100
|
-
export declare function isReservedSymbol(symbol: string): symbol is keyof typeof
|
|
62
|
+
export declare function isReservedSymbol(symbol: string): symbol is keyof typeof reservedSymbolRecord;
|
|
101
63
|
export declare function isNumberReservedSymbol(symbol: string): symbol is keyof typeof numberReservedSymbolRecord;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReservedSymbol } from './reservedNames';
|
|
2
2
|
import { type SymbolicBinaryOperator, type SymbolicOperator } from './operators';
|
|
3
3
|
export declare const tokenTypes: readonly ["LBrace", "LBracket", "RBrace", "RBracket", "LParen", "RParen", "BasePrefixedNumber", "MultiLineComment", "Number", "Operator", "RegexpShorthand", "ReservedSymbol", "SingleLineComment", "String", "Symbol", "Whitespace"];
|
|
4
4
|
export type TokenType = typeof tokenTypes[number];
|
|
@@ -16,7 +16,7 @@ export type MultiLineCommentToken = GenericToken<'MultiLineComment'>;
|
|
|
16
16
|
export type NumberToken = GenericToken<'Number'>;
|
|
17
17
|
export type OperatorToken<T extends SymbolicOperator = SymbolicOperator> = GenericToken<'Operator', T>;
|
|
18
18
|
export type RegexpShorthandToken = GenericToken<'RegexpShorthand'>;
|
|
19
|
-
export type ReservedSymbolToken<T extends
|
|
19
|
+
export type ReservedSymbolToken<T extends ReservedSymbol = ReservedSymbol> = GenericToken<'ReservedSymbol', T>;
|
|
20
20
|
export type SingleLineCommentToken = GenericToken<'SingleLineComment'>;
|
|
21
21
|
export type StringToken = GenericToken<'String'>;
|
|
22
22
|
export type SymbolToken<T extends string = string> = GenericToken<'Symbol', T>;
|
|
@@ -34,9 +34,9 @@ export interface SourceCodeInfo {
|
|
|
34
34
|
export declare function isSymbolToken<T extends string>(token: Token | undefined | undefined, symbolName?: T): token is SymbolToken<T>;
|
|
35
35
|
export declare function assertSymbolToken<T extends string>(token: Token | undefined | undefined, symbolName?: T): asserts token is SymbolToken<T>;
|
|
36
36
|
export declare function asSymbolToken<T extends string>(token: Token | undefined | undefined, symbolName?: T): SymbolToken<T>;
|
|
37
|
-
export declare function isReservedSymbolToken<T extends
|
|
38
|
-
export declare function assertReservedSymbolToken<T extends
|
|
39
|
-
export declare function asReservedSymbolToken<T extends
|
|
37
|
+
export declare function isReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): token is ReservedSymbolToken<T>;
|
|
38
|
+
export declare function assertReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): asserts token is ReservedSymbolToken<T>;
|
|
39
|
+
export declare function asReservedSymbolToken<T extends ReservedSymbol>(token: Token | undefined | undefined, symbolName?: T): ReservedSymbolToken<T>;
|
|
40
40
|
export declare function isSingleLineCommentToken(token: Token | undefined): token is SingleLineCommentToken;
|
|
41
41
|
export declare function assertSingleLineCommentToken(token: Token | undefined): asserts token is SingleLineCommentToken;
|
|
42
42
|
export declare function asSingleLineCommentToken(token: Token | undefined): SingleLineCommentToken;
|
|
@@ -11684,9 +11684,8 @@ var numberReservedSymbolRecord = {
|
|
|
11684
11684
|
'NaN': Number.NaN,
|
|
11685
11685
|
};
|
|
11686
11686
|
var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
|
|
11687
|
-
var validReservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
|
|
11688
11687
|
function isReservedSymbol(symbol) {
|
|
11689
|
-
return symbol in
|
|
11688
|
+
return symbol in reservedSymbolRecord;
|
|
11690
11689
|
}
|
|
11691
11690
|
function isNumberReservedSymbol(symbol) {
|
|
11692
11691
|
return symbol in numberReservedSymbolRecord;
|
|
@@ -14800,18 +14799,25 @@ var Parser = /** @class */ (function () {
|
|
|
14800
14799
|
return Parser;
|
|
14801
14800
|
}());
|
|
14802
14801
|
|
|
14803
|
-
var
|
|
14804
|
-
'Operator',
|
|
14805
|
-
'ReservedSymbol',
|
|
14806
|
-
'Symbol',
|
|
14807
|
-
];
|
|
14808
|
-
var litsCommands = new Set(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false));
|
|
14802
|
+
var litsCommands = new Set(__spreadArray(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false), __read(Object.keys(reservedSymbolRecord)), false));
|
|
14809
14803
|
// TODO: replace with get suggestions function
|
|
14810
14804
|
var AutoCompleter = /** @class */ (function () {
|
|
14811
|
-
function AutoCompleter(
|
|
14812
|
-
this.
|
|
14805
|
+
function AutoCompleter(originalProgram, originalPosition, lits, params) {
|
|
14806
|
+
this.originalProgram = originalProgram;
|
|
14807
|
+
this.originalPosition = originalPosition;
|
|
14808
|
+
this.prefixProgram = '';
|
|
14809
|
+
this.suffixProgram = '';
|
|
14810
|
+
this.searchString = '';
|
|
14813
14811
|
this.suggestions = [];
|
|
14814
14812
|
this.suggestionIndex = null;
|
|
14813
|
+
var partialProgram = this.originalProgram.slice(0, this.originalPosition);
|
|
14814
|
+
var tokenStream = null;
|
|
14815
|
+
try {
|
|
14816
|
+
tokenStream = lits.tokenize(partialProgram);
|
|
14817
|
+
}
|
|
14818
|
+
catch (_a) {
|
|
14819
|
+
// do nothing
|
|
14820
|
+
}
|
|
14815
14821
|
if (!tokenStream) {
|
|
14816
14822
|
return;
|
|
14817
14823
|
}
|
|
@@ -14819,14 +14825,28 @@ var AutoCompleter = /** @class */ (function () {
|
|
|
14819
14825
|
if (!lastToken) {
|
|
14820
14826
|
return;
|
|
14821
14827
|
}
|
|
14822
|
-
|
|
14823
|
-
|
|
14824
|
-
|
|
14825
|
-
|
|
14826
|
-
this.
|
|
14827
|
-
this.generateSuggestions(params);
|
|
14828
|
+
this.searchString = lastToken[1];
|
|
14829
|
+
this.prefixProgram = this.originalProgram.slice(0, this.originalPosition - this.searchString.length);
|
|
14830
|
+
this.suffixProgram = this.originalProgram.slice(this.prefixProgram.length + this.searchString.length);
|
|
14831
|
+
this.originalProgram.slice(this.prefixProgram.length + this.searchString.length);
|
|
14832
|
+
this.suggestions = this.generateSuggestions(params);
|
|
14828
14833
|
}
|
|
14829
14834
|
AutoCompleter.prototype.getNextSuggestion = function () {
|
|
14835
|
+
return this.getAutoCompleteSuggestionResult(this.getNextSuggestionSymbol());
|
|
14836
|
+
};
|
|
14837
|
+
AutoCompleter.prototype.getPreviousSuggestion = function () {
|
|
14838
|
+
return this.getAutoCompleteSuggestionResult(this.getPreviousSuggestionSymbol());
|
|
14839
|
+
};
|
|
14840
|
+
AutoCompleter.prototype.getAutoCompleteSuggestionResult = function (suggestion) {
|
|
14841
|
+
if (suggestion === null) {
|
|
14842
|
+
return null;
|
|
14843
|
+
}
|
|
14844
|
+
return {
|
|
14845
|
+
program: this.prefixProgram + suggestion + this.suffixProgram,
|
|
14846
|
+
position: this.prefixProgram.length + suggestion.length,
|
|
14847
|
+
};
|
|
14848
|
+
};
|
|
14849
|
+
AutoCompleter.prototype.getNextSuggestionSymbol = function () {
|
|
14830
14850
|
if (this.suggestions.length === 0) {
|
|
14831
14851
|
return null;
|
|
14832
14852
|
}
|
|
@@ -14839,12 +14859,9 @@ var AutoCompleter = /** @class */ (function () {
|
|
|
14839
14859
|
this.suggestionIndex = 0;
|
|
14840
14860
|
}
|
|
14841
14861
|
}
|
|
14842
|
-
return
|
|
14843
|
-
suggestion: this.suggestions[this.suggestionIndex],
|
|
14844
|
-
searchPattern: this.searchPrefix,
|
|
14845
|
-
};
|
|
14862
|
+
return this.suggestions[this.suggestionIndex];
|
|
14846
14863
|
};
|
|
14847
|
-
AutoCompleter.prototype.
|
|
14864
|
+
AutoCompleter.prototype.getPreviousSuggestionSymbol = function () {
|
|
14848
14865
|
if (this.suggestions.length === 0) {
|
|
14849
14866
|
return null;
|
|
14850
14867
|
}
|
|
@@ -14857,41 +14874,38 @@ var AutoCompleter = /** @class */ (function () {
|
|
|
14857
14874
|
this.suggestionIndex = this.suggestions.length - 1;
|
|
14858
14875
|
}
|
|
14859
14876
|
}
|
|
14860
|
-
return
|
|
14861
|
-
suggestion: this.suggestions[this.suggestionIndex],
|
|
14862
|
-
searchPattern: this.searchPrefix,
|
|
14863
|
-
};
|
|
14877
|
+
return this.suggestions[this.suggestionIndex];
|
|
14864
14878
|
};
|
|
14865
14879
|
AutoCompleter.prototype.getSuggestions = function () {
|
|
14866
14880
|
return __spreadArray([], __read(this.suggestions), false);
|
|
14867
14881
|
};
|
|
14868
|
-
AutoCompleter.prototype.
|
|
14869
|
-
return this.
|
|
14882
|
+
AutoCompleter.prototype.getSearchString = function () {
|
|
14883
|
+
return this.searchString;
|
|
14870
14884
|
};
|
|
14871
14885
|
AutoCompleter.prototype.generateSuggestions = function (params) {
|
|
14872
14886
|
var _this = this;
|
|
14873
14887
|
var _a, _b, _c, _d;
|
|
14874
14888
|
var suggestions = new Set();
|
|
14875
14889
|
litsCommands.forEach(function (name) {
|
|
14876
|
-
if (name.startsWith(_this.
|
|
14890
|
+
if (name.startsWith(_this.searchString)) {
|
|
14877
14891
|
suggestions.add(name);
|
|
14878
14892
|
}
|
|
14879
14893
|
});
|
|
14880
14894
|
Object.keys((_a = params.globalContext) !== null && _a !== void 0 ? _a : {})
|
|
14881
|
-
.filter(function (name) { return name.startsWith(_this.
|
|
14895
|
+
.filter(function (name) { return name.startsWith(_this.searchString); })
|
|
14882
14896
|
.forEach(function (name) { return suggestions.add(name); });
|
|
14883
14897
|
(_b = params.contexts) === null || _b === void 0 ? void 0 : _b.forEach(function (context) {
|
|
14884
14898
|
Object.keys(context)
|
|
14885
|
-
.filter(function (name) { return name.startsWith(_this.
|
|
14899
|
+
.filter(function (name) { return name.startsWith(_this.searchString); })
|
|
14886
14900
|
.forEach(function (name) { return suggestions.add(name); });
|
|
14887
14901
|
});
|
|
14888
14902
|
Object.keys((_c = params.jsFunctions) !== null && _c !== void 0 ? _c : {})
|
|
14889
|
-
.filter(function (name) { return name.startsWith(_this.
|
|
14903
|
+
.filter(function (name) { return name.startsWith(_this.searchString); })
|
|
14890
14904
|
.forEach(function (name) { return suggestions.add(name); });
|
|
14891
14905
|
Object.keys((_d = params.values) !== null && _d !== void 0 ? _d : {})
|
|
14892
|
-
.filter(function (name) { return name.startsWith(_this.
|
|
14906
|
+
.filter(function (name) { return name.startsWith(_this.searchString); })
|
|
14893
14907
|
.forEach(function (name) { return suggestions.add(name); });
|
|
14894
|
-
|
|
14908
|
+
return __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.localeCompare(b); });
|
|
14895
14909
|
};
|
|
14896
14910
|
return AutoCompleter;
|
|
14897
14911
|
}());
|
|
@@ -15071,15 +15085,9 @@ var Lits = /** @class */ (function () {
|
|
|
15071
15085
|
(_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
|
|
15072
15086
|
return ast;
|
|
15073
15087
|
};
|
|
15074
|
-
Lits.prototype.getAutoCompleter = function (
|
|
15088
|
+
Lits.prototype.getAutoCompleter = function (program, position, params) {
|
|
15075
15089
|
if (params === void 0) { params = {}; }
|
|
15076
|
-
|
|
15077
|
-
var tokenStream = this.tokenize(partialProgram);
|
|
15078
|
-
return new AutoCompleter(tokenStream, params);
|
|
15079
|
-
}
|
|
15080
|
-
catch (_a) {
|
|
15081
|
-
return new AutoCompleter(null, params);
|
|
15082
|
-
}
|
|
15090
|
+
return new AutoCompleter(program, position, this, params);
|
|
15083
15091
|
};
|
|
15084
15092
|
return Lits;
|
|
15085
15093
|
}());
|