@witchcraft/expressit 0.0.2
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 +86 -0
- package/dist/ast/builders/array.d.ts +8 -0
- package/dist/ast/builders/array.d.ts.map +1 -0
- package/dist/ast/builders/array.js +31 -0
- package/dist/ast/builders/condition.d.ts +20 -0
- package/dist/ast/builders/condition.d.ts.map +1 -0
- package/dist/ast/builders/condition.js +28 -0
- package/dist/ast/builders/delim.d.ts +11 -0
- package/dist/ast/builders/delim.d.ts.map +1 -0
- package/dist/ast/builders/delim.js +20 -0
- package/dist/ast/builders/error.d.ts +9 -0
- package/dist/ast/builders/error.d.ts.map +1 -0
- package/dist/ast/builders/error.js +16 -0
- package/dist/ast/builders/expression.d.ts +12 -0
- package/dist/ast/builders/expression.d.ts.map +1 -0
- package/dist/ast/builders/expression.js +31 -0
- package/dist/ast/builders/group.d.ts +20 -0
- package/dist/ast/builders/group.d.ts.map +1 -0
- package/dist/ast/builders/group.js +47 -0
- package/dist/ast/builders/index.d.ts +12 -0
- package/dist/ast/builders/index.d.ts.map +1 -0
- package/dist/ast/builders/index.js +24 -0
- package/dist/ast/builders/isFullPos.d.ts +6 -0
- package/dist/ast/builders/isFullPos.d.ts.map +1 -0
- package/dist/ast/builders/isFullPos.js +6 -0
- package/dist/ast/builders/pos.d.ts +21 -0
- package/dist/ast/builders/pos.d.ts.map +1 -0
- package/dist/ast/builders/pos.js +28 -0
- package/dist/ast/builders/token.d.ts +12 -0
- package/dist/ast/builders/token.d.ts.map +1 -0
- package/dist/ast/builders/token.js +26 -0
- package/dist/ast/builders/type.d.ts +6 -0
- package/dist/ast/builders/type.d.ts.map +1 -0
- package/dist/ast/builders/type.js +37 -0
- package/dist/ast/builders/variable.d.ts +17 -0
- package/dist/ast/builders/variable.d.ts.map +1 -0
- package/dist/ast/builders/variable.js +62 -0
- package/dist/ast/classes/ArrayNode.d.ts +18 -0
- package/dist/ast/classes/ArrayNode.d.ts.map +1 -0
- package/dist/ast/classes/ArrayNode.js +55 -0
- package/dist/ast/classes/Condition.d.ts +13 -0
- package/dist/ast/classes/Condition.d.ts.map +1 -0
- package/dist/ast/classes/Condition.js +21 -0
- package/dist/ast/classes/ConditionNode.d.ts +73 -0
- package/dist/ast/classes/ConditionNode.d.ts.map +1 -0
- package/dist/ast/classes/ConditionNode.js +101 -0
- package/dist/ast/classes/ErrorToken.d.ts +27 -0
- package/dist/ast/classes/ErrorToken.d.ts.map +1 -0
- package/dist/ast/classes/ErrorToken.js +47 -0
- package/dist/ast/classes/Expression.d.ts +13 -0
- package/dist/ast/classes/Expression.d.ts.map +1 -0
- package/dist/ast/classes/Expression.js +19 -0
- package/dist/ast/classes/ExpressionNode.d.ts +21 -0
- package/dist/ast/classes/ExpressionNode.d.ts.map +1 -0
- package/dist/ast/classes/ExpressionNode.js +57 -0
- package/dist/ast/classes/GroupNode.d.ts +64 -0
- package/dist/ast/classes/GroupNode.d.ts.map +1 -0
- package/dist/ast/classes/GroupNode.js +69 -0
- package/dist/ast/classes/Node.d.ts +22 -0
- package/dist/ast/classes/Node.d.ts.map +1 -0
- package/dist/ast/classes/Node.js +28 -0
- package/dist/ast/classes/Token.d.ts +27 -0
- package/dist/ast/classes/Token.d.ts.map +1 -0
- package/dist/ast/classes/Token.js +28 -0
- package/dist/ast/classes/ValidToken.d.ts +26 -0
- package/dist/ast/classes/ValidToken.d.ts.map +1 -0
- package/dist/ast/classes/ValidToken.js +49 -0
- package/dist/ast/classes/VariableNode.d.ts +33 -0
- package/dist/ast/classes/VariableNode.d.ts.map +1 -0
- package/dist/ast/classes/VariableNode.js +58 -0
- package/dist/ast/classes/index.d.ts +12 -0
- package/dist/ast/classes/index.d.ts.map +1 -0
- package/dist/ast/classes/index.js +24 -0
- package/dist/ast/handlers.d.ts +42 -0
- package/dist/ast/handlers.d.ts.map +1 -0
- package/dist/ast/handlers.js +150 -0
- package/dist/ast/index.d.ts +4 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/index.js +8 -0
- package/dist/examples/advancedValueComparer.d.ts +3 -0
- package/dist/examples/advancedValueComparer.d.ts.map +1 -0
- package/dist/examples/advancedValueComparer.js +28 -0
- package/dist/examples/shortcutContextParser.d.ts +22 -0
- package/dist/examples/shortcutContextParser.d.ts.map +1 -0
- package/dist/examples/shortcutContextParser.js +126 -0
- package/dist/global.d.js +1 -0
- package/dist/grammar/ParserBase.d.ts +51 -0
- package/dist/grammar/ParserBase.d.ts.map +1 -0
- package/dist/grammar/ParserBase.js +516 -0
- package/dist/grammar/createTokens.d.ts +56 -0
- package/dist/grammar/createTokens.d.ts.map +1 -0
- package/dist/grammar/createTokens.js +843 -0
- package/dist/grammar/index.d.ts +3 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +6 -0
- package/dist/helpers/errors.d.ts +9 -0
- package/dist/helpers/errors.d.ts.map +1 -0
- package/dist/helpers/errors.js +41 -0
- package/dist/helpers/general/applyBoolean.d.ts +3 -0
- package/dist/helpers/general/applyBoolean.d.ts.map +1 -0
- package/dist/helpers/general/applyBoolean.js +17 -0
- package/dist/helpers/general/applyPrefix.d.ts +4 -0
- package/dist/helpers/general/applyPrefix.d.ts.map +1 -0
- package/dist/helpers/general/applyPrefix.js +9 -0
- package/dist/helpers/general/defaultConditionNormalizer.d.ts +3 -0
- package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +1 -0
- package/dist/helpers/general/defaultConditionNormalizer.js +6 -0
- package/dist/helpers/general/defaultKeyParser.d.ts +3 -0
- package/dist/helpers/general/defaultKeyParser.d.ts.map +1 -0
- package/dist/helpers/general/defaultKeyParser.js +8 -0
- package/dist/helpers/general/defaultPrefixApplier.d.ts +3 -0
- package/dist/helpers/general/defaultPrefixApplier.d.ts.map +1 -0
- package/dist/helpers/general/defaultPrefixApplier.js +6 -0
- package/dist/helpers/general/defaultValueComparer.d.ts +3 -0
- package/dist/helpers/general/defaultValueComparer.d.ts.map +1 -0
- package/dist/helpers/general/defaultValueComparer.js +6 -0
- package/dist/helpers/general/index.d.ts +7 -0
- package/dist/helpers/general/index.d.ts.map +1 -0
- package/dist/helpers/general/index.js +14 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +8 -0
- package/dist/helpers/parser/assignParents.d.ts +4 -0
- package/dist/helpers/parser/assignParents.d.ts.map +1 -0
- package/dist/helpers/parser/assignParents.js +71 -0
- package/dist/helpers/parser/checkParserOpts.d.ts +3 -0
- package/dist/helpers/parser/checkParserOpts.d.ts.map +1 -0
- package/dist/helpers/parser/checkParserOpts.js +126 -0
- package/dist/helpers/parser/extractPosition.d.ts +9 -0
- package/dist/helpers/parser/extractPosition.d.ts.map +1 -0
- package/dist/helpers/parser/extractPosition.js +9 -0
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +5 -0
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +1 -0
- package/dist/helpers/parser/getUnclosedRightParenCount.js +20 -0
- package/dist/helpers/parser/index.d.ts +9 -0
- package/dist/helpers/parser/index.d.ts.map +1 -0
- package/dist/helpers/parser/index.js +18 -0
- package/dist/helpers/parser/parseParserOptions.d.ts +4 -0
- package/dist/helpers/parser/parseParserOptions.d.ts.map +1 -0
- package/dist/helpers/parser/parseParserOptions.js +45 -0
- package/dist/helpers/parser/seal.d.ts +8 -0
- package/dist/helpers/parser/seal.d.ts.map +1 -0
- package/dist/helpers/parser/seal.js +10 -0
- package/dist/helpers/parser/setParent.d.ts +6 -0
- package/dist/helpers/parser/setParent.d.ts.map +1 -0
- package/dist/helpers/parser/setParent.js +4 -0
- package/dist/helpers/parser/unescape.d.ts +3 -0
- package/dist/helpers/parser/unescape.d.ts.map +1 -0
- package/dist/helpers/parser/unescape.js +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/methods/autocomplete.d.ts +18 -0
- package/dist/methods/autocomplete.d.ts.map +1 -0
- package/dist/methods/autocomplete.js +109 -0
- package/dist/methods/autoreplace.d.ts +13 -0
- package/dist/methods/autoreplace.d.ts.map +1 -0
- package/dist/methods/autoreplace.js +36 -0
- package/dist/methods/autosuggest.d.ts +28 -0
- package/dist/methods/autosuggest.d.ts.map +1 -0
- package/dist/methods/autosuggest.js +371 -0
- package/dist/methods/evaluate.d.ts +11 -0
- package/dist/methods/evaluate.d.ts.map +1 -0
- package/dist/methods/evaluate.js +30 -0
- package/dist/methods/getBestIndex.d.ts +19 -0
- package/dist/methods/getBestIndex.d.ts.map +1 -0
- package/dist/methods/getBestIndex.js +53 -0
- package/dist/methods/getIndexes.d.ts +17 -0
- package/dist/methods/getIndexes.d.ts.map +1 -0
- package/dist/methods/getIndexes.js +97 -0
- package/dist/methods/index.d.ts +9 -0
- package/dist/methods/index.d.ts.map +1 -0
- package/dist/methods/index.js +18 -0
- package/dist/methods/normalize.d.ts +12 -0
- package/dist/methods/normalize.d.ts.map +1 -0
- package/dist/methods/normalize.js +99 -0
- package/dist/methods/validate.d.ts +11 -0
- package/dist/methods/validate.d.ts.map +1 -0
- package/dist/methods/validate.js +111 -0
- package/dist/package.js +7 -0
- package/dist/package.json.js +193 -0
- package/dist/parser.d.ts +58 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +136 -0
- package/dist/types/ast.d.ts +70 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js +29 -0
- package/dist/types/autocomplete.d.ts +143 -0
- package/dist/types/autocomplete.d.ts.map +1 -0
- package/dist/types/autocomplete.js +24 -0
- package/dist/types/errors.d.ts +34 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +10 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/parser.d.ts +451 -0
- package/dist/types/parser.d.ts.map +1 -0
- package/dist/types/parser.js +1 -0
- package/dist/utils/extractTokens.d.ts +8 -0
- package/dist/utils/extractTokens.d.ts.map +1 -0
- package/dist/utils/extractTokens.js +50 -0
- package/dist/utils/getCursorInfo.d.ts +7 -0
- package/dist/utils/getCursorInfo.d.ts.map +1 -0
- package/dist/utils/getCursorInfo.js +86 -0
- package/dist/utils/getOppositeDelimiter.d.ts +6 -0
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -0
- package/dist/utils/getOppositeDelimiter.js +35 -0
- package/dist/utils/getSurroundingErrors.d.ts +25 -0
- package/dist/utils/getSurroundingErrors.d.ts.map +1 -0
- package/dist/utils/getSurroundingErrors.js +37 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/isBracket.d.ts +3 -0
- package/dist/utils/isBracket.d.ts.map +1 -0
- package/dist/utils/isBracket.js +7 -0
- package/dist/utils/isDelimiter.d.ts +6 -0
- package/dist/utils/isDelimiter.d.ts.map +1 -0
- package/dist/utils/isDelimiter.js +17 -0
- package/dist/utils/isParen.d.ts +3 -0
- package/dist/utils/isParen.d.ts.map +1 -0
- package/dist/utils/isParen.js +7 -0
- package/dist/utils/isQuote.d.ts +4 -0
- package/dist/utils/isQuote.d.ts.map +1 -0
- package/dist/utils/isQuote.js +7 -0
- package/dist/utils/prettyAst.d.ts +35 -0
- package/dist/utils/prettyAst.d.ts.map +1 -0
- package/dist/utils/prettyAst.js +112 -0
- package/package.json +152 -0
- package/src/ast/builders/array.ts +45 -0
- package/src/ast/builders/condition.ts +56 -0
- package/src/ast/builders/delim.ts +39 -0
- package/src/ast/builders/error.ts +22 -0
- package/src/ast/builders/expression.ts +66 -0
- package/src/ast/builders/group.ts +79 -0
- package/src/ast/builders/index.ts +13 -0
- package/src/ast/builders/isFullPos.ts +10 -0
- package/src/ast/builders/pos.ts +57 -0
- package/src/ast/builders/token.ts +46 -0
- package/src/ast/builders/type.ts +32 -0
- package/src/ast/builders/variable.ts +89 -0
- package/src/ast/classes/ArrayNode.ts +46 -0
- package/src/ast/classes/Condition.ts +22 -0
- package/src/ast/classes/ConditionNode.ts +141 -0
- package/src/ast/classes/ErrorToken.ts +49 -0
- package/src/ast/classes/Expression.ts +26 -0
- package/src/ast/classes/ExpressionNode.ts +62 -0
- package/src/ast/classes/GroupNode.ts +127 -0
- package/src/ast/classes/Node.ts +47 -0
- package/src/ast/classes/Token.ts +59 -0
- package/src/ast/classes/ValidToken.ts +56 -0
- package/src/ast/classes/VariableNode.ts +67 -0
- package/src/ast/classes/index.ts +13 -0
- package/src/ast/handlers.ts +190 -0
- package/src/ast/index.ts +5 -0
- package/src/examples/advancedValueComparer.ts +31 -0
- package/src/examples/shortcutContextParser.ts +140 -0
- package/src/global.d.ts +4 -0
- package/src/grammar/ParserBase.ts +715 -0
- package/src/grammar/createTokens.ts +512 -0
- package/src/grammar/index.ts +4 -0
- package/src/helpers/errors.ts +45 -0
- package/src/helpers/general/applyBoolean.ts +9 -0
- package/src/helpers/general/applyPrefix.ts +7 -0
- package/src/helpers/general/defaultConditionNormalizer.ts +9 -0
- package/src/helpers/general/defaultKeyParser.ts +8 -0
- package/src/helpers/general/defaultPrefixApplier.ts +7 -0
- package/src/helpers/general/defaultValueComparer.ts +7 -0
- package/src/helpers/general/index.ts +8 -0
- package/src/helpers/index.ts +5 -0
- package/src/helpers/parser/assignParents.ts +51 -0
- package/src/helpers/parser/checkParserOpts.ts +143 -0
- package/src/helpers/parser/extractPosition.ts +15 -0
- package/src/helpers/parser/getUnclosedRightParenCount.ts +22 -0
- package/src/helpers/parser/index.ts +10 -0
- package/src/helpers/parser/parseParserOptions.ts +54 -0
- package/src/helpers/parser/seal.ts +14 -0
- package/src/helpers/parser/setParent.ts +5 -0
- package/src/helpers/parser/unescape.ts +4 -0
- package/src/index.ts +7 -0
- package/src/methods/autocomplete.ts +128 -0
- package/src/methods/autoreplace.ts +46 -0
- package/src/methods/autosuggest.ts +543 -0
- package/src/methods/evaluate.ts +37 -0
- package/src/methods/getBestIndex.ts +53 -0
- package/src/methods/getIndexes.ts +99 -0
- package/src/methods/index.ts +10 -0
- package/src/methods/normalize.ts +138 -0
- package/src/methods/validate.ts +141 -0
- package/src/package.js +11 -0
- package/src/parser.ts +183 -0
- package/src/types/ast.ts +148 -0
- package/src/types/autocomplete.ts +152 -0
- package/src/types/errors.ts +40 -0
- package/src/types/index.ts +6 -0
- package/src/types/parser.ts +479 -0
- package/src/utils/extractTokens.ts +67 -0
- package/src/utils/getCursorInfo.ts +106 -0
- package/src/utils/getOppositeDelimiter.ts +36 -0
- package/src/utils/getSurroundingErrors.ts +57 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/isBracket.ts +6 -0
- package/src/utils/isDelimiter.ts +18 -0
- package/src/utils/isParen.ts +6 -0
- package/src/utils/isQuote.ts +6 -0
- package/src/utils/prettyAst.ts +152 -0
|
@@ -0,0 +1,516 @@
|
|
|
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 { isArray, unreachable } from "@alanscodelog/utils";
|
|
8
|
+
import { EmbeddedActionsParser, EOF, tokenMatcher } from "chevrotain";
|
|
9
|
+
import { pos } from "../ast/builders/pos.js";
|
|
10
|
+
import { ArrayNode } from "../ast/classes/ArrayNode.js";
|
|
11
|
+
import { ConditionNode } from "../ast/classes/ConditionNode.js";
|
|
12
|
+
import { ErrorToken } from "../ast/classes/ErrorToken.js";
|
|
13
|
+
import { VariableNode } from "../ast/classes/VariableNode.js";
|
|
14
|
+
import { token, operator, expression, variable, condition, group, array, delimiter } from "../ast/handlers.js";
|
|
15
|
+
import { extractPosition } from "../helpers/parser/extractPosition.js";
|
|
16
|
+
import { Parser } from "../parser.js";
|
|
17
|
+
import { TOKEN_TYPE } from "../types/ast.js";
|
|
18
|
+
function processToken(token2, shift) {
|
|
19
|
+
let val = token2.image;
|
|
20
|
+
if (token2.isInsertedInRecovery)
|
|
21
|
+
val = void 0;
|
|
22
|
+
return [val, extractPosition(token2, shift)];
|
|
23
|
+
}
|
|
24
|
+
class ParserBase extends EmbeddedActionsParser {
|
|
25
|
+
constructor(opts, t, { customOpAlsoNegation, expandedSepAlsoCustom }) {
|
|
26
|
+
super(t, {
|
|
27
|
+
recoveryEnabled: true
|
|
28
|
+
// skipValidations: true
|
|
29
|
+
});
|
|
30
|
+
__publicField(this, "rawInput");
|
|
31
|
+
__publicField(this, "subParser");
|
|
32
|
+
__publicField(this, "subParser2");
|
|
33
|
+
const $ = this;
|
|
34
|
+
$.RULE("main", () => {
|
|
35
|
+
const res = $.SUBRULE($.boolOr);
|
|
36
|
+
$.CONSUME(EOF);
|
|
37
|
+
return $.ACTION(() => {
|
|
38
|
+
if (res === void 0) {
|
|
39
|
+
const error = token.value(void 0, { start: 0, end: 0 });
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
return res;
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
$.RULE("boolOr", () => {
|
|
46
|
+
const pairs = [];
|
|
47
|
+
const DEF = () => {
|
|
48
|
+
const exp = $.SUBRULE2($.boolAnd);
|
|
49
|
+
const extras = [];
|
|
50
|
+
let next = $.LA(1);
|
|
51
|
+
$.OPTION1({
|
|
52
|
+
GATE: () => opts.onMissingBooleanOperator === "or" && (tokenMatcher(next, t.VALUE) || tokenMatcher(next, t.QUOTE_ANY) || tokenMatcher(next, t.PAREN_L) || tokenMatcher(next, t.EXP_PROP_OP) || tokenMatcher(next, t.REGEX_START) || tokenMatcher(next, t.CUSTOM_PROP_OP)),
|
|
53
|
+
DEF: () => {
|
|
54
|
+
let dummyOp;
|
|
55
|
+
const cond = $.SUBRULE3($.condition);
|
|
56
|
+
$.ACTION(() => {
|
|
57
|
+
const prev = $.LA(-1);
|
|
58
|
+
const start = prev.endOffset + 1;
|
|
59
|
+
dummyOp = operator.or("", pos({ start }, { fill: true }));
|
|
60
|
+
});
|
|
61
|
+
extras.push([dummyOp, cond]);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
next = $.LA(1);
|
|
65
|
+
pairs.push([exp, tokenMatcher(next, t.OPERATOR_OR) ? operator.or(...processToken(next, $.shift)) : void 0]);
|
|
66
|
+
for (const extra of extras) {
|
|
67
|
+
pairs[pairs.length - 1].splice(1, 1, extra[0]);
|
|
68
|
+
pairs.push([extra[1]]);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
$.MANY_SEP({ SEP: t.OPERATOR_OR, DEF });
|
|
72
|
+
$.OPTION({
|
|
73
|
+
// many sep sometimes fails to recover when it technically could
|
|
74
|
+
GATE: () => pairs.length === 0 && tokenMatcher($.LA(1), t.OPERATOR_OR),
|
|
75
|
+
DEF: () => {
|
|
76
|
+
$.MANY(() => {
|
|
77
|
+
const next = $.CONSUME(t.OPERATOR_OR);
|
|
78
|
+
pairs.push([void 0, operator.or(...processToken(next, $.shift))]);
|
|
79
|
+
while (tokenMatcher($.LA(1), t.VALUE) || tokenMatcher($.LA(1), t.QUOTE_ANY) || tokenMatcher($.LA(1), t.PAREN_L)) {
|
|
80
|
+
pairs.push([$.SUBRULE3($.condition)]);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return $.ACTION(() => {
|
|
86
|
+
let res = pairs[pairs.length - 1][0];
|
|
87
|
+
for (let i = pairs.length - 1; i > 0; i--) {
|
|
88
|
+
const before = pairs[i - 1];
|
|
89
|
+
if (res === void 0 && before === void 0)
|
|
90
|
+
return void 0;
|
|
91
|
+
res = expression(before[0], before[1], res);
|
|
92
|
+
}
|
|
93
|
+
return res;
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
$.RULE("boolAnd", () => {
|
|
97
|
+
const pairs = [];
|
|
98
|
+
const DEF = () => {
|
|
99
|
+
const exp = $.SUBRULE2($.condition);
|
|
100
|
+
const extras = [];
|
|
101
|
+
let next = $.LA(1);
|
|
102
|
+
$.OPTION1({
|
|
103
|
+
GATE: () => ["error", "and"].includes(opts.onMissingBooleanOperator) && (tokenMatcher(next, t.VALUE) || tokenMatcher(next, t.QUOTE_ANY) || tokenMatcher(next, t.PAREN_L) || tokenMatcher(next, t.EXP_PROP_OP) || tokenMatcher(next, t.REGEX_START) || tokenMatcher(next, t.CUSTOM_PROP_OP)),
|
|
104
|
+
DEF: () => {
|
|
105
|
+
$.MANY2(() => {
|
|
106
|
+
let dummyOp;
|
|
107
|
+
const cond = $.SUBRULE3($.condition);
|
|
108
|
+
$.ACTION(() => {
|
|
109
|
+
if (opts.onMissingBooleanOperator === "and") {
|
|
110
|
+
const prev = $.LA(-1);
|
|
111
|
+
const start = prev.endOffset + 1;
|
|
112
|
+
dummyOp = operator.and("", pos({ start }, { fill: true }));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
extras.push([dummyOp, cond]);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
next = $.LA(1);
|
|
120
|
+
pairs.push([exp, tokenMatcher(next, t.OPERATOR_AND) ? operator.and(...processToken(next, $.shift)) : void 0]);
|
|
121
|
+
for (const extra of extras) {
|
|
122
|
+
pairs[pairs.length - 1].splice(1, 1, extra[0]);
|
|
123
|
+
pairs.push([extra[1]]);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
$.MANY_SEP({ SEP: t.OPERATOR_AND, DEF });
|
|
127
|
+
$.OPTION({
|
|
128
|
+
GATE: () => pairs.length === 0 && tokenMatcher($.LA(1), t.OPERATOR_AND),
|
|
129
|
+
DEF: () => {
|
|
130
|
+
$.MANY(() => {
|
|
131
|
+
const next = $.CONSUME(t.OPERATOR_AND);
|
|
132
|
+
pairs.push([void 0, operator.and(...processToken(next, $.shift))]);
|
|
133
|
+
while (tokenMatcher($.LA(1), t.VALUE) || tokenMatcher($.LA(1), t.QUOTE_ANY) || tokenMatcher($.LA(1), t.PAREN_L)) {
|
|
134
|
+
pairs.push([$.SUBRULE3($.condition)]);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return $.ACTION(() => {
|
|
140
|
+
if (pairs.length === 0)
|
|
141
|
+
return void 0;
|
|
142
|
+
let res = pairs[pairs.length - 1][0];
|
|
143
|
+
for (let i = pairs.length - 1; i > 0; i--) {
|
|
144
|
+
const before = pairs[i - 1];
|
|
145
|
+
res = expression(before[0], before[1], res);
|
|
146
|
+
}
|
|
147
|
+
return res;
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
$.RULE("condition", () => {
|
|
151
|
+
const not = $.OPTION(() => $.SUBRULE($.not));
|
|
152
|
+
const property = $.OPTION2({
|
|
153
|
+
GATE: () => tokenMatcher($.LA(1), t.EXP_PROP_OP) || tokenMatcher($.LA(1), t.CUSTOM_PROP_OP) || tokenMatcher($.LA(2), t.EXP_PROP_OP) || tokenMatcher($.LA(2), t.CUSTOM_PROP_OP) || customOpAlsoNegation && (tokenMatcher($.LA(2), t.SYM_NOT) || tokenMatcher($.LA(0), t.SYM_NOT) && tokenMatcher($.LA(1), t.SYM_NOT)),
|
|
154
|
+
DEF: () => $.SUBRULE($.property)
|
|
155
|
+
});
|
|
156
|
+
const propVal = $.ACTION(() => {
|
|
157
|
+
var _a;
|
|
158
|
+
return ((_a = property == null ? void 0 : property.prop) == null ? void 0 : _a.value) === void 0 ? void 0 : property.prop.value instanceof ErrorToken ? "" : property.prop.value.value;
|
|
159
|
+
});
|
|
160
|
+
const propOpVal = $.ACTION(() => (property == null ? void 0 : property.rest.propertyOperator) === void 0 ? void 0 : property.rest.propertyOperator instanceof ErrorToken ? "" : property.rest.propertyOperator.value);
|
|
161
|
+
const isExpanded = $.ACTION(() => ((property == null ? void 0 : property.rest.sepL) ?? (property == null ? void 0 : property.rest.sepR)) !== void 0);
|
|
162
|
+
const convertRegexValues = $.ACTION(() => typeof opts.regexValues === "function" && !opts.regexValues(propVal, propOpVal, isExpanded));
|
|
163
|
+
const convertArrayValues = $.ACTION(() => typeof opts.arrayValues === "function" && !opts.arrayValues(propVal, propOpVal, isExpanded));
|
|
164
|
+
let value = $.OR2([
|
|
165
|
+
{
|
|
166
|
+
GATE: () => opts.prefixableGroups && property === void 0 && $.LA(1).tokenType !== t.PAREN_L && // moves to parsing group below
|
|
167
|
+
(tokenMatcher($.LA(1), t.VALUE) && (tokenMatcher($.LA(2), t.PAREN_L) || // a(
|
|
168
|
+
tokenMatcher($.LA(2), t.QUOTE_ANY) && tokenMatcher($.LA(3), t.PAREN_L)) || tokenMatcher($.LA(1), t.QUOTE_ANY) && (tokenMatcher($.LA(2), t.PAREN_L) || // "(
|
|
169
|
+
tokenMatcher($.LA(2), t.VALUE) && (tokenMatcher($.LA(3), t.PAREN_L) || // "a(
|
|
170
|
+
tokenMatcher($.LA(3), t.QUOTE_ANY) && tokenMatcher($.LA(4), t.PAREN_L)))),
|
|
171
|
+
ALT: () => $.SUBRULE($.variable, { ARGS: [{ unprefixed: true }] })
|
|
172
|
+
// un-prefixed
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
GATE: () => $.LA(1).tokenType !== t.PAREN_L,
|
|
176
|
+
ALT: () => $.SUBRULE2($.variable)
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
GATE: () => $.LA(1).tokenType === t.PAREN_L,
|
|
180
|
+
ALT: () => $.SUBRULE2($.plainGroup, { ARGS: [{ onlyValues: property !== void 0, convertRegexValues, convertArrayValues }] })
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
GATE: () => $.LA(1).tokenType === t.BRACKET_L,
|
|
184
|
+
ALT: () => $.SUBRULE2($.plainBracketGroup, { ARGS: [{ convertArrayValues }] })
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
GATE: () => not !== void 0 || property !== void 0 || $.LA(1).tokenType === EOF,
|
|
188
|
+
ALT: () => void 0
|
|
189
|
+
}
|
|
190
|
+
]);
|
|
191
|
+
let group$1 = $.OPTION3({
|
|
192
|
+
GATE: () => !(value instanceof ArrayNode) && !isArray(value) && (!value || opts.prefixableGroups) && $.LA(1).tokenType === t.PAREN_L,
|
|
193
|
+
// is not already plain group
|
|
194
|
+
DEF: () => $.SUBRULE3($.plainGroup, { ARGS: [{ onlyValues: property !== void 0, convertRegexValues, convertArrayValues }] })
|
|
195
|
+
});
|
|
196
|
+
return $.ACTION(() => {
|
|
197
|
+
var _a, _b, _c, _d, _e;
|
|
198
|
+
if (isArray(value)) {
|
|
199
|
+
group$1 = value;
|
|
200
|
+
value = void 0;
|
|
201
|
+
}
|
|
202
|
+
if (convertRegexValues && value instanceof VariableNode && ((_a = value.quote) == null ? void 0 : _a.left.type) === TOKEN_TYPE.REGEX) {
|
|
203
|
+
value = variable(void 0, void 0, token.value(
|
|
204
|
+
(((_c = (_b = value.quote) == null ? void 0 : _b.left) == null ? void 0 : _c.value) ?? "") + (value.value.value ?? "") + (((_e = (_d = value.quote) == null ? void 0 : _d.right) == null ? void 0 : _e.value) ?? ""),
|
|
205
|
+
pos(value)
|
|
206
|
+
), void 0);
|
|
207
|
+
}
|
|
208
|
+
if (group$1) {
|
|
209
|
+
if (property) {
|
|
210
|
+
return condition(not, property == null ? void 0 : property.prop, property == null ? void 0 : property.rest, group(void 0, void 0, ...group$1));
|
|
211
|
+
}
|
|
212
|
+
if (value) {
|
|
213
|
+
return group(void 0, condition(not, void 0, void 0, value), ...group$1);
|
|
214
|
+
}
|
|
215
|
+
return group(not, value, ...group$1);
|
|
216
|
+
}
|
|
217
|
+
if ([not, property, value].every((_) => _ === void 0))
|
|
218
|
+
return void 0;
|
|
219
|
+
return condition(not, property == null ? void 0 : property.prop, property == null ? void 0 : property.rest, value);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
$.RULE("property", () => {
|
|
223
|
+
const prop = $.OPTION3(() => $.SUBRULE($.variable, { ARGS: [{ unprefixed: true }] }));
|
|
224
|
+
const rest = $.OR([
|
|
225
|
+
{
|
|
226
|
+
ALT: () => {
|
|
227
|
+
let sepL = $.CONSUME(t.EXP_PROP_OP);
|
|
228
|
+
sepL && (sepL = token.sep(...processToken(sepL, $.shift)));
|
|
229
|
+
let op = $.OPTION4(() => $.CONSUME2(t.VALUE_UNQUOTED));
|
|
230
|
+
op && (op = token.value(...processToken(op, $.shift)));
|
|
231
|
+
let sepR = $.OPTION5(() => $.CONSUME2(t.EXP_PROP_OP));
|
|
232
|
+
sepR && (sepR = token.sep(...processToken(sepR, $.shift)));
|
|
233
|
+
if (expandedSepAlsoCustom && op === void 0 && sepR === void 0) {
|
|
234
|
+
op = sepL;
|
|
235
|
+
op.type = TOKEN_TYPE.OP_CUSTOM;
|
|
236
|
+
sepL = void 0;
|
|
237
|
+
}
|
|
238
|
+
return { sepL, sepR, propertyOperator: op };
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
ALT: () => {
|
|
243
|
+
let op = $.CONSUME(t.CUSTOM_PROP_OP);
|
|
244
|
+
if (!op.isInsertedInRecovery)
|
|
245
|
+
op = token.custom(...processToken(op, $.shift));
|
|
246
|
+
return { propertyOperator: op };
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
GATE: () => customOpAlsoNegation,
|
|
251
|
+
ALT: () => {
|
|
252
|
+
let op = $.CONSUME2(t.SYM_NOT);
|
|
253
|
+
if (!op.isInsertedInRecovery)
|
|
254
|
+
op = token.custom(...processToken(op, $.shift));
|
|
255
|
+
return { propertyOperator: op };
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
]);
|
|
259
|
+
return { prop, rest };
|
|
260
|
+
});
|
|
261
|
+
$.RULE("plainGroup", ({ onlyValues = false, convertRegexValues = false, convertArrayValues = false } = {}) => {
|
|
262
|
+
const parenL = $.SUBRULE1($.parenL);
|
|
263
|
+
let parenLeftCount = 0;
|
|
264
|
+
let start;
|
|
265
|
+
let end;
|
|
266
|
+
const condition2 = $.OPTION1({
|
|
267
|
+
GATE: () => !onlyValues,
|
|
268
|
+
DEF: () => $.SUBRULE1($.boolOr)
|
|
269
|
+
});
|
|
270
|
+
if (onlyValues && $.LA(1).tokenType !== EOF) {
|
|
271
|
+
while (!tokenMatcher($.LA(1), EOF) && (!tokenMatcher($.LA(1), t.PAREN_R) || parenLeftCount !== 0)) {
|
|
272
|
+
const token2 = $.CONSUME(t.ANY);
|
|
273
|
+
start ?? (start = extractPosition(token2, this.shift).start);
|
|
274
|
+
if (tokenMatcher(token2, t.PAREN_L)) {
|
|
275
|
+
parenLeftCount++;
|
|
276
|
+
}
|
|
277
|
+
if (tokenMatcher(token2, t.PAREN_R)) {
|
|
278
|
+
parenLeftCount--;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (start !== void 0) {
|
|
283
|
+
end ?? (end = extractPosition($.LA(0), this.shift).end);
|
|
284
|
+
}
|
|
285
|
+
const parenR = $.OPTION2(() => $.SUBRULE1($.parenR));
|
|
286
|
+
return $.ACTION(() => {
|
|
287
|
+
if (start !== void 0) {
|
|
288
|
+
const subInput = this.rawInput.slice(start, end);
|
|
289
|
+
if (this.subParser === void 0) {
|
|
290
|
+
this.subParser = new Parser({
|
|
291
|
+
...opts,
|
|
292
|
+
customPropertyOperators: [],
|
|
293
|
+
expandedPropertySeparator: void 0,
|
|
294
|
+
regexValues: convertRegexValues,
|
|
295
|
+
arrayValues: convertArrayValues
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const parsed = this.subParser.parse(" ".repeat(start) + subInput, { unsealed: true });
|
|
299
|
+
return [parenL, parsed, parenR];
|
|
300
|
+
}
|
|
301
|
+
return [parenL, condition2, parenR];
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
$.RULE("plainBracketGroup", ({ convertArrayValues = false } = {}) => {
|
|
305
|
+
const bracketL = $.SUBRULE1($.bracketL);
|
|
306
|
+
const start = bracketL.start;
|
|
307
|
+
const values = [];
|
|
308
|
+
$.MANY({
|
|
309
|
+
GATE: () => !convertArrayValues,
|
|
310
|
+
DEF: () => values.push($.SUBRULE($.variable, { ARGS: [{ unprefixed: false, bracketVal: true }] }))
|
|
311
|
+
});
|
|
312
|
+
if (convertArrayValues && $.LA(1).tokenType !== EOF) {
|
|
313
|
+
while (!tokenMatcher($.LA(1), EOF) && !tokenMatcher($.LA(1), t.BRACKET_R)) {
|
|
314
|
+
$.CONSUME(t.ANY);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const bracketR = $.OPTION2(() => $.SUBRULE1($.bracketR));
|
|
318
|
+
const end = bracketR == null ? void 0 : bracketR.end;
|
|
319
|
+
return $.ACTION(() => {
|
|
320
|
+
if (!convertArrayValues)
|
|
321
|
+
return array(bracketL, values, bracketR);
|
|
322
|
+
const subInput = this.rawInput.slice(start, end);
|
|
323
|
+
if (this.subParser2 === void 0) {
|
|
324
|
+
this.subParser2 = new Parser({
|
|
325
|
+
...opts,
|
|
326
|
+
customPropertyOperators: [],
|
|
327
|
+
expandedPropertySeparator: void 0,
|
|
328
|
+
arrayValues: false
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
const parsed = this.subParser2.parse(" ".repeat(start) + subInput, { unsealed: true });
|
|
332
|
+
if (parsed instanceof ConditionNode) {
|
|
333
|
+
return parsed.value;
|
|
334
|
+
}
|
|
335
|
+
return parsed;
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
$.RULE("not", () => {
|
|
339
|
+
const op = $.CONSUME(t.OPERATOR_NOT);
|
|
340
|
+
return $.ACTION(() => operator.not(...processToken(op, $.shift)));
|
|
341
|
+
});
|
|
342
|
+
$.RULE("variable", ({ unprefixed = false, bracketVal = false } = {}) => {
|
|
343
|
+
let prefix = $.OPTION({
|
|
344
|
+
GATE: () => !unprefixed && opts.prefixableStrings !== void 0 && tokenMatcher($.LA(2), t.QUOTE_ANY) && tokenMatcher($.LA(4), $.LA(2).tokenType) && opts.prefixableStrings.includes($.LA(1).image),
|
|
345
|
+
DEF: () => $.SUBRULE7($.valueUnquoted, { ARGS: [{ bracketVal, onlyToken: true }] })
|
|
346
|
+
});
|
|
347
|
+
prefix && (prefix = token.value(...processToken(prefix, $.shift)));
|
|
348
|
+
const ARGS = [{ bracketVal }];
|
|
349
|
+
const val = $.OR([
|
|
350
|
+
{
|
|
351
|
+
ALT: () => {
|
|
352
|
+
const quoteL = $.SUBRULE($.quoteDouble);
|
|
353
|
+
const value = $.OPTION1(() => $.OR1([
|
|
354
|
+
{ ALT: () => $.SUBRULE($.valueUnquoted, { ARGS }) },
|
|
355
|
+
{ ALT: () => $.SUBRULE($.valueNotDouble) }
|
|
356
|
+
]));
|
|
357
|
+
const quoteR = $.SUBRULE2($.quoteDouble);
|
|
358
|
+
return $.ACTION(() => variable(prefix, quoteL, value, quoteR));
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
ALT: () => {
|
|
363
|
+
const quoteL = $.SUBRULE($.quoteSingle);
|
|
364
|
+
const value = $.OPTION2(() => $.OR2([
|
|
365
|
+
{ ALT: () => $.SUBRULE2($.valueUnquoted, { ARGS }) },
|
|
366
|
+
{ ALT: () => $.SUBRULE($.valueNotSingle) }
|
|
367
|
+
]));
|
|
368
|
+
const quoteR = $.SUBRULE2($.quoteSingle);
|
|
369
|
+
return $.ACTION(() => variable(prefix, quoteL, value, quoteR));
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
ALT: () => {
|
|
374
|
+
const quoteL = $.SUBRULE($.quoteBacktick);
|
|
375
|
+
const value = $.OPTION3(() => $.OR3([
|
|
376
|
+
{ ALT: () => $.SUBRULE3($.valueUnquoted, { ARGS }) },
|
|
377
|
+
{ ALT: () => $.SUBRULE($.valueNotBacktick) }
|
|
378
|
+
]));
|
|
379
|
+
const quoteR = $.SUBRULE2($.quoteBacktick);
|
|
380
|
+
return $.ACTION(() => variable(prefix, quoteL, value, quoteR));
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
ALT: () => {
|
|
385
|
+
const quoteL = $.SUBRULE($.regexAny);
|
|
386
|
+
const value = $.OPTION4(() => $.SUBRULE5($.valueRegex));
|
|
387
|
+
const quoteR = $.OPTION5(() => $.SUBRULE5($.regexAny));
|
|
388
|
+
return $.ACTION(() => {
|
|
389
|
+
const args = isArray(quoteR) ? quoteR : [quoteR];
|
|
390
|
+
return variable(void 0, quoteL, value, args[0], args[1]);
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
// error
|
|
396
|
+
ALT: () => {
|
|
397
|
+
const value = $.SUBRULE4($.valueUnquoted, { ARGS });
|
|
398
|
+
const quoteR = $.SUBRULE4($.valueDelimAny);
|
|
399
|
+
return $.ACTION(() => variable(void 0, void 0, value, quoteR));
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
// error
|
|
404
|
+
ALT: () => {
|
|
405
|
+
const quoteL = $.SUBRULE5($.valueDelimAny);
|
|
406
|
+
const value = $.OPTION6(() => $.SUBRULE5($.valueUnquoted, { ARGS }));
|
|
407
|
+
return $.ACTION(() => variable(void 0, quoteL, value, void 0));
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
ALT: () => {
|
|
412
|
+
const value = $.SUBRULE6($.valueUnquoted, { ARGS });
|
|
413
|
+
return $.ACTION(() => variable(void 0, void 0, value, void 0));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
]);
|
|
417
|
+
return val;
|
|
418
|
+
});
|
|
419
|
+
$.RULE("valueDelimAny", () => {
|
|
420
|
+
const value = $.CONSUME(t.QUOTE_ANY);
|
|
421
|
+
return $.ACTION(() => {
|
|
422
|
+
const type = value.image === `"` ? "double" : value.image === "'" ? "single" : value.image === "\\" ? "regex" : value.image === "`" ? "tick" : unreachable();
|
|
423
|
+
return delimiter[type](...processToken(value, $.shift));
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
$.RULE("regexAny", () => {
|
|
427
|
+
const value = $.CONSUME(t.REGEX_ANY);
|
|
428
|
+
return $.ACTION(() => {
|
|
429
|
+
if (value.image.length > 1) {
|
|
430
|
+
const delim = {
|
|
431
|
+
image: "/",
|
|
432
|
+
startOffset: value.startOffset,
|
|
433
|
+
endOffset: value.startOffset
|
|
434
|
+
};
|
|
435
|
+
const flags = {
|
|
436
|
+
image: value.image.slice(1),
|
|
437
|
+
startOffset: value.startOffset + 1,
|
|
438
|
+
endOffset: value.endOffset
|
|
439
|
+
};
|
|
440
|
+
return [
|
|
441
|
+
delimiter.regex(...processToken(delim, $.shift)),
|
|
442
|
+
token.value(...processToken(flags, $.shift))
|
|
443
|
+
];
|
|
444
|
+
}
|
|
445
|
+
return delimiter.regex(...processToken(value, $.shift));
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
$.RULE("valueRegex", () => {
|
|
449
|
+
const value = $.CONSUME(t.VALUE_REGEX);
|
|
450
|
+
return $.ACTION(() => token.value(...processToken(value, $.shift)));
|
|
451
|
+
});
|
|
452
|
+
$.RULE("quoteSingle", () => {
|
|
453
|
+
const value = $.CONSUME(t.QUOTE_SINGLE);
|
|
454
|
+
return $.ACTION(() => delimiter.single(...processToken(value, $.shift)));
|
|
455
|
+
});
|
|
456
|
+
$.RULE("quoteDouble", () => {
|
|
457
|
+
const value = $.CONSUME(t.QUOTE_DOUBLE);
|
|
458
|
+
return $.ACTION(() => delimiter.double(...processToken(value, $.shift)));
|
|
459
|
+
});
|
|
460
|
+
$.RULE("quoteBacktick", () => {
|
|
461
|
+
const value = $.CONSUME(t.QUOTE_BACKTICK);
|
|
462
|
+
return $.ACTION(() => delimiter.tick(...processToken(value, $.shift)));
|
|
463
|
+
});
|
|
464
|
+
$.RULE("valueNotSingle", () => {
|
|
465
|
+
const value = $.CONSUME(t.VALUE_FOR_SINGLE);
|
|
466
|
+
return $.ACTION(() => token.value(...processToken(value, $.shift)));
|
|
467
|
+
});
|
|
468
|
+
$.RULE("valueNotDouble", () => {
|
|
469
|
+
const value = $.CONSUME(t.VALUE_FOR_DOUBLE);
|
|
470
|
+
return $.ACTION(() => token.value(...processToken(value, $.shift)));
|
|
471
|
+
});
|
|
472
|
+
$.RULE("valueNotBacktick", () => {
|
|
473
|
+
const value = $.CONSUME(t.VALUE_FOR_BACKTICK);
|
|
474
|
+
return $.ACTION(() => token.value(...processToken(value, $.shift)));
|
|
475
|
+
});
|
|
476
|
+
$.RULE("valueUnquoted", ({ bracketVal = false, onlyToken = false } = {}) => {
|
|
477
|
+
const value = $.OR([
|
|
478
|
+
{
|
|
479
|
+
GATE: () => !bracketVal,
|
|
480
|
+
ALT: () => $.CONSUME(t.VALUE_UNQUOTED)
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
GATE: () => bracketVal,
|
|
484
|
+
ALT: () => $.CONSUME(t.BRACKET_VALUE_UNQUOTED)
|
|
485
|
+
}
|
|
486
|
+
]);
|
|
487
|
+
return $.ACTION(() => onlyToken ? value : token.value(...processToken(value, $.shift)));
|
|
488
|
+
});
|
|
489
|
+
$.RULE("parenL", () => {
|
|
490
|
+
const value = $.CONSUME(t.PAREN_L);
|
|
491
|
+
return $.ACTION(() => {
|
|
492
|
+
const loc = extractPosition(value, $.shift);
|
|
493
|
+
return $.shift === 0 || loc.start > 0 ? delimiter.parenL(value.isInsertedInRecovery ? void 0 : value.image, loc) : void 0;
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
$.RULE("parenR", () => {
|
|
497
|
+
const value = $.CONSUME(t.PAREN_R);
|
|
498
|
+
return $.ACTION(() => delimiter.parenR(...processToken(value, $.shift)));
|
|
499
|
+
});
|
|
500
|
+
$.RULE("bracketL", () => {
|
|
501
|
+
const value = $.CONSUME(t.BRACKET_L);
|
|
502
|
+
return $.ACTION(() => {
|
|
503
|
+
const loc = extractPosition(value, $.shift);
|
|
504
|
+
return $.shift === 0 || loc.start > 0 ? delimiter.bracketL(value.isInsertedInRecovery ? void 0 : value.image, loc) : void 0;
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
$.RULE("bracketR", () => {
|
|
508
|
+
const value = $.CONSUME(t.BRACKET_R);
|
|
509
|
+
return $.ACTION(() => delimiter.bracketR(...processToken(value, $.shift)));
|
|
510
|
+
});
|
|
511
|
+
this.performSelfAnalysis();
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
export {
|
|
515
|
+
ParserBase
|
|
516
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Lexer, type TokenType } from "chevrotain";
|
|
2
|
+
import type { FullParserOptions } from "../types/parser.js";
|
|
3
|
+
/** Makes it easier to rename the tokens while still returning a properly typed record of them.*/
|
|
4
|
+
declare enum $T {
|
|
5
|
+
_ = "_",
|
|
6
|
+
ANY = "ANY",
|
|
7
|
+
QUOTE_ANY = "QUOTE_ANY",
|
|
8
|
+
QUOTE_SINGLE = "QUOTE_SINGLE",
|
|
9
|
+
QUOTE_DOUBLE = "QUOTE_DOUBLE",
|
|
10
|
+
QUOTE_BACKTICK = "QUOTE_BACKTICK",
|
|
11
|
+
VALUE = "VALUE",
|
|
12
|
+
REGEX_ANY = "REGEX_ANY",
|
|
13
|
+
VALUE_UNQUOTED = "VALUE_UNQUOTED",
|
|
14
|
+
BRACKET_VALUE_UNQUOTED = "BRACKET_VALUE_UNQUOTED",
|
|
15
|
+
VALUE_REGEX = "VALUE_REGEX",
|
|
16
|
+
VALUE_NOT_SINGLE = "VALUE_NOT_SINGLE",
|
|
17
|
+
VALUE_NOT_DOUBLE = "VALUE_NOT_DOUBLE",
|
|
18
|
+
VALUE_NOT_BACKTICK = "VALUE_NOT_BACKTICK",
|
|
19
|
+
VALUE_FOR_SINGLE = "VALUE_FOR_SINGLE",
|
|
20
|
+
VALUE_FOR_DOUBLE = "VALUE_FOR_DOUBLE",
|
|
21
|
+
VALUE_FOR_BACKTICK = "VALUE_FOR_BACKTICK",
|
|
22
|
+
OPERATOR_OR = "OPERATOR_OR",
|
|
23
|
+
OPERATOR_AND = "OPERATOR_AND",
|
|
24
|
+
OPERATOR_NOT = "OPERATOR_NOT",
|
|
25
|
+
SYM_OR = "SYM_OR",
|
|
26
|
+
SYM_AND = "SYM_AND",
|
|
27
|
+
SYM_NOT = "SYM_NOT",
|
|
28
|
+
WORD_OR = "WORD_OR",
|
|
29
|
+
WORD_AND = "WORD_AND",
|
|
30
|
+
WORD_NOT = "WORD_NOT",
|
|
31
|
+
REGEX_START = "REGEX_START",
|
|
32
|
+
REGEX_END = "REGEX_END",
|
|
33
|
+
QUOTE_SINGLE_START = "QUOTE_SINGLE_START",
|
|
34
|
+
QUOTE_DOUBLE_START = "QUOTE_DOUBLE_START",
|
|
35
|
+
QUOTE_BACKTICK_START = "QUOTE_BACKTICK_START",
|
|
36
|
+
QUOTE_SINGLE_END = "QUOTE_SINGLE_END",
|
|
37
|
+
QUOTE_DOUBLE_END = "QUOTE_DOUBLE_END",
|
|
38
|
+
QUOTE_BACKTICK_END = "QUOTE_BACKTICK_END",
|
|
39
|
+
EXP_PROP_OP = "EXP_PROP_OP",
|
|
40
|
+
CUSTOM_PROP_OP = "CUSTOM_PROP_OP",
|
|
41
|
+
PAREN_L = "PAREN_L",
|
|
42
|
+
PAREN_R = "PAREN_R",
|
|
43
|
+
BRACKET_L = "BRACKET_L",
|
|
44
|
+
BRACKET_R = "BRACKET_R"
|
|
45
|
+
}
|
|
46
|
+
type LexerOnly = $T.VALUE_NOT_BACKTICK | $T.VALUE_NOT_DOUBLE | $T.VALUE_NOT_SINGLE | $T.SYM_OR | $T.SYM_AND | $T.WORD_OR | $T.WORD_AND | $T.REGEX_END | $T.QUOTE_SINGLE_START | $T.QUOTE_DOUBLE_START | $T.QUOTE_BACKTICK_START | $T.QUOTE_SINGLE_END | $T.QUOTE_DOUBLE_END | $T.QUOTE_BACKTICK_END | $T.WORD_NOT;
|
|
47
|
+
export declare function createTokens<T extends {} = {}>(opts: FullParserOptions<T>): {
|
|
48
|
+
tokens: Record<Exclude<$T, LexerOnly>, TokenType>;
|
|
49
|
+
lexer: Lexer;
|
|
50
|
+
info: {
|
|
51
|
+
expandedSepAlsoCustom: boolean;
|
|
52
|
+
customOpAlsoNegation: boolean;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=createTokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTokens.d.ts","sourceRoot":"","sources":["../../src/grammar/createTokens.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAA;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAG3D,iGAAiG;AAEjG,aAAK,EAAE;IACN,CAAC,MAAM;IACP,GAAG,QAAQ;IACX,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;IAC7B,cAAc,mBAAmB;IACjC,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,cAAc,mBAAmB;IACjC,sBAAsB,2BAA2B;IACjD,WAAW,gBAAgB;IAC3B,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,WAAW,gBAAgB;IAC3B,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;IAC7B,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,kBAAkB,uBAAuB;IACzC,kBAAkB,uBAAuB;IACzC,oBAAoB,yBAAyB;IAC7C,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,kBAAkB,uBAAuB;IACzC,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IACjC,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,SAAS,cAAc;CACvB;AAGD,KAAK,SAAS,GAEX,EAAE,CAAC,kBAAkB,GACrB,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,MAAM,GACT,EAAE,CAAC,OAAO,GACV,EAAE,CAAC,OAAO,GACV,EAAE,CAAC,QAAQ,GAEX,EAAE,CAAC,SAAS,GACZ,EAAE,CAAC,kBAAkB,GACrB,EAAE,CAAC,kBAAkB,GACrB,EAAE,CAAC,oBAAoB,GACvB,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,kBAAkB,GACrB,EAAE,CAAC,QAAQ,CAAA;AAuBd,wBAAgB,YAAY,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG;IAC5E,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC,CAAA;IACjD,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE;QACL,qBAAqB,EAAE,OAAO,CAAA;QAC9B,oBAAoB,EAAE,OAAO,CAAA;KAC7B,CAAA;CACD,CA0ZA"}
|