@witchcraft/expressit 0.0.3 → 0.1.1
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/README.md +3 -1
- package/dist/Lexer.d.ts +146 -0
- package/dist/Lexer.d.ts.map +1 -0
- package/dist/Lexer.js +960 -0
- package/dist/Parser.d.ts +211 -0
- package/dist/Parser.d.ts.map +1 -0
- package/dist/Parser.js +1476 -0
- package/dist/ast/builders/token.js +1 -1
- package/dist/ast/handlers.d.ts +3 -3
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/examples/shortcutContextParser.d.ts +1 -1
- package/dist/examples/shortcutContextParser.js +1 -1
- package/dist/helpers/errors.js +3 -3
- package/dist/helpers/parser/checkParserOpts.js +2 -2
- package/dist/helpers/parser/extractPosition.d.ts +2 -6
- package/dist/helpers/parser/extractPosition.d.ts.map +1 -1
- package/dist/helpers/parser/extractPosition.js +3 -3
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +2 -3
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +1 -1
- package/dist/helpers/parser/getUnclosedRightParenCount.js +4 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/package.json.js +27 -41
- package/dist/types/ast.d.ts +1 -7
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/errors.d.ts +5 -17
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +0 -1
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +1 -1
- package/dist/utils/getCursorInfo.d.ts +2 -2
- package/dist/utils/getCursorInfo.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +3 -6
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +1 -1
- package/dist/utils/prettyAst.js +7 -6
- package/package.json +25 -41
- package/src/Lexer.ts +704 -0
- package/src/Parser.ts +2014 -0
- package/src/ast/builders/array.ts +1 -1
- package/src/ast/builders/condition.ts +1 -1
- package/src/ast/builders/expression.ts +1 -1
- package/src/ast/builders/group.ts +1 -1
- package/src/ast/builders/pos.ts +1 -1
- package/src/ast/builders/token.ts +2 -2
- package/src/ast/builders/type.ts +1 -1
- package/src/ast/builders/variable.ts +1 -1
- package/src/ast/classes/ConditionNode.ts +1 -1
- package/src/ast/classes/ErrorToken.ts +1 -1
- package/src/ast/classes/ValidToken.ts +2 -2
- package/src/ast/handlers.ts +6 -6
- package/src/examples/shortcutContextParser.ts +2 -2
- package/src/helpers/errors.ts +4 -4
- package/src/helpers/general/defaultConditionNormalizer.ts +1 -1
- package/src/helpers/parser/checkParserOpts.ts +12 -12
- package/src/helpers/parser/extractPosition.ts +4 -8
- package/src/helpers/parser/getUnclosedRightParenCount.ts +6 -6
- package/src/helpers/parser/parseParserOptions.ts +1 -1
- package/src/index.ts +1 -2
- package/src/types/ast.ts +1 -8
- package/src/types/errors.ts +12 -22
- package/src/types/parser.ts +0 -1
- package/src/utils/extractTokens.ts +1 -1
- package/src/utils/getCursorInfo.ts +6 -5
- package/src/utils/getOppositeDelimiter.ts +5 -2
- package/src/utils/prettyAst.ts +4 -4
- package/dist/grammar/ParserBase.d.ts +0 -51
- package/dist/grammar/ParserBase.d.ts.map +0 -1
- package/dist/grammar/ParserBase.js +0 -517
- package/dist/grammar/createTokens.d.ts +0 -56
- package/dist/grammar/createTokens.d.ts.map +0 -1
- package/dist/grammar/createTokens.js +0 -844
- package/dist/grammar/index.d.ts +0 -3
- package/dist/grammar/index.d.ts.map +0 -1
- package/dist/grammar/index.js +0 -6
- package/dist/methods/autocomplete.d.ts +0 -18
- package/dist/methods/autocomplete.d.ts.map +0 -1
- package/dist/methods/autocomplete.js +0 -109
- package/dist/methods/autoreplace.d.ts +0 -13
- package/dist/methods/autoreplace.d.ts.map +0 -1
- package/dist/methods/autoreplace.js +0 -36
- package/dist/methods/autosuggest.d.ts +0 -28
- package/dist/methods/autosuggest.d.ts.map +0 -1
- package/dist/methods/autosuggest.js +0 -371
- package/dist/methods/evaluate.d.ts +0 -11
- package/dist/methods/evaluate.d.ts.map +0 -1
- package/dist/methods/evaluate.js +0 -32
- package/dist/methods/getBestIndex.d.ts +0 -19
- package/dist/methods/getBestIndex.d.ts.map +0 -1
- package/dist/methods/getBestIndex.js +0 -53
- package/dist/methods/getIndexes.d.ts +0 -17
- package/dist/methods/getIndexes.d.ts.map +0 -1
- package/dist/methods/getIndexes.js +0 -98
- package/dist/methods/index.d.ts +0 -9
- package/dist/methods/index.d.ts.map +0 -1
- package/dist/methods/index.js +0 -18
- package/dist/methods/normalize.d.ts +0 -10
- package/dist/methods/normalize.d.ts.map +0 -1
- package/dist/methods/normalize.js +0 -98
- package/dist/methods/validate.d.ts +0 -11
- package/dist/methods/validate.d.ts.map +0 -1
- package/dist/methods/validate.js +0 -112
- package/dist/parser.d.ts +0 -58
- package/dist/parser.d.ts.map +0 -1
- package/dist/parser.js +0 -137
- package/src/grammar/ParserBase.ts +0 -716
- package/src/grammar/createTokens.ts +0 -513
- package/src/grammar/index.ts +0 -4
- package/src/methods/autocomplete.ts +0 -128
- package/src/methods/autoreplace.ts +0 -46
- package/src/methods/autosuggest.ts +0 -543
- package/src/methods/evaluate.ts +0 -39
- package/src/methods/getBestIndex.ts +0 -53
- package/src/methods/getIndexes.ts +0 -100
- package/src/methods/index.ts +0 -10
- package/src/methods/normalize.ts +0 -137
- package/src/methods/validate.ts +0 -143
- package/src/parser.ts +0 -184
package/dist/parser.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
import { isWhitespace } from "@alanscodelog/utils/isWhitespace";
|
|
8
|
-
import { mixin } from "@alanscodelog/utils/mixin";
|
|
9
|
-
import { createSyntaxDiagramsCode } from "chevrotain";
|
|
10
|
-
import { token } from "./ast/handlers.js";
|
|
11
|
-
import { createTokens } from "./grammar/createTokens.js";
|
|
12
|
-
import { ParserBase } from "./grammar/ParserBase.js";
|
|
13
|
-
import { BooleanParserLibraryError } from "./helpers/errors.js";
|
|
14
|
-
import { checkParserOpts } from "./helpers/parser/checkParserOpts.js";
|
|
15
|
-
import { getUnclosedRightParenCount } from "./helpers/parser/getUnclosedRightParenCount.js";
|
|
16
|
-
import { ERROR_CODES } from "./types/errors.js";
|
|
17
|
-
import { parseParserOptions } from "./helpers/parser/parseParserOptions.js";
|
|
18
|
-
import { seal } from "./helpers/parser/seal.js";
|
|
19
|
-
import { AutocompleteMixin } from "./methods/autocomplete.js";
|
|
20
|
-
import { AutoreplaceMixin } from "./methods/autoreplace.js";
|
|
21
|
-
import { Autosuggest } from "./methods/autosuggest.js";
|
|
22
|
-
import { EvaluateMixin } from "./methods/evaluate.js";
|
|
23
|
-
import { GetBestIndexesMixin } from "./methods/getBestIndex.js";
|
|
24
|
-
import { GetIndexMixin } from "./methods/getIndexes.js";
|
|
25
|
-
import { NormalizeMixin } from "./methods/normalize.js";
|
|
26
|
-
import { ValidateMixin } from "./methods/validate.js";
|
|
27
|
-
class Parser {
|
|
28
|
-
constructor(options) {
|
|
29
|
-
__publicField(this, "options");
|
|
30
|
-
__publicField(this, "rawOptions");
|
|
31
|
-
__publicField(this, "parser");
|
|
32
|
-
__publicField(this, "lexer");
|
|
33
|
-
__publicField(this, "tokens");
|
|
34
|
-
__publicField(this, "info");
|
|
35
|
-
// needed for evaluate and validate so they are only checked on demand
|
|
36
|
-
__publicField(this, "evaluationOptionsChecked", false);
|
|
37
|
-
__publicField(this, "validationOptionsChecked", false);
|
|
38
|
-
this.rawOptions = options ?? {};
|
|
39
|
-
const opts = parseParserOptions(this.rawOptions);
|
|
40
|
-
checkParserOpts(opts);
|
|
41
|
-
this.options = opts;
|
|
42
|
-
const { lexer, tokens, info } = createTokens(opts);
|
|
43
|
-
this.lexer = lexer;
|
|
44
|
-
this.tokens = tokens;
|
|
45
|
-
this.info = info;
|
|
46
|
-
this.parser = new ParserBase(opts, this.tokens, this.info);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Parses a string.
|
|
50
|
-
*/
|
|
51
|
-
parse(input) {
|
|
52
|
-
var _a;
|
|
53
|
-
if (isWhitespace(input)) {
|
|
54
|
-
return token.value(void 0, { start: 0, end: 0 });
|
|
55
|
-
}
|
|
56
|
-
let lexed = this._lex(input);
|
|
57
|
-
const shift = getUnclosedRightParenCount(lexed.tokens, this.tokens);
|
|
58
|
-
if (shift) {
|
|
59
|
-
input = "(".repeat(shift) + input;
|
|
60
|
-
lexed = this._lex(input);
|
|
61
|
-
}
|
|
62
|
-
this.parser.shift = shift;
|
|
63
|
-
this.parser.input = lexed.tokens;
|
|
64
|
-
this.parser.rawInput = input;
|
|
65
|
-
try {
|
|
66
|
-
if (lexed.errors.length > 0)
|
|
67
|
-
throw new Error("Unexpected Lexer Errors");
|
|
68
|
-
this.parser.input = lexed.tokens;
|
|
69
|
-
const res = this.parser.main();
|
|
70
|
-
if (res === void 0) {
|
|
71
|
-
throw new Error("throw");
|
|
72
|
-
}
|
|
73
|
-
if (!((_a = arguments[1]) == null ? void 0 : _a.unsealed))
|
|
74
|
-
seal(res);
|
|
75
|
-
return res;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
if (error.message === "throw")
|
|
78
|
-
error = void 0;
|
|
79
|
-
const err = new BooleanParserLibraryError(ERROR_CODES.PARSER_ERROR, {
|
|
80
|
-
input,
|
|
81
|
-
options: this.rawOptions,
|
|
82
|
-
"parsed options": this.options,
|
|
83
|
-
error,
|
|
84
|
-
"lexed tokens": lexed.tokens,
|
|
85
|
-
"lexer errors": lexed.errors,
|
|
86
|
-
"parser errors": this.parser.errors
|
|
87
|
-
});
|
|
88
|
-
throw err;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
92
|
-
_checkEvaluationOptions() {
|
|
93
|
-
if (!this.evaluationOptionsChecked) {
|
|
94
|
-
checkParserOpts(this.options, true);
|
|
95
|
-
this.evaluationOptionsChecked = true;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
99
|
-
_checkValidationOptions() {
|
|
100
|
-
if (!this.validationOptionsChecked) {
|
|
101
|
-
checkParserOpts(this.options, false, true);
|
|
102
|
-
this.validationOptionsChecked = true;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Generates a railroad diagram for debugging. Does not 100% represent how things are actually handled internally.
|
|
107
|
-
*
|
|
108
|
-
* Not exposed because it uses the raw chevrotain tokens.
|
|
109
|
-
*
|
|
110
|
-
* **Note: It is not 100% accurate. Some special cases are parsed one way but handled internally differently.**
|
|
111
|
-
*/
|
|
112
|
-
_generateRailRoadDiagram() {
|
|
113
|
-
const serialized = this.parser.getSerializedGastProductions();
|
|
114
|
-
const html = createSyntaxDiagramsCode(serialized);
|
|
115
|
-
return html;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* For debugging.
|
|
119
|
-
* Not exposed because it returns the raw chevrotain tokens.
|
|
120
|
-
*/
|
|
121
|
-
_lex(input) {
|
|
122
|
-
return this.lexer.tokenize(input);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
mixin(Parser, [
|
|
126
|
-
AutocompleteMixin,
|
|
127
|
-
AutoreplaceMixin,
|
|
128
|
-
Autosuggest,
|
|
129
|
-
EvaluateMixin,
|
|
130
|
-
ValidateMixin,
|
|
131
|
-
NormalizeMixin,
|
|
132
|
-
GetIndexMixin,
|
|
133
|
-
GetBestIndexesMixin
|
|
134
|
-
]);
|
|
135
|
-
export {
|
|
136
|
-
Parser
|
|
137
|
-
};
|