@witchcraft/expressit 0.1.2 → 0.2.0
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 +9 -5
- package/dist/Lexer.js +2 -2
- package/dist/Parser.d.ts +14 -29
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +120 -135
- package/dist/ast/builders/array.d.ts +1 -3
- package/dist/ast/builders/array.d.ts.map +1 -1
- package/dist/ast/builders/array.js +3 -5
- package/dist/ast/builders/condition.d.ts +5 -11
- package/dist/ast/builders/condition.d.ts.map +1 -1
- package/dist/ast/builders/condition.js +2 -3
- package/dist/ast/builders/delim.d.ts +1 -1
- package/dist/ast/builders/error.d.ts +3 -4
- package/dist/ast/builders/error.d.ts.map +1 -1
- package/dist/ast/builders/error.js +6 -2
- package/dist/ast/builders/expression.d.ts +3 -7
- package/dist/ast/builders/expression.d.ts.map +1 -1
- package/dist/ast/builders/expression.js +3 -5
- package/dist/ast/builders/group.d.ts +3 -8
- package/dist/ast/builders/group.d.ts.map +1 -1
- package/dist/ast/builders/group.js +3 -3
- package/dist/ast/builders/pos.d.ts +1 -2
- package/dist/ast/builders/pos.d.ts.map +1 -1
- package/dist/ast/builders/token.d.ts +3 -5
- package/dist/ast/builders/token.d.ts.map +1 -1
- package/dist/ast/builders/token.js +3 -4
- package/dist/ast/builders/type.d.ts +1 -1
- package/dist/ast/builders/variable.d.ts +3 -5
- package/dist/ast/builders/variable.d.ts.map +1 -1
- package/dist/ast/builders/variable.js +2 -3
- package/dist/ast/createArrayNode.d.ts +3 -0
- package/dist/ast/createArrayNode.d.ts.map +1 -0
- package/dist/ast/createArrayNode.js +12 -0
- package/dist/ast/createConditionNode.d.ts +11 -0
- package/dist/ast/createConditionNode.d.ts.map +1 -0
- package/dist/ast/createConditionNode.js +18 -0
- package/dist/ast/createExpressionNode.d.ts +3 -0
- package/dist/ast/createExpressionNode.d.ts.map +1 -0
- package/dist/ast/createExpressionNode.js +14 -0
- package/dist/ast/createGroupNode.d.ts +5 -0
- package/dist/ast/createGroupNode.d.ts.map +1 -0
- package/dist/ast/createGroupNode.js +14 -0
- package/dist/ast/createNormalizedCondition.d.ts +3 -0
- package/dist/ast/createNormalizedCondition.d.ts.map +1 -0
- package/dist/ast/createNormalizedCondition.js +10 -0
- package/dist/ast/createNormalizedExpression.d.ts +3 -0
- package/dist/ast/createNormalizedExpression.d.ts.map +1 -0
- package/dist/ast/createNormalizedExpression.js +10 -0
- package/dist/ast/createToken.d.ts +6 -0
- package/dist/ast/createToken.d.ts.map +1 -0
- package/dist/ast/createToken.js +15 -0
- package/dist/ast/createVariableNode.d.ts +3 -0
- package/dist/ast/createVariableNode.d.ts.map +1 -0
- package/dist/ast/createVariableNode.js +12 -0
- package/dist/ast/error.d.ts +3 -0
- package/dist/ast/error.d.ts.map +1 -0
- package/dist/ast/error.js +9 -0
- package/dist/ast/handlers.d.ts +5 -12
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +21 -29
- package/dist/ast/index.d.ts +9 -1
- package/dist/ast/index.d.ts.map +1 -1
- package/dist/ast/index.js +18 -2
- package/dist/defaults/defaultConditionNormalizer.d.ts +3 -0
- package/dist/defaults/defaultConditionNormalizer.d.ts.map +1 -0
- package/dist/defaults/defaultKeyParser.d.ts +3 -0
- package/dist/defaults/defaultKeyParser.d.ts.map +1 -0
- package/dist/defaults/defaultPrefixApplier.d.ts +3 -0
- package/dist/defaults/defaultPrefixApplier.d.ts.map +1 -0
- package/dist/defaults/defaultValueComparer.d.ts +3 -0
- package/dist/defaults/defaultValueComparer.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.d.ts +0 -2
- package/dist/defaults/index.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.js +0 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/{helpers/errors.d.ts → internal/ExpressitError.d.ts} +3 -2
- package/dist/internal/ExpressitError.d.ts.map +1 -0
- package/dist/{helpers/errors.js → internal/ExpressitError.js} +2 -2
- package/dist/internal/applyBoolean.d.ts.map +1 -0
- package/dist/{helpers/general → internal}/applyPrefix.d.ts +1 -1
- package/dist/internal/applyPrefix.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.d.ts +2 -1
- package/dist/internal/checkParserOpts.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.js +14 -14
- package/dist/internal/escapeVariableOrPrefix.d.ts +2 -0
- package/dist/internal/escapeVariableOrPrefix.d.ts.map +1 -0
- package/dist/internal/escapeVariableOrPrefix.js +38 -0
- package/dist/internal/extractPosition.d.ts +5 -0
- package/dist/internal/extractPosition.d.ts.map +1 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts +4 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/getUnclosedRightParenCount.js +1 -1
- package/dist/{helpers/parser → internal}/parseParserOptions.d.ts +1 -1
- package/dist/internal/parseParserOptions.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/parseParserOptions.js +4 -4
- package/dist/internal/unescape.d.ts.map +1 -0
- package/dist/package.json.js +7 -7
- package/dist/types/ast.d.ts +195 -6
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +2 -0
- package/dist/types/autocomplete.d.ts +5 -6
- package/dist/types/autocomplete.d.ts.map +1 -1
- package/dist/types/parser.d.ts +17 -22
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.d.ts +2 -4
- package/dist/utils/extractTokens.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +14 -18
- package/dist/utils/generateParentsMap.d.ts +10 -0
- package/dist/utils/generateParentsMap.d.ts.map +1 -0
- package/dist/utils/generateParentsMap.js +73 -0
- package/dist/utils/getCursorInfo.d.ts +1 -1
- package/dist/utils/getCursorInfo.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +3 -5
- package/dist/utils/getOppositeDelimiter.d.ts +2 -1
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +6 -5
- package/dist/utils/getParent.d.ts +5 -0
- package/dist/utils/getParent.d.ts.map +1 -0
- package/dist/utils/getParent.js +6 -0
- package/dist/utils/getSurroundingErrors.d.ts +3 -4
- package/dist/utils/getSurroundingErrors.d.ts.map +1 -1
- package/dist/utils/getSurroundingErrors.js +3 -3
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -0
- package/dist/utils/isNode.d.ts +10 -0
- package/dist/utils/isNode.d.ts.map +1 -0
- package/dist/utils/isNode.js +6 -0
- package/dist/utils/isToken.d.ts +8 -0
- package/dist/utils/isToken.d.ts.map +1 -0
- package/dist/utils/isToken.js +6 -0
- package/dist/utils/prettyAst.d.ts +1 -2
- package/dist/utils/prettyAst.d.ts.map +1 -1
- package/dist/utils/prettyAst.js +19 -26
- package/package.json +7 -7
- package/src/Lexer.ts +2 -2
- package/src/Parser.ts +158 -165
- package/src/ast/builders/array.ts +4 -9
- package/src/ast/builders/condition.ts +10 -15
- package/src/ast/builders/delim.ts +1 -1
- package/src/ast/builders/error.ts +10 -6
- package/src/ast/builders/expression.ts +17 -23
- package/src/ast/builders/group.ts +7 -11
- package/src/ast/builders/pos.ts +2 -3
- package/src/ast/builders/token.ts +6 -7
- package/src/ast/builders/type.ts +1 -1
- package/src/ast/builders/variable.ts +6 -8
- package/src/ast/createArrayNode.ts +17 -0
- package/src/ast/createConditionNode.ts +58 -0
- package/src/ast/createExpressionNode.ts +21 -0
- package/src/ast/createGroupNode.ts +46 -0
- package/src/ast/createNormalizedCondition.ts +12 -0
- package/src/ast/createNormalizedExpression.ts +9 -0
- package/src/ast/createToken.ts +26 -0
- package/src/ast/createVariableNode.ts +18 -0
- package/src/ast/error.ts +9 -0
- package/src/ast/handlers.ts +26 -37
- package/src/ast/index.ts +9 -1
- package/src/{helpers/general → defaults}/defaultConditionNormalizer.ts +1 -1
- package/src/{helpers/general → defaults}/defaultKeyParser.ts +1 -1
- package/src/{helpers/general → defaults}/defaultPrefixApplier.ts +1 -1
- package/src/{helpers/general → defaults}/defaultValueComparer.ts +1 -1
- package/src/{helpers/general → defaults}/index.ts +0 -2
- package/src/index.ts +2 -1
- package/src/{helpers/errors.ts → internal/ExpressitError.ts} +2 -2
- package/src/{helpers/general → internal}/applyPrefix.ts +1 -1
- package/src/{helpers/parser → internal}/checkParserOpts.ts +16 -15
- package/src/internal/escapeVariableOrPrefix.ts +36 -0
- package/src/{helpers/parser → internal}/extractPosition.ts +2 -2
- package/src/{helpers/parser → internal}/getUnclosedRightParenCount.ts +1 -2
- package/src/{helpers/parser → internal}/parseParserOptions.ts +5 -5
- package/src/types/ast.ts +292 -7
- package/src/types/autocomplete.ts +5 -7
- package/src/types/parser.ts +17 -22
- package/src/utils/extractTokens.ts +16 -20
- package/src/utils/generateParentsMap.ts +60 -0
- package/src/utils/getCursorInfo.ts +4 -6
- package/src/utils/getOppositeDelimiter.ts +11 -10
- package/src/utils/getParent.ts +16 -0
- package/src/utils/getSurroundingErrors.ts +10 -9
- package/src/utils/index.ts +4 -0
- package/src/utils/isNode.ts +12 -0
- package/src/utils/isToken.ts +10 -0
- package/src/utils/prettyAst.ts +20 -17
- package/dist/ast/classes/ArrayNode.d.ts +0 -18
- package/dist/ast/classes/ArrayNode.d.ts.map +0 -1
- package/dist/ast/classes/ArrayNode.js +0 -55
- package/dist/ast/classes/Condition.d.ts +0 -13
- package/dist/ast/classes/Condition.d.ts.map +0 -1
- package/dist/ast/classes/Condition.js +0 -21
- package/dist/ast/classes/ConditionNode.d.ts +0 -73
- package/dist/ast/classes/ConditionNode.d.ts.map +0 -1
- package/dist/ast/classes/ConditionNode.js +0 -101
- package/dist/ast/classes/ErrorToken.d.ts +0 -27
- package/dist/ast/classes/ErrorToken.d.ts.map +0 -1
- package/dist/ast/classes/ErrorToken.js +0 -47
- package/dist/ast/classes/Expression.d.ts +0 -13
- package/dist/ast/classes/Expression.d.ts.map +0 -1
- package/dist/ast/classes/Expression.js +0 -19
- package/dist/ast/classes/ExpressionNode.d.ts +0 -21
- package/dist/ast/classes/ExpressionNode.d.ts.map +0 -1
- package/dist/ast/classes/ExpressionNode.js +0 -57
- package/dist/ast/classes/GroupNode.d.ts +0 -64
- package/dist/ast/classes/GroupNode.d.ts.map +0 -1
- package/dist/ast/classes/GroupNode.js +0 -69
- package/dist/ast/classes/Node.d.ts +0 -22
- package/dist/ast/classes/Node.d.ts.map +0 -1
- package/dist/ast/classes/Node.js +0 -28
- package/dist/ast/classes/Token.d.ts +0 -27
- package/dist/ast/classes/Token.d.ts.map +0 -1
- package/dist/ast/classes/Token.js +0 -28
- package/dist/ast/classes/ValidToken.d.ts +0 -26
- package/dist/ast/classes/ValidToken.d.ts.map +0 -1
- package/dist/ast/classes/ValidToken.js +0 -49
- package/dist/ast/classes/VariableNode.d.ts +0 -33
- package/dist/ast/classes/VariableNode.d.ts.map +0 -1
- package/dist/ast/classes/VariableNode.js +0 -58
- package/dist/ast/classes/index.d.ts +0 -12
- package/dist/ast/classes/index.d.ts.map +0 -1
- package/dist/ast/classes/index.js +0 -24
- package/dist/helpers/errors.d.ts.map +0 -1
- package/dist/helpers/general/applyBoolean.d.ts.map +0 -1
- package/dist/helpers/general/applyPrefix.d.ts.map +0 -1
- package/dist/helpers/general/defaultConditionNormalizer.d.ts +0 -3
- package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +0 -1
- package/dist/helpers/general/defaultKeyParser.d.ts +0 -3
- package/dist/helpers/general/defaultKeyParser.d.ts.map +0 -1
- package/dist/helpers/general/defaultPrefixApplier.d.ts +0 -3
- package/dist/helpers/general/defaultPrefixApplier.d.ts.map +0 -1
- package/dist/helpers/general/defaultValueComparer.d.ts +0 -3
- package/dist/helpers/general/defaultValueComparer.d.ts.map +0 -1
- package/dist/helpers/general/index.d.ts.map +0 -1
- package/dist/helpers/index.d.ts +0 -4
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -8
- package/dist/helpers/parser/assignParents.d.ts +0 -4
- package/dist/helpers/parser/assignParents.d.ts.map +0 -1
- package/dist/helpers/parser/assignParents.js +0 -71
- package/dist/helpers/parser/checkParserOpts.d.ts.map +0 -1
- package/dist/helpers/parser/extractPosition.d.ts +0 -5
- package/dist/helpers/parser/extractPosition.d.ts.map +0 -1
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +0 -4
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +0 -1
- package/dist/helpers/parser/index.d.ts +0 -9
- package/dist/helpers/parser/index.d.ts.map +0 -1
- package/dist/helpers/parser/index.js +0 -18
- package/dist/helpers/parser/parseParserOptions.d.ts.map +0 -1
- package/dist/helpers/parser/seal.d.ts +0 -8
- package/dist/helpers/parser/seal.d.ts.map +0 -1
- package/dist/helpers/parser/seal.js +0 -10
- package/dist/helpers/parser/setParent.d.ts +0 -6
- package/dist/helpers/parser/setParent.d.ts.map +0 -1
- package/dist/helpers/parser/setParent.js +0 -4
- package/dist/helpers/parser/unescape.d.ts.map +0 -1
- package/src/ast/classes/ArrayNode.ts +0 -46
- package/src/ast/classes/Condition.ts +0 -22
- package/src/ast/classes/ConditionNode.ts +0 -141
- package/src/ast/classes/ErrorToken.ts +0 -49
- package/src/ast/classes/Expression.ts +0 -26
- package/src/ast/classes/ExpressionNode.ts +0 -62
- package/src/ast/classes/GroupNode.ts +0 -127
- package/src/ast/classes/Node.ts +0 -47
- package/src/ast/classes/Token.ts +0 -59
- package/src/ast/classes/ValidToken.ts +0 -56
- package/src/ast/classes/VariableNode.ts +0 -67
- package/src/ast/classes/index.ts +0 -13
- package/src/helpers/index.ts +0 -6
- package/src/helpers/parser/assignParents.ts +0 -51
- package/src/helpers/parser/index.ts +0 -10
- package/src/helpers/parser/seal.ts +0 -14
- package/src/helpers/parser/setParent.ts +0 -5
- /package/dist/{helpers/general → defaults}/defaultConditionNormalizer.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultKeyParser.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultPrefixApplier.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultValueComparer.js +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.d.ts +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.js +0 -0
- /package/dist/{helpers/general → internal}/applyPrefix.js +0 -0
- /package/dist/{helpers/parser → internal}/extractPosition.js +0 -0
- /package/dist/{helpers/parser → internal}/unescape.d.ts +0 -0
- /package/dist/{helpers/parser → internal}/unescape.js +0 -0
- /package/src/{helpers/general → internal}/applyBoolean.ts +0 -0
- /package/src/{helpers/parser → internal}/unescape.ts +0 -0
package/dist/types/ast.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AnyFunction } from "@alanscodelog/utils/types";
|
|
2
|
-
import type { ArrayNode, ConditionNode, ErrorToken, ExpressionNode, GroupNode, ValidToken, VariableNode } from "../ast/classes/index.js";
|
|
3
2
|
export type AddParameters<T extends AnyFunction, TExtra extends any[] = [boolean]> = (...args: [...Parameters<T>, ...TExtra]) => ReturnType<T>;
|
|
4
3
|
export declare enum TOKEN_TYPE {
|
|
5
4
|
VALUE = "VALUE",
|
|
@@ -30,28 +29,146 @@ export type TokenBooleanTypes = TOKEN_TYPE.AND | TOKEN_TYPE.OR;
|
|
|
30
29
|
export type TokenOperatorTypes = TokenBooleanTypes | TOKEN_TYPE.NOT;
|
|
31
30
|
export type TokenPropertyOperatorTypes = TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.OP_EXPANDED_SEP;
|
|
32
31
|
export type EmptyObj = Record<any, never>;
|
|
33
|
-
export type
|
|
32
|
+
export type FirstParam<T extends AnyFunction> = Parameters<T>["0"];
|
|
34
33
|
export type Position = {
|
|
35
34
|
start: number;
|
|
36
35
|
end: number;
|
|
37
36
|
};
|
|
38
37
|
export declare enum AST_TYPE {
|
|
39
38
|
EXPRESSION = "EXPRESSION",
|
|
39
|
+
NORMALIZED_EXPRESSION = "NORMALIZED_EXPRESSION",
|
|
40
40
|
GROUP = "GROUP",
|
|
41
41
|
ARRAY = "ARRAY",
|
|
42
42
|
CONDITION = "CONDITION",
|
|
43
|
+
NORMALIZED_CONDITION = "NORMALIZED_CONDITION",
|
|
43
44
|
VARIABLE = "VARIABLE"
|
|
44
45
|
}
|
|
46
|
+
export type RawNode<T extends Node> = Omit<T, "valid" | "type" | "isNode">;
|
|
47
|
+
/**
|
|
48
|
+
* The base type from which {@link ValidToken} and {@link ErrorToken} extend.
|
|
49
|
+
*
|
|
50
|
+
* Mostly for internal use, and I would suggest using {@link AnyToken} instead of this for typing things.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
export interface BaseToken {
|
|
54
|
+
isToken: true;
|
|
55
|
+
start: number;
|
|
56
|
+
end: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Valid tokens always have a value, even if it might be an empty string.
|
|
60
|
+
*/
|
|
61
|
+
export interface ValidToken<TType extends TOKEN_TYPE = TOKEN_TYPE> extends BaseToken {
|
|
62
|
+
valid: true;
|
|
63
|
+
type: TType;
|
|
64
|
+
value: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The type for invalid recovery tokens.
|
|
68
|
+
*
|
|
69
|
+
* Unlike valid tokens, error tokens:
|
|
70
|
+
*
|
|
71
|
+
* - Have no value.
|
|
72
|
+
*
|
|
73
|
+
* - Contain an extra property, `expected` with an array of tokens *that would have fixed the issue* (NOT every possible token that could be there).
|
|
74
|
+
*
|
|
75
|
+
* - The start end positions will always be equal. An invalid token has no length.
|
|
76
|
+
*/
|
|
77
|
+
export interface ErrorToken extends BaseToken {
|
|
78
|
+
type?: undefined;
|
|
79
|
+
value?: undefined;
|
|
80
|
+
valid: false;
|
|
81
|
+
expected: TOKEN_TYPE[];
|
|
82
|
+
}
|
|
45
83
|
/**
|
|
46
84
|
* For more easily typing tokens that might or might not be valid.
|
|
47
85
|
*
|
|
48
|
-
* Using @
|
|
86
|
+
* Using {@link Token} does not work well in certain situations and is also more complex because it has so many generics.
|
|
87
|
+
*/
|
|
88
|
+
export type AnyToken<TType extends TOKEN_TYPE = TOKEN_TYPE> = ValidToken<TType> | ErrorToken;
|
|
89
|
+
export type RawToken<T extends AnyToken> = Omit<T, "isToken" | "valid">;
|
|
90
|
+
export type ParserResults = ExpressionNode | ConditionNode | GroupNode | ErrorToken;
|
|
91
|
+
/**
|
|
92
|
+
* The base AST type all node types extend from.
|
|
93
|
+
*/
|
|
94
|
+
export interface Node<TType extends AST_TYPE = AST_TYPE, TValid extends boolean = boolean> {
|
|
95
|
+
isNode: true;
|
|
96
|
+
type: TType;
|
|
97
|
+
start: number;
|
|
98
|
+
end: number;
|
|
99
|
+
valid: TValid;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A node that symbolizes a parenthesized expression (might be negated), and if `prefixableGroups` is enabled, a prefixed expression {@link ParserOptions} .
|
|
103
|
+
*
|
|
104
|
+
* ```txt
|
|
105
|
+
* (a || b)
|
|
106
|
+
* |----| ExpressionNode
|
|
107
|
+
* |------| GroupNode
|
|
108
|
+
*
|
|
109
|
+
* !(a || b)
|
|
110
|
+
* ^ prefix: "not" Token
|
|
111
|
+
* |----| ExpressionNode
|
|
112
|
+
* |-------| GroupNode
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* If `prefixableGroups` is enabled:
|
|
116
|
+
* ```txt
|
|
117
|
+
* prefix(a || b)
|
|
118
|
+
* |----| prefix: ConditionNode
|
|
119
|
+
* |----| ExpressionNode
|
|
120
|
+
* |------------| GroupNode
|
|
121
|
+
*
|
|
122
|
+
* !prefix(a || b)
|
|
123
|
+
* |-----| prefix: ConditionNode
|
|
124
|
+
* |----| ExpressionNode
|
|
125
|
+
* |-------------| GroupNode
|
|
126
|
+
*
|
|
127
|
+
* !(a || b)
|
|
128
|
+
* ^ prefix: STILL a "not" Token
|
|
129
|
+
* ```
|
|
49
130
|
*/
|
|
50
|
-
export
|
|
51
|
-
|
|
131
|
+
export interface GroupNode<TValid extends boolean = boolean, TPrefixable extends boolean = true, TPrefix extends TPrefixable extends true ? ConditionNode<TValid> | ValidToken<TOKEN_TYPE.NOT> | undefined : ValidToken<TOKEN_TYPE.NOT> | undefined = TPrefixable extends true ? ConditionNode<TValid> | ValidToken<TOKEN_TYPE.NOT> | undefined : ValidToken<TOKEN_TYPE.NOT>> extends Node<AST_TYPE.GROUP> {
|
|
132
|
+
/**
|
|
133
|
+
* If the condition is negated this will contain a "not" **token**, {@link ValidToken} .
|
|
134
|
+
*
|
|
135
|
+
* If `prefixableGroups` is enabled and the group is prefixed by a **condition**, this will be an {@link ConditionNode}.
|
|
136
|
+
*
|
|
137
|
+
* **Careful:** `!(a)` here this would not be a **condition** since it's just a regular negation.
|
|
138
|
+
*
|
|
139
|
+
* See examples at {@link GroupNode} .
|
|
140
|
+
*/
|
|
141
|
+
prefix: TPrefix;
|
|
142
|
+
expression: ConditionNode<TValid> | GroupNode<TValid> | ExpressionNode<TValid> | (TValid extends false ? ErrorToken : never);
|
|
143
|
+
/**
|
|
144
|
+
* The parenthesis tokens, {@link ValidToken} . These will always be defined (although not necessarily with valid tokens).
|
|
145
|
+
*/
|
|
146
|
+
paren: NodeDelimiters<TOKEN_TYPE.PARENL, TOKEN_TYPE.PARENR>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A variable represents **just** a string value (NOT it's boolean value).
|
|
150
|
+
*
|
|
151
|
+
* The parser will never return just a variable, they are always wrapped in an {@link ConditionNode} to give them a boolean value.
|
|
152
|
+
*
|
|
153
|
+
* A variable might or might not be quoted. If it is, the `quote` property will contain the quote tokens, see {@link ValidToken} . While they will always be of the same quote type, one might be valid while the other might not (see {@link ErrorToken}).
|
|
154
|
+
*
|
|
155
|
+
* `value` will contain the string value of the variable. The text is not processed and might still contain escaped characters (even if unquoted!) that need to be removed to get the intended value. This is so that the position of the node is accurate. {@link evaluate} will take care of unescaping when needed.
|
|
156
|
+
*
|
|
157
|
+
* If `prefixableStrings` is true, the `prefix` property might contain a value token.
|
|
158
|
+
*/
|
|
159
|
+
export interface VariableNode<TValid extends boolean = boolean> extends Node<AST_TYPE.VARIABLE, TValid> {
|
|
160
|
+
value: TValid extends boolean ? AnyToken<TOKEN_TYPE.VALUE> : TValid extends true ? ValidToken<TOKEN_TYPE.VALUE> : ErrorToken;
|
|
161
|
+
prefix?: ValidToken<TOKEN_TYPE.VALUE>;
|
|
162
|
+
quote?: NodeDelimiters<TokenQuoteTypes, TokenQuoteTypes>;
|
|
163
|
+
}
|
|
164
|
+
export interface ExpressionNode<TValid extends boolean = boolean> extends Node<AST_TYPE.EXPRESSION> {
|
|
165
|
+
operator: AnyToken<TokenBooleanTypes>;
|
|
166
|
+
left: ExpressionNode<TValid> | ConditionNode<TValid> | GroupNode<TValid> | (TValid extends false ? ErrorToken : never);
|
|
167
|
+
right: ExpressionNode<TValid> | ConditionNode<TValid> | GroupNode<TValid> | (TValid extends false ? ErrorToken : never);
|
|
168
|
+
}
|
|
52
169
|
export type Nodes = ExpressionNode | ConditionNode | GroupNode | VariableNode | ArrayNode;
|
|
53
170
|
/**
|
|
54
|
-
* Contains any delimiter tokens some AST nodes ( @
|
|
171
|
+
* Contains any delimiter tokens some AST nodes ( {@link GroupNode} and {@link VariableNode} ) can have.
|
|
55
172
|
*
|
|
56
173
|
* These are usually not important for evaluating an expression but are useful for syntax highlighting.
|
|
57
174
|
*/
|
|
@@ -61,4 +178,76 @@ export type NodeDelimiters<TLEFT extends TOKEN_TYPE, TRIGHT extends TOKEN_TYPE =
|
|
|
61
178
|
/** Only exists if regexes are enabled and this is a regex value. */
|
|
62
179
|
flags?: ValidToken<TOKEN_TYPE.VALUE>;
|
|
63
180
|
};
|
|
181
|
+
export interface ArrayNode<TValid extends boolean = boolean> extends Node<AST_TYPE.ARRAY> {
|
|
182
|
+
values: VariableNode[];
|
|
183
|
+
bracket: NodeDelimiters<TOKEN_TYPE.BRACKETL, TOKEN_TYPE.BRACKETR>;
|
|
184
|
+
valid: TValid;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A condition is composed of a {@link Variable} , and, if it's negated, a "not" `operator` token, see {@link ValidToken}.
|
|
188
|
+
*
|
|
189
|
+
* The `value` property refers to the boolean value of the condition (not to the string value of the variable). See the `operator` property.
|
|
190
|
+
*
|
|
191
|
+
*/
|
|
192
|
+
export interface ConditionNode<TValid extends boolean = boolean> extends Node<AST_TYPE.CONDITION> {
|
|
193
|
+
/**
|
|
194
|
+
* Contains a value node which could be a variable, an array node (if enabled), or a group.
|
|
195
|
+
*
|
|
196
|
+
* Might be an error in cases like:
|
|
197
|
+
* - just passing a negation operator
|
|
198
|
+
* - if condition property operators are used and you have an input like just `[SEP]`, `op[SEP]`, `prop[SEP]op[SEP]`, `[CUSTOM OP]`, or `prop[CUSTOM OP]` where the variable is missing.
|
|
199
|
+
*/
|
|
200
|
+
value: VariableNode<TValid> | ArrayNode<TValid> | GroupNode<TValid> | (TValid extends false ? ErrorToken : never);
|
|
201
|
+
/**
|
|
202
|
+
* If the condition was negated, contains the "not" token, {@link ValidToken} , the condition was negated with.
|
|
203
|
+
*/
|
|
204
|
+
operator?: ValidToken<TOKEN_TYPE.NOT>;
|
|
205
|
+
/**
|
|
206
|
+
* If condition property operators are used, this will contain the property (as a variable), or an error token if it was missing (but some separator or operator was passed).
|
|
207
|
+
*
|
|
208
|
+
* While the property is a variable and can be a quoted variable, it cannot be a prefixed variable string.
|
|
209
|
+
*
|
|
210
|
+
* See the corresponding {@link ParserOptions} for more details.
|
|
211
|
+
*/
|
|
212
|
+
property?: VariableNode | (TValid extends false ? ErrorToken : never);
|
|
213
|
+
/**
|
|
214
|
+
* If condition property operators are used, this will contain the operator.
|
|
215
|
+
*
|
|
216
|
+
* If a "short" form was used, this will contain an `OP_CUSTOM` type token, and the condition's `sep` will always be undefined.
|
|
217
|
+
*
|
|
218
|
+
* If a "long/expanded" form was used, this will contain a `VALUE` type token, and at least one of condition's `sep` tokens will be defined.
|
|
219
|
+
*
|
|
220
|
+
* See the corresponding {@link ParserOptions} for more details.
|
|
221
|
+
*/
|
|
222
|
+
propertyOperator?: AnyToken<TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.VALUE>;
|
|
223
|
+
/**
|
|
224
|
+
* If "long/expanded" form condition property operators are used, this will contain the separators, otherwise it is undefined.
|
|
225
|
+
*
|
|
226
|
+
* If it's defined, either both side will be valid tokens, or only the left, while the right might be undefined or an error token.
|
|
227
|
+
*
|
|
228
|
+
* This is because given a string like `[SEP]val` which would produce an error like `[MISSING PROPERTY ERROR][SEP]var`, the separator is always interpreted as being the left one. And even if we have a situation like `op[SEP]var`, it is always interpreted by the parser as `prop[SEP]var`.
|
|
229
|
+
*
|
|
230
|
+
* Why might the right be undefined instead of an error token? This is because we don't need a separator between the operator and a group, `prop[SEP]op(group)`, but we do between a variable in cases like `prop[SEP]op"var"` which would produce an error token on the right side (we could parse this but it just looks inconsistent).
|
|
231
|
+
*
|
|
232
|
+
* See the corresponding {@link ParserOptions} for more details.
|
|
233
|
+
*/
|
|
234
|
+
sep?: {
|
|
235
|
+
left?: AnyToken<TOKEN_TYPE.OP_EXPANDED_SEP>;
|
|
236
|
+
right?: AnyToken<TOKEN_TYPE.OP_EXPANDED_SEP>;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
export interface NormalizedCondition<TOp extends string = string, TValue = any> {
|
|
240
|
+
type: AST_TYPE.NORMALIZED_CONDITION;
|
|
241
|
+
value: TValue;
|
|
242
|
+
operator?: TOp;
|
|
243
|
+
property: string[];
|
|
244
|
+
negate: boolean;
|
|
245
|
+
}
|
|
246
|
+
export interface NormalizedExpression<TType extends string = string, TValue = any> {
|
|
247
|
+
type: AST_TYPE.NORMALIZED_EXPRESSION;
|
|
248
|
+
left: NormalizedExpression<TType, TValue> | NormalizedCondition<TType, TValue>;
|
|
249
|
+
right: NormalizedExpression<TType, TValue> | NormalizedCondition<TType, TValue>;
|
|
250
|
+
operator: TokenBooleanTypes;
|
|
251
|
+
}
|
|
252
|
+
export type ParentTypes<T extends Node | BaseToken | undefined> = T extends ValidToken ? VariableNode | GroupNode | ExpressionNode | ArrayNode | ConditionNode : T extends ErrorToken ? VariableNode | GroupNode | ExpressionNode | ArrayNode | ConditionNode : T extends GroupNode ? ExpressionNode | GroupNode | undefined : T extends VariableNode ? ConditionNode | ArrayNode | undefined : T extends ExpressionNode ? GroupNode | ExpressionNode | undefined : T extends ArrayNode ? ConditionNode | undefined : T extends ConditionNode | ExpressionNode ? GroupNode | undefined : T extends undefined ? undefined : never;
|
|
64
253
|
//# sourceMappingURL=ast.d.ts.map
|
package/dist/types/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/types/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/types/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAG5D,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,SAAS,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAA;AAE9I,oBAAY,UAAU;IACrB,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,EAAE,OAAO;IACT,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,e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SAAS,GACtC,CAAC,SAAS,YAAY,GACtB,aAAa,GAAG,SAAS,GAAG,SAAS,GACrC,CAAC,SAAS,cAAc,GACxB,SAAS,GAAG,cAAc,GAAG,SAAS,GACtC,CAAC,SAAS,SAAS,GACnB,aAAa,GAAG,SAAS,GACzB,CAAC,SAAS,aAAa,GAAG,cAAc,GACxC,SAAS,GAAG,SAAS,GACrB,CAAC,SAAS,SAAS,GACnB,SAAS,GACT,KAAK,CAAA"}
|
package/dist/types/ast.js
CHANGED
|
@@ -17,9 +17,11 @@ var TOKEN_TYPE = /* @__PURE__ */ ((TOKEN_TYPE2) => {
|
|
|
17
17
|
})(TOKEN_TYPE || {});
|
|
18
18
|
var AST_TYPE = /* @__PURE__ */ ((AST_TYPE2) => {
|
|
19
19
|
AST_TYPE2["EXPRESSION"] = "EXPRESSION";
|
|
20
|
+
AST_TYPE2["NORMALIZED_EXPRESSION"] = "NORMALIZED_EXPRESSION";
|
|
20
21
|
AST_TYPE2["GROUP"] = "GROUP";
|
|
21
22
|
AST_TYPE2["ARRAY"] = "ARRAY";
|
|
22
23
|
AST_TYPE2["CONDITION"] = "CONDITION";
|
|
24
|
+
AST_TYPE2["NORMALIZED_CONDITION"] = "NORMALIZED_CONDITION";
|
|
23
25
|
AST_TYPE2["VARIABLE"] = "VARIABLE";
|
|
24
26
|
return AST_TYPE2;
|
|
25
27
|
})(AST_TYPE || {});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type { AnyToken, Position } from "./ast.js";
|
|
2
|
-
import type { ValidToken } from "../ast/classes/ValidToken.js";
|
|
1
|
+
import type { AnyToken, Position, ValidToken } from "./ast.js";
|
|
3
2
|
/**
|
|
4
|
-
* Contains information regarding the tokens around a cursor position. Mostly for internally use by @
|
|
3
|
+
* Contains information regarding the tokens around a cursor position. Mostly for internally use by {@link autosuggest}.
|
|
5
4
|
*
|
|
6
5
|
* Notes:
|
|
7
6
|
*
|
|
8
|
-
* - There are no whitespace tokens because whitespace is not tokenized. `prev`, `at`, `next` properties that contain tokens are set looking only at the list of tokens extracted from the ast by @
|
|
9
|
-
* - If next/prev are invalid tokens, note that there are cases where more invalid tokens might follow them. To get them we can use @
|
|
7
|
+
* - There are no whitespace tokens because whitespace is not tokenized. `prev`, `at`, `next` properties that contain tokens are set looking only at the list of tokens extracted from the ast by {@link extractTokens}. This is why there is an extra `whitespace` property to tell us whether there is whitespace (i.e. a hole) between the cursor and the next/prev **valid** tokens or if it can't find any, the start/end of the input.
|
|
8
|
+
* - If next/prev are invalid tokens, note that there are cases where more invalid tokens might follow them. To get them we can use {@link getSurroundingErrors} or we can just find their index in the tokens list and go forward/backward as needed:
|
|
10
9
|
* ```ts
|
|
11
10
|
* let i = tokens.findIndex(t => t === info.next)
|
|
12
11
|
* while (tokens[i] instanceof ErrorToken) {...}
|
|
@@ -107,7 +106,7 @@ export type Suggestion = {
|
|
|
107
106
|
type: SUGGESTION_TYPE;
|
|
108
107
|
/** The range the suggestion should replace / be inserted at. */
|
|
109
108
|
range: Position;
|
|
110
|
-
/** @
|
|
109
|
+
/** {@link CursorInfo} */
|
|
111
110
|
cursorInfo: CursorInfo;
|
|
112
111
|
/** Tells us any additional requirements for inserting the suggestion. */
|
|
113
112
|
requires: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../src/types/autocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../src/types/autocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAG9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb;;;;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G;IACH,OAAO,EAAE,OAAO,CAAA;CAChB,CAAA;AAGD,MAAM,MAAM,UAAU,GAAG;IACxB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;CACb,CAAA"}
|
package/dist/types/parser.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { DeepRequired, MakeRequired } from "@alanscodelog/utils/types";
|
|
2
|
-
import type { Position, TOKEN_TYPE } from "./ast.js";
|
|
3
|
-
import type { ArrayNode } from "../ast/classes/ArrayNode.js";
|
|
4
|
-
import type { Condition } from "../ast/classes/Condition.js";
|
|
5
|
-
import type { ConditionNode } from "../ast/classes/ConditionNode.js";
|
|
6
|
-
import type { ValidToken } from "../ast/classes/ValidToken.js";
|
|
7
|
-
import type { VariableNode } from "../ast/classes/VariableNode.js";
|
|
2
|
+
import type { ArrayNode, ConditionNode, NormalizedCondition, Position, TOKEN_TYPE, ValidToken, VariableNode } from "./ast.js";
|
|
8
3
|
export type FullParserOptions<T extends {} = {}> = MakeRequired<ParserOptions<T>, Exclude<keyof ParserOptions<T>, "prefixableStrings" | "expandedPropertySeparator" | "customPropertyOperators" | "keywords">> & {
|
|
9
4
|
keywords: DeepRequired<KeywordOptions>;
|
|
10
5
|
};
|
|
@@ -16,14 +11,14 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
16
11
|
* ```js
|
|
17
12
|
* category.subcategory.(variable1 || variable2 && !variable3)
|
|
18
13
|
* ```
|
|
19
|
-
* returns an @
|
|
14
|
+
* returns an {@link GroupNode} whose prefix is a value token with the value `category.subcategory.`
|
|
20
15
|
*
|
|
21
|
-
* This prefix can later be applied by utility functions when evaluating the expression or extracting information from it. The default @
|
|
16
|
+
* This prefix can later be applied by utility functions when evaluating the expression or extracting information from it. The default {@link PrefixApplier} appends the prefix name to every variable inside the group, so the above would expand into something like:
|
|
22
17
|
* ```js
|
|
23
18
|
* category.subcategory.variable1 || category.subcategory.variable2 || !category.subcategory.variable3
|
|
24
19
|
* ```
|
|
25
20
|
*
|
|
26
|
-
* @
|
|
21
|
+
* {@link UtilityOptions}["prefixApplier"] for more examples and details on how to customize the behavior.
|
|
27
22
|
*/
|
|
28
23
|
prefixableGroups?: boolean;
|
|
29
24
|
/**
|
|
@@ -46,11 +41,11 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
46
41
|
* title:contains(value)
|
|
47
42
|
* ```
|
|
48
43
|
*
|
|
49
|
-
* The information for these types of conditions are stored in a @
|
|
44
|
+
* The information for these types of conditions are stored in a {@link ConditionNode} 's `property`, `propertyOperator`, and `sep` properties.
|
|
50
45
|
*
|
|
51
46
|
* The separator can only be one character long and is added to the list of characters that need to be escaped.
|
|
52
47
|
*
|
|
53
|
-
* The property is always a @
|
|
48
|
+
* The property is always a {@link VariableNode} and can be a quoted variable, but it can never be a prefixed string (if using `prefixableStrings`).
|
|
54
49
|
* ```
|
|
55
50
|
*/
|
|
56
51
|
expandedPropertySeparator?: string;
|
|
@@ -81,7 +76,7 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
81
76
|
* title:(prefix(a OR B)) // title:prefix.a OR title:prefix.b
|
|
82
77
|
* ```
|
|
83
78
|
*
|
|
84
|
-
* Like expanded property operators, these are stored in the @
|
|
79
|
+
* Like expanded property operators, these are stored in the {@link ConditionNode} 's `property`, `propertyOperator` properties. `sep` is not used, not even if the the same operator as the `expandedPropertySeparator` is used. This is what is meant by these types of operators taking priority. If used in this short style, it will always be interpreted as a `propertyOperator`.
|
|
85
80
|
*
|
|
86
81
|
*/
|
|
87
82
|
customPropertyOperators?: string[];
|
|
@@ -176,9 +171,9 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
176
171
|
*/
|
|
177
172
|
keywords?: KeywordOptions;
|
|
178
173
|
/**
|
|
179
|
-
* If prefixableGroups is true, this allows you to control how a prefix is applied for any methods that need to apply them (e.g. @
|
|
174
|
+
* If prefixableGroups is true, this allows you to control how a prefix is applied for any methods that need to apply them (e.g. {@link extractVariables} {@link evaluate}).
|
|
180
175
|
*
|
|
181
|
-
* The default @
|
|
176
|
+
* The default {@link PrefixApplier} function just appends the prefix.
|
|
182
177
|
*
|
|
183
178
|
* So for example:
|
|
184
179
|
*
|
|
@@ -253,7 +248,7 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
253
248
|
/**
|
|
254
249
|
* When evaluating an ast against a context, this function determines whether a context value satisfies a condition.
|
|
255
250
|
*
|
|
256
|
-
* Given a partial {@link
|
|
251
|
+
* Given a partial {@link NormalizedCondition} instance (negate property is not passed) and the contextValue (as extracted using {@link NormalizedCondition.property}), it should return whether the values are equal.
|
|
257
252
|
*
|
|
258
253
|
* It is also passed the context itself for cases where there is no property and you might want to check the value against all properties of the context.
|
|
259
254
|
*
|
|
@@ -278,7 +273,7 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
278
273
|
/**
|
|
279
274
|
* When {@link Parser.normalize normalizing} an ast, this function is needed to determine what exactly the value and operator of the condition is and whether it should be negated when evaluating.
|
|
280
275
|
*
|
|
281
|
-
* Given a query object it should return the values of the `value`, `operator`, and `negate` properties that will be assigned to {@link
|
|
276
|
+
* Given a query object it should return the values of the `value`, `operator`, and `negate` properties that will be assigned to {@link NormalizedCondition}.
|
|
282
277
|
*
|
|
283
278
|
* You can think of the query object as a simplified version of the condition node. See {@link ValueQuery} for details on each property.
|
|
284
279
|
*
|
|
@@ -333,7 +328,7 @@ export type ParserOptions<T extends {} = {}> = {
|
|
|
333
328
|
*/
|
|
334
329
|
conditionNormalizer?: ConditionNormalizer;
|
|
335
330
|
/**
|
|
336
|
-
* Similar to the valueComparer but for validating the ast before it's evaluated using @
|
|
331
|
+
* Similar to the valueComparer but for validating the ast before it's evaluated using {@link Parser}["validate"] (e.g. for syntax highlighting purposes). For the moment the ast must be valid (without syntax errors) to be validated.
|
|
337
332
|
*
|
|
338
333
|
* The only difference is nothing is actually evaluated (even though the values are available to the function\*) and the query contains the actual nodes/tokens for certain properties to make extracting positions easier.
|
|
339
334
|
*
|
|
@@ -417,23 +412,23 @@ export type ValueQuery = {
|
|
|
417
412
|
/** If the operator is an expanded operator. */
|
|
418
413
|
isExpanded: boolean;
|
|
419
414
|
};
|
|
420
|
-
/** @
|
|
415
|
+
/** {@link ParserOptions}["valueValidator"] */
|
|
421
416
|
export type ValidationQuery = Omit<ValueQuery, "value" | "operator" | "prefix" | "regexFlags" | "property"> & {
|
|
422
417
|
value?: VariableNode | ArrayNode;
|
|
423
418
|
operator?: ValidToken<TOKEN_TYPE.VALUE | TOKEN_TYPE.OP_CUSTOM>;
|
|
424
419
|
prefix?: ValidToken<TOKEN_TYPE.VALUE>;
|
|
425
420
|
regexFlags?: ValidToken<TOKEN_TYPE.VALUE>;
|
|
426
421
|
property: VariableNode[];
|
|
427
|
-
/** The property as would be passed to the @
|
|
422
|
+
/** The property as would be passed to the {@link ParserOptions}["valueComparer"] function (i.e. joined as a string using the {@link ParseOptions}["prefixApplier"] ) */
|
|
428
423
|
propertyName?: string;
|
|
429
|
-
/** The property keys, as parsed by @
|
|
424
|
+
/** The property keys, as parsed by {@link ParserOptions}["keysParser"] */
|
|
430
425
|
propertyKeys: string[];
|
|
431
426
|
/**
|
|
432
427
|
* Contains a list of all the wrapping group prefix nodes.
|
|
433
428
|
*/
|
|
434
429
|
prefixes?: VariableNode[];
|
|
435
430
|
};
|
|
436
|
-
export type ValueComparer = (condition: Omit<
|
|
431
|
+
export type ValueComparer = (condition: Omit<NormalizedCondition, "negate">, contextValue: any, context: any) => boolean;
|
|
437
432
|
export type ConditionNormalizer = (query: ValueQuery) => {
|
|
438
433
|
value: any;
|
|
439
434
|
operator: any;
|
|
@@ -443,7 +438,7 @@ export type ValueValidator<T = Record<string, any>> = (contextValue: any | undef
|
|
|
443
438
|
export type KeyParser = (key: string) => string[];
|
|
444
439
|
export type PrefixApplier = (prefix: string, variable: string) => string;
|
|
445
440
|
export type KeywordEntry = {
|
|
446
|
-
/** See @
|
|
441
|
+
/** See {@link ParserOptions}["KeywordOptions"] */
|
|
447
442
|
isSymbol: boolean;
|
|
448
443
|
value: string;
|
|
449
444
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/types/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE3E,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/types/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAI7H,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,YAAY,CAC9D,aAAa,CAAC,CAAC,CAAC,EAEhB,OAAO,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,EAC3B,mBAAmB,GACnB,2BAA2B,GAC3B,yBAAyB,GACzB,UAAU,CACZ,CACD,GACC;IAED,QAAQ,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;CACtC,CAAA;AACD,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI;IAC9C;;;;;;;;;;;;;;;OAeG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B;;;;;;;;;;;;;;;;;;OAkBG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAA;IAClC;;;;;;;;;;;;;;;;OAgBG;IACH,wBAAwB,CAAC,EAA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G,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAA;AACvG,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,GAAG,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,GAAG,SAAS,GAAG,IAAI,CAAA;AAEnL,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EAAE,CAAA;AACjD,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;AAExE,MAAM,MAAM,YAAY,GAAG;IAC1B,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACb,CAAA;AACD,MAAM,MAAM,cAAc,GAAG;IAC5B,EAAE,CAAC,EAAE,YAAY,EAAE,CAAA;IACnB,GAAG,CAAC,EAAE,YAAY,EAAE,CAAA;IACpB,GAAG,CAAC,EAAE,YAAY,EAAE,CAAA;CACpB,CAAA"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ErrorToken } from "../ast
|
|
2
|
-
import { Node } from "../ast/classes/Node.js";
|
|
3
|
-
import type { AnyToken, AST_TYPE } from "../types/ast.js";
|
|
1
|
+
import { type AnyToken, type ErrorToken, type Nodes } from "../types/ast.js";
|
|
4
2
|
/**
|
|
5
3
|
* Extract a list of all the tokens (which might or might not be valid).
|
|
6
4
|
*/
|
|
7
|
-
export declare function extractTokens(ast:
|
|
5
|
+
export declare function extractTokens(ast: ErrorToken | Nodes): AnyToken[];
|
|
8
6
|
//# sourceMappingURL=extractTokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractTokens.d.ts","sourceRoot":"","sources":["../../src/utils/extractTokens.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extractTokens.d.ts","sourceRoot":"","sources":["../../src/utils/extractTokens.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,QAAQ,EAAY,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAGtF;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,KAAK,GAAG,QAAQ,EAAE,CAmDjE"}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import { unreachable } from "@alanscodelog/utils/unreachable.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ExpressionNode } from "../ast/classes/ExpressionNode.js";
|
|
6
|
-
import { GroupNode } from "../ast/classes/GroupNode.js";
|
|
7
|
-
import { Node } from "../ast/classes/Node.js";
|
|
8
|
-
import { VariableNode } from "../ast/classes/VariableNode.js";
|
|
2
|
+
import { isNode } from "./isNode.js";
|
|
3
|
+
import { isToken } from "./isToken.js";
|
|
4
|
+
import { AST_TYPE } from "../types/ast.js";
|
|
9
5
|
function extractTokens(ast) {
|
|
10
6
|
var _a, _b, _c;
|
|
11
|
-
if (ast
|
|
7
|
+
if (isToken(ast) && !ast.valid) {
|
|
12
8
|
return [ast];
|
|
13
9
|
}
|
|
14
|
-
if (ast
|
|
10
|
+
if (ast.type === AST_TYPE.VARIABLE) {
|
|
15
11
|
const prefix = ast.prefix ? [ast.prefix] : [];
|
|
16
12
|
const quoteR = ast.quote ? [ast.quote.right] : [];
|
|
17
13
|
const quoteL = ast.quote ? [ast.quote.left] : [];
|
|
18
14
|
const quoteFlags = ((_a = ast.quote) == null ? void 0 : _a.flags) ? [ast.quote.flags] : [];
|
|
19
15
|
return [...prefix, ...quoteL, ast.value, ...quoteR, ...quoteFlags];
|
|
20
16
|
}
|
|
21
|
-
if (ast
|
|
22
|
-
const value = ast.value
|
|
17
|
+
if (ast.type === AST_TYPE.CONDITION) {
|
|
18
|
+
const value = isNode(ast.value) ? extractTokens(ast.value) : [ast.value];
|
|
23
19
|
const operator = ast.operator ? [ast.operator] : [];
|
|
24
20
|
const property = ast.property ? extractTokens(ast.property) : [];
|
|
25
21
|
const propertyOperator = ast.propertyOperator ? [ast.propertyOperator] : [];
|
|
@@ -27,20 +23,20 @@ function extractTokens(ast) {
|
|
|
27
23
|
const sepR = ((_c = ast.sep) == null ? void 0 : _c.right) ? [ast.sep.right] : [];
|
|
28
24
|
return [...operator, ...property, ...sepL, ...propertyOperator, ...sepR, ...value];
|
|
29
25
|
}
|
|
30
|
-
if (ast
|
|
31
|
-
const prefix = ast.prefix ? ast.prefix
|
|
26
|
+
if (ast.type === AST_TYPE.GROUP) {
|
|
27
|
+
const prefix = ast.prefix ? isNode(ast.prefix) ? extractTokens(ast.prefix) : [ast.prefix] : [];
|
|
32
28
|
const parenL = ast.paren ? [ast.paren.left] : [];
|
|
33
29
|
const parenR = ast.paren ? [ast.paren.right] : [];
|
|
34
|
-
const expression = ast.expression
|
|
30
|
+
const expression = isNode(ast.expression) ? extractTokens(ast.expression) : [ast.expression];
|
|
35
31
|
return [...prefix, ...parenL, ...expression, ...parenR];
|
|
36
32
|
}
|
|
37
|
-
if (ast
|
|
33
|
+
if (ast.type === AST_TYPE.ARRAY) {
|
|
38
34
|
const values = ast.values.map((val) => extractTokens(val));
|
|
39
35
|
return [ast.bracket.left, ...values.flat(), ast.bracket.right];
|
|
40
36
|
}
|
|
41
|
-
if (ast
|
|
42
|
-
const right = ast.right
|
|
43
|
-
const left = ast.left
|
|
37
|
+
if (ast.type === AST_TYPE.EXPRESSION) {
|
|
38
|
+
const right = isNode(ast.right) ? extractTokens(ast.right) : [ast.right];
|
|
39
|
+
const left = isNode(ast.left) ? extractTokens(ast.left) : [ast.left];
|
|
44
40
|
return [...left, ast.operator, ...right];
|
|
45
41
|
}
|
|
46
42
|
return unreachable();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type AnyToken, type Nodes } from "../types/ast.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a map like Map<Node, Parent>, for easily accessing parents of nodes.
|
|
4
|
+
*
|
|
5
|
+
* This is done like this to avoid having circular structures in the ast.
|
|
6
|
+
*
|
|
7
|
+
* To get a properly typed parent, use {@link getParent} which you will need to pass a generated map.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateParentsMap(ast: Nodes | AnyToken): Map<Nodes | AnyToken, Nodes>;
|
|
10
|
+
//# sourceMappingURL=generateParentsMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateParentsMap.d.ts","sourceRoot":"","sources":["../../src/utils/generateParentsMap.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAY,KAAK,KAAK,EAAG,MAAM,iBAAiB,CAAA;AAEtE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,KAAK,GAAG,QAAQ,GAAG,GAAG,CAAC,KAAK,GAAG,QAAQ,EAAE,KAAK,CAAC,CA8CtF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import "@alanscodelog/utils/types";
|
|
2
|
+
import { isNode } from "./isNode.js";
|
|
3
|
+
import { AST_TYPE } from "../types/ast.js";
|
|
4
|
+
function generateParentsMap(ast) {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
6
|
+
const recursiveMap = arguments[1];
|
|
7
|
+
const map = recursiveMap ?? /* @__PURE__ */ new Map();
|
|
8
|
+
const self = generateParentsMap;
|
|
9
|
+
if (ast.type === AST_TYPE.VARIABLE) {
|
|
10
|
+
if (ast.prefix)
|
|
11
|
+
map.set(ast.prefix, ast);
|
|
12
|
+
if ((_a = ast.quote) == null ? void 0 : _a.left)
|
|
13
|
+
map.set(ast.quote.left, ast);
|
|
14
|
+
if ((_b = ast.quote) == null ? void 0 : _b.right)
|
|
15
|
+
map.set(ast.quote.right, ast);
|
|
16
|
+
if ((_c = ast.quote) == null ? void 0 : _c.flags)
|
|
17
|
+
map.set(ast.quote.flags, ast);
|
|
18
|
+
map.set(ast.value, ast);
|
|
19
|
+
} else if (ast.type === AST_TYPE.CONDITION) {
|
|
20
|
+
if (ast.operator)
|
|
21
|
+
map.set(ast.operator, ast);
|
|
22
|
+
if (ast.property) {
|
|
23
|
+
map.set(ast.property, ast);
|
|
24
|
+
if (isNode(ast.property))
|
|
25
|
+
self(ast.property, map);
|
|
26
|
+
}
|
|
27
|
+
if (ast.propertyOperator)
|
|
28
|
+
map.set(ast.propertyOperator, ast);
|
|
29
|
+
if ((_d = ast.sep) == null ? void 0 : _d.left)
|
|
30
|
+
map.set(ast.sep.left, ast);
|
|
31
|
+
if ((_e = ast.sep) == null ? void 0 : _e.right)
|
|
32
|
+
map.set(ast.sep.right, ast);
|
|
33
|
+
map.set(ast.value, ast);
|
|
34
|
+
if (isNode(ast.value))
|
|
35
|
+
self(ast.value, map);
|
|
36
|
+
} else if (ast.type === AST_TYPE.EXPRESSION) {
|
|
37
|
+
if (ast.operator)
|
|
38
|
+
map.set(ast.operator, ast);
|
|
39
|
+
map.set(ast.right, ast);
|
|
40
|
+
if (isNode(ast.right))
|
|
41
|
+
self(ast.right, map);
|
|
42
|
+
map.set(ast.left, ast);
|
|
43
|
+
if (isNode(ast.left))
|
|
44
|
+
self(ast.left, map);
|
|
45
|
+
} else if (ast.type === AST_TYPE.GROUP) {
|
|
46
|
+
if (ast.prefix) {
|
|
47
|
+
map.set(ast.prefix, ast);
|
|
48
|
+
if (isNode(ast.prefix))
|
|
49
|
+
self(ast.prefix, map);
|
|
50
|
+
}
|
|
51
|
+
if ((_f = ast.paren) == null ? void 0 : _f.left)
|
|
52
|
+
map.set(ast.paren.left, ast);
|
|
53
|
+
if ((_g = ast.paren) == null ? void 0 : _g.right)
|
|
54
|
+
map.set(ast.paren.right, ast);
|
|
55
|
+
map.set(ast.expression, ast);
|
|
56
|
+
if (isNode(ast.expression))
|
|
57
|
+
self(ast.expression, map);
|
|
58
|
+
} else if (ast.type === AST_TYPE.ARRAY) {
|
|
59
|
+
if (ast.bracket.left)
|
|
60
|
+
map.set(ast.bracket.left, ast);
|
|
61
|
+
if (ast.bracket.right)
|
|
62
|
+
map.set(ast.bracket.right, ast);
|
|
63
|
+
for (const val of ast.values) {
|
|
64
|
+
map.set(val, ast);
|
|
65
|
+
if (isNode(val))
|
|
66
|
+
self(val, map);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return map;
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
generateParentsMap
|
|
73
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AnyToken, type ParserResults } from "../types/ast.js";
|
|
2
2
|
import { type CursorInfo } from "../types/autocomplete.js";
|
|
3
3
|
/**
|
|
4
|
-
* Returns a @
|
|
4
|
+
* Returns a {@link CursorInfo} object, see it for details.
|
|
5
5
|
*/
|
|
6
6
|
export declare function getCursorInfo(input: string, ast: ParserResults | AnyToken[], index: number): CursorInfo;
|
|
7
7
|
//# sourceMappingURL=getCursorInfo.d.ts.map
|