@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,28 @@
|
|
|
1
|
+
function valueComparer(contextValue, { operator, prefix, value, isRegex, regexFlags }) {
|
|
2
|
+
let finalValue = value;
|
|
3
|
+
if (prefix) {
|
|
4
|
+
const val = value;
|
|
5
|
+
switch (prefix) {
|
|
6
|
+
case "num":
|
|
7
|
+
finalValue = parseInt(val, 2);
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (isRegex) {
|
|
12
|
+
const val = value;
|
|
13
|
+
const regex = new RegExp(val, regexFlags);
|
|
14
|
+
return contextValue.match(regex) !== null;
|
|
15
|
+
}
|
|
16
|
+
if (operator) {
|
|
17
|
+
switch (operator) {
|
|
18
|
+
case ">":
|
|
19
|
+
return contextValue > finalValue;
|
|
20
|
+
case "contains":
|
|
21
|
+
return contextValue.includes(finalValue);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return contextValue === finalValue;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
valueComparer
|
|
28
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pre-configured parser for parsing shortcut contexts (similar to VSCode's [when clause contexts](https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts)).
|
|
3
|
+
*
|
|
4
|
+
* The only difference is that it does not have a regex operator since you can just do `prop == /regex/`, and because of how it has `prefixableGroups` turned on and how the parser allows groups as values, user's can use shorter queries.
|
|
5
|
+
*
|
|
6
|
+
* It also automatically implements a prefixApplier (variables are joined with `.`) and a value validator (which is why it requires a dummy context and a list of valid regex flags be passed). The value of the dummy context should be true to indicate the key is regexable, otherwise just false or a nested object. Any nested keys found are joined with a `.` and added to a list of valid keys. The prefixApplier is loose and allows things like `a.(b.(c))` and `a(b(c))` to both be parsed as `a.b.c`.
|
|
7
|
+
*
|
|
8
|
+
* The validate function will return a list of positions with a list of errors which includes handling invalid or duplicate regex flags.
|
|
9
|
+
*/
|
|
10
|
+
import { Parser } from "../parser.js";
|
|
11
|
+
import type { Position } from "../types/ast.js";
|
|
12
|
+
export declare class ShortcutContextParser<T extends Position & {
|
|
13
|
+
type: ("invalidKey" | "unregexableKey" | "invalidRegexFlag" | "duplicateRegexFlag");
|
|
14
|
+
} = Position & {
|
|
15
|
+
type: ("invalidKey" | "unregexableKey" | "invalidRegexFlag" | "duplicateRegexFlag");
|
|
16
|
+
}> extends Parser<T> {
|
|
17
|
+
validKeys: string[];
|
|
18
|
+
regexablekeys: string[];
|
|
19
|
+
constructor(dummyContext: Record<string, any>, validRegexFlags?: string[]);
|
|
20
|
+
private _extractKeysFromContext;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=shortcutContextParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcutContextParser.d.ts","sourceRoot":"","sources":["../../src/examples/shortcutContextParser.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAI/C,qBAAa,qBAAqB,CAAC,CAAC,SACnC,QAAQ,GAAG;IAAE,IAAI,EAAE,CAAC,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC,CAAA;CAAE,GAClG,QAAQ,GAAG;IAAE,IAAI,EAAE,CAAC,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC,CAAA;CAAE,CACjG,SAAQ,MAAM,CAAC,CAAC,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAK;IAExB,aAAa,EAAE,MAAM,EAAE,CAAK;gBAG3B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,eAAe,GAAE,MAAM,EAAoB;IAmG5C,OAAO,CAAC,uBAAuB;CAa/B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 { Parser } from "../parser.js";
|
|
8
|
+
class ShortcutContextParser extends Parser {
|
|
9
|
+
constructor(dummyContext, validRegexFlags = ["i", "u", "m"]) {
|
|
10
|
+
super({
|
|
11
|
+
arrayValues: false,
|
|
12
|
+
keyParser: (key) => key.split(/\.+/),
|
|
13
|
+
keywords: {
|
|
14
|
+
and: [{ isSymbol: true, value: "&&" }],
|
|
15
|
+
or: [{ isSymbol: true, value: "||" }],
|
|
16
|
+
not: [{ isSymbol: true, value: "!" }]
|
|
17
|
+
},
|
|
18
|
+
regexValues: (property, operator) => property !== void 0 && operator !== void 0,
|
|
19
|
+
customPropertyOperators: ["!=", "=="],
|
|
20
|
+
prefixableGroups: true,
|
|
21
|
+
prefixApplier: (prefix, variable) => {
|
|
22
|
+
if (!prefix.endsWith(".")) {
|
|
23
|
+
return `${prefix}.${variable}`;
|
|
24
|
+
}
|
|
25
|
+
return prefix + variable;
|
|
26
|
+
},
|
|
27
|
+
valueComparer: (_condition, contextValue, query) => {
|
|
28
|
+
if (query.isRegex) {
|
|
29
|
+
return contextValue.match(new RegExp(query.value, query.regexFlags ?? "")) !== null;
|
|
30
|
+
}
|
|
31
|
+
return contextValue === query.value;
|
|
32
|
+
},
|
|
33
|
+
valueValidator: (_contextValue, query) => {
|
|
34
|
+
let tokens = [];
|
|
35
|
+
if (!this.validKeys.includes(query.propertyName)) {
|
|
36
|
+
tokens = tokens.concat(query.property.map((token) => ({
|
|
37
|
+
start: token.start,
|
|
38
|
+
end: token.end,
|
|
39
|
+
type: "invalidKey"
|
|
40
|
+
})));
|
|
41
|
+
}
|
|
42
|
+
if (query.isRegex && !this.regexablekeys.includes(query.propertyName)) {
|
|
43
|
+
tokens = tokens.concat(query.property.map((token) => ({
|
|
44
|
+
start: token.start,
|
|
45
|
+
end: token.end,
|
|
46
|
+
type: "unregexableKey"
|
|
47
|
+
})));
|
|
48
|
+
}
|
|
49
|
+
if (query.regexFlags) {
|
|
50
|
+
const chars = query.regexFlags.value.split("");
|
|
51
|
+
const start = query.regexFlags.start;
|
|
52
|
+
for (let i = 0; i < chars.length; i++) {
|
|
53
|
+
const char = chars[i];
|
|
54
|
+
if (chars.slice(0, i).includes(char)) {
|
|
55
|
+
tokens.push({
|
|
56
|
+
start: start + i,
|
|
57
|
+
end: start + i + 1,
|
|
58
|
+
type: "duplicateRegexFlag"
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (!validRegexFlags.includes(char)) {
|
|
62
|
+
tokens.push({
|
|
63
|
+
start: start + i,
|
|
64
|
+
end: start + i + 1,
|
|
65
|
+
type: "invalidRegexFlag"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (tokens.length > 0)
|
|
71
|
+
return tokens;
|
|
72
|
+
},
|
|
73
|
+
conditionNormalizer({ operator, value, regexFlags, isRegex, isNegated, isQuoted }) {
|
|
74
|
+
let finalValue = value;
|
|
75
|
+
let finalOperator = operator;
|
|
76
|
+
if (typeof value === "string" && !isQuoted) {
|
|
77
|
+
const asNum = parseInt(value, 2);
|
|
78
|
+
if (!isNaN(asNum))
|
|
79
|
+
finalValue = asNum;
|
|
80
|
+
if (["true", "false"].includes(value)) {
|
|
81
|
+
finalValue = value === "true";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (isRegex) {
|
|
85
|
+
const val = value;
|
|
86
|
+
const regex = new RegExp(val, regexFlags);
|
|
87
|
+
finalValue = regex;
|
|
88
|
+
}
|
|
89
|
+
if (operator) {
|
|
90
|
+
switch (operator) {
|
|
91
|
+
case "==": {
|
|
92
|
+
finalOperator = "equals";
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case "!=": {
|
|
96
|
+
finalOperator = "equals";
|
|
97
|
+
isNegated = !isNegated;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { value: finalValue, operator: finalOperator, negate: isNegated };
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
__publicField(this, "validKeys", []);
|
|
106
|
+
__publicField(this, "regexablekeys", []);
|
|
107
|
+
this._extractKeysFromContext(dummyContext);
|
|
108
|
+
}
|
|
109
|
+
_extractKeysFromContext(context, prev) {
|
|
110
|
+
for (const key of Object.keys(context)) {
|
|
111
|
+
if (typeof context[key] === "boolean") {
|
|
112
|
+
this.validKeys.push(prev ? `${prev}.${key}` : key);
|
|
113
|
+
if (context[key] === true) {
|
|
114
|
+
this.regexablekeys.push(prev ? `${prev}.${key}` : key);
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
if (typeof context[key] !== "object")
|
|
118
|
+
throw new Error("A dummy context value must be a boolean or an object.");
|
|
119
|
+
this._extractKeysFromContext(context[key], prev ? `${prev}.${key}` : key);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
ShortcutContextParser
|
|
126
|
+
};
|
package/dist/global.d.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EmbeddedActionsParser, type IToken } from "chevrotain";
|
|
2
|
+
import type { createTokens } from "./createTokens.js";
|
|
3
|
+
import { ArrayNode } from "../ast/classes/ArrayNode.js";
|
|
4
|
+
import { ConditionNode } from "../ast/classes/ConditionNode.js";
|
|
5
|
+
import type { ExpressionNode } from "../ast/classes/ExpressionNode.js";
|
|
6
|
+
import type { GroupNode } from "../ast/classes/GroupNode.js";
|
|
7
|
+
import type { ValidToken } from "../ast/classes/ValidToken.js";
|
|
8
|
+
import { VariableNode } from "../ast/classes/VariableNode.js";
|
|
9
|
+
import { type AnyToken, type ParserResults, TOKEN_TYPE, type TokenQuoteTypes } from "../types/ast.js";
|
|
10
|
+
import type { FullParserOptions } from "../types/parser.js";
|
|
11
|
+
export declare class ParserBase<T extends {} = {}> extends EmbeddedActionsParser {
|
|
12
|
+
rawInput: string;
|
|
13
|
+
private subParser?;
|
|
14
|
+
private subParser2?;
|
|
15
|
+
constructor(opts: FullParserOptions<T>, t: ReturnType<typeof createTokens>["tokens"], { customOpAlsoNegation, expandedSepAlsoCustom }: ReturnType<typeof createTokens>["info"]);
|
|
16
|
+
}
|
|
17
|
+
export interface ParserBase {
|
|
18
|
+
shift: number;
|
|
19
|
+
main: () => ParserResults;
|
|
20
|
+
anySym: () => IToken;
|
|
21
|
+
boolOr: () => ExpressionNode;
|
|
22
|
+
boolAnd: () => ExpressionNode;
|
|
23
|
+
condition: () => ConditionNode | GroupNode;
|
|
24
|
+
property: () => {
|
|
25
|
+
prop?: VariableNode;
|
|
26
|
+
rest: {
|
|
27
|
+
sepL?: ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP>;
|
|
28
|
+
sepR?: ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP>;
|
|
29
|
+
propertyOperator?: ConditionNode["propertyOperator"];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
plainGroup: () => [ValidToken<TOKEN_TYPE.PARENL>, GroupNode["expression"], ValidToken<TOKEN_TYPE.PARENR> | undefined];
|
|
33
|
+
plainBracketGroup: () => ArrayNode;
|
|
34
|
+
not: () => ValidToken<TOKEN_TYPE.NOT>;
|
|
35
|
+
variable: () => VariableNode;
|
|
36
|
+
valueDelimAny: () => AnyToken<TokenQuoteTypes>;
|
|
37
|
+
quoteSingle: () => AnyToken<TOKEN_TYPE.SINGLEQUOTE>;
|
|
38
|
+
quoteDouble: () => AnyToken<TOKEN_TYPE.DOUBLEQUOTE>;
|
|
39
|
+
quoteBacktick: () => AnyToken<TOKEN_TYPE.BACKTICK>;
|
|
40
|
+
regexAny: () => AnyToken<TOKEN_TYPE.REGEX> | [AnyToken<TOKEN_TYPE.REGEX>, ValidToken<TOKEN_TYPE.VALUE>];
|
|
41
|
+
valueNotSingle: () => AnyToken<TOKEN_TYPE.VALUE>;
|
|
42
|
+
valueNotDouble: () => AnyToken<TOKEN_TYPE.VALUE>;
|
|
43
|
+
valueNotBacktick: () => AnyToken<TOKEN_TYPE.VALUE>;
|
|
44
|
+
valueUnquoted: () => AnyToken<TOKEN_TYPE.VALUE>;
|
|
45
|
+
valueRegex: () => AnyToken<TOKEN_TYPE.VALUE>;
|
|
46
|
+
parenL: () => ValidToken<TOKEN_TYPE.PARENL>;
|
|
47
|
+
parenR: () => ValidToken<TOKEN_TYPE.PARENR> | undefined;
|
|
48
|
+
bracketL: () => ValidToken<TOKEN_TYPE.BRACKETL>;
|
|
49
|
+
bracketR: () => ValidToken<TOKEN_TYPE.BRACKETR> | undefined;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=ParserBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParserBase.d.ts","sour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