@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
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { ConditionNode } from "./ConditionNode.js"
|
|
2
|
-
import type { ErrorToken } from "./ErrorToken.js"
|
|
3
|
-
import type { ExpressionNode } from "./ExpressionNode.js"
|
|
4
|
-
import { Node } from "./Node.js"
|
|
5
|
-
import { ValidToken } from "./ValidToken.js"
|
|
6
|
-
|
|
7
|
-
import { AST_TYPE, type NodeDelimiters, type TOKEN_TYPE } from "../../types/ast.js"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A node that symbolizes a parenthesized expression (might be negated), and if `prefixableGroups` is enabled, a prefixed expression @see ParserOptions .
|
|
12
|
-
*
|
|
13
|
-
* ```txt
|
|
14
|
-
* (a || b)
|
|
15
|
-
* |----| ExpressionNode
|
|
16
|
-
* |------| GroupNode
|
|
17
|
-
*
|
|
18
|
-
* !(a || b)
|
|
19
|
-
* ^ prefix: "not" Token
|
|
20
|
-
* |----| ExpressionNode
|
|
21
|
-
* |-------| GroupNode
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* If `prefixableGroups` is enabled:
|
|
25
|
-
* ```txt
|
|
26
|
-
* prefix(a || b)
|
|
27
|
-
* |----| prefix: ConditionNode
|
|
28
|
-
* |----| ExpressionNode
|
|
29
|
-
* |------------| GroupNode
|
|
30
|
-
*
|
|
31
|
-
* !prefix(a || b)
|
|
32
|
-
* |-----| prefix: ConditionNode
|
|
33
|
-
* |----| ExpressionNode
|
|
34
|
-
* |-------------| GroupNode
|
|
35
|
-
*
|
|
36
|
-
* !(a || b)
|
|
37
|
-
* ^ prefix: STILL a "not" Token
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
export class GroupNode<
|
|
42
|
-
TValid extends boolean = boolean,
|
|
43
|
-
TPrefixable extends boolean = true,
|
|
44
|
-
TPrefix extends
|
|
45
|
-
TPrefixable extends true
|
|
46
|
-
? ConditionNode<TValid> |
|
|
47
|
-
ValidToken<TOKEN_TYPE.NOT> |
|
|
48
|
-
undefined
|
|
49
|
-
: ValidToken<TOKEN_TYPE.NOT> |
|
|
50
|
-
undefined =
|
|
51
|
-
TPrefixable extends true
|
|
52
|
-
? ConditionNode<TValid> |
|
|
53
|
-
ValidToken<TOKEN_TYPE.NOT> |
|
|
54
|
-
undefined
|
|
55
|
-
: ValidToken<TOKEN_TYPE.NOT>,
|
|
56
|
-
>
|
|
57
|
-
extends Node<AST_TYPE.GROUP> {
|
|
58
|
-
/**
|
|
59
|
-
* If the condition is negated this will contain a "not" **token**, @see ValidToken .
|
|
60
|
-
*
|
|
61
|
-
* If `prefixableGroups` is enabled and the group is prefixed by a **condition**, this will be an @see ConditionNode.
|
|
62
|
-
*
|
|
63
|
-
* **Careful:** `!(a)` here this would not be a **condition** since it's just a regular negation.
|
|
64
|
-
*
|
|
65
|
-
* See examples at @see GroupNode .
|
|
66
|
-
*/
|
|
67
|
-
readonly prefix: TPrefix
|
|
68
|
-
|
|
69
|
-
expression:
|
|
70
|
-
| ConditionNode<TValid>
|
|
71
|
-
| GroupNode<TValid>
|
|
72
|
-
| ExpressionNode<TValid>
|
|
73
|
-
| (TValid extends false ? ErrorToken<TOKEN_TYPE.VALUE> : never)
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The parenthesis tokens, @see ValidToken . These will always be defined (although not necessarily with valid tokens).
|
|
77
|
-
*/
|
|
78
|
-
readonly paren: NodeDelimiters<TOKEN_TYPE.PARENL, TOKEN_TYPE.PARENR>
|
|
79
|
-
|
|
80
|
-
#parent: any
|
|
81
|
-
|
|
82
|
-
#setParent: boolean = false
|
|
83
|
-
|
|
84
|
-
get parent(): ExpressionNode | undefined {
|
|
85
|
-
return this.#parent
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
set parent(value: ExpressionNode | undefined) {
|
|
89
|
-
if (this.#setParent) {throw new Error("parent property is readonly")}
|
|
90
|
-
this.#parent = value
|
|
91
|
-
this.#setParent = true
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
constructor({ prefix, expression, paren, start, end }: {
|
|
95
|
-
prefix: TPrefix
|
|
96
|
-
expression: GroupNode<TValid>["expression"]
|
|
97
|
-
paren: GroupNode<TValid>["paren"]
|
|
98
|
-
start: number
|
|
99
|
-
end: number
|
|
100
|
-
}) {
|
|
101
|
-
super(AST_TYPE.GROUP, start, end)
|
|
102
|
-
this.prefix = prefix
|
|
103
|
-
this.expression = expression
|
|
104
|
-
this.paren = paren
|
|
105
|
-
// @ts-expect-error ignore readonly
|
|
106
|
-
this.valid = (
|
|
107
|
-
(
|
|
108
|
-
this.prefix === undefined ||
|
|
109
|
-
this.prefix instanceof ValidToken ||
|
|
110
|
-
(
|
|
111
|
-
this.prefix instanceof Node &&
|
|
112
|
-
this.prefix.valid
|
|
113
|
-
)
|
|
114
|
-
) &&
|
|
115
|
-
this.expression instanceof Node &&
|
|
116
|
-
this.expression.valid &&
|
|
117
|
-
(
|
|
118
|
-
this.paren === undefined ||
|
|
119
|
-
(
|
|
120
|
-
this.paren.left instanceof ValidToken &&
|
|
121
|
-
this.paren.right instanceof ValidToken
|
|
122
|
-
)
|
|
123
|
-
)
|
|
124
|
-
) as TValid
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
package/src/ast/classes/Node.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { ArrayNode } from "./ArrayNode.js"
|
|
2
|
-
import type { ConditionNode } from "./ConditionNode.js"
|
|
3
|
-
import type { ExpressionNode } from "./ExpressionNode.js"
|
|
4
|
-
import type { GroupNode } from "./GroupNode.js"
|
|
5
|
-
|
|
6
|
-
import { BooleanParserLibraryError } from "../../helpers/errors.js"
|
|
7
|
-
import type { AST_TYPE } from "../../types/ast.js"
|
|
8
|
-
import { ERROR_CODES } from "../../types/errors.js"
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The base AST node class all node types extend from. Can be used to check if an object is an ast node.
|
|
12
|
-
* ```ts
|
|
13
|
-
* if (group.prefix instanceof Node) {
|
|
14
|
-
* //...
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export class Node<
|
|
19
|
-
TType extends AST_TYPE = AST_TYPE,
|
|
20
|
-
TValid extends boolean = boolean,
|
|
21
|
-
> {
|
|
22
|
-
readonly type: TType
|
|
23
|
-
|
|
24
|
-
readonly start: number
|
|
25
|
-
|
|
26
|
-
readonly end: number
|
|
27
|
-
|
|
28
|
-
readonly valid!: TValid
|
|
29
|
-
|
|
30
|
-
get parent():
|
|
31
|
-
ConditionNode |
|
|
32
|
-
GroupNode |
|
|
33
|
-
ExpressionNode |
|
|
34
|
-
ArrayNode |
|
|
35
|
-
undefined {
|
|
36
|
-
return undefined as any
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
constructor(type: TType, start: number, end: number) {
|
|
40
|
-
this.type = type
|
|
41
|
-
if (start === undefined || end === undefined) {
|
|
42
|
-
throw new BooleanParserLibraryError(ERROR_CODES.PARSER_POSITION_ERROR, { start, end })
|
|
43
|
-
}
|
|
44
|
-
this.start = start
|
|
45
|
-
this.end = end
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/ast/classes/Token.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { ArrayNode } from "./ArrayNode.js"
|
|
2
|
-
import type { ConditionNode } from "./ConditionNode.js"
|
|
3
|
-
import type { ExpressionNode } from "./ExpressionNode.js"
|
|
4
|
-
import type { GroupNode } from "./GroupNode.js"
|
|
5
|
-
import type { VariableNode } from "./VariableNode.js"
|
|
6
|
-
|
|
7
|
-
import { BooleanParserLibraryError } from "../../helpers/errors.js"
|
|
8
|
-
import type { TOKEN_TYPE } from "../../types/ast.js"
|
|
9
|
-
import { ERROR_CODES } from "../../types/errors.js"
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The base class from which @see ValidToken and @see ErrorToken extend.
|
|
13
|
-
*
|
|
14
|
-
* Mostly for internal use, and I would suggest using @see AnyToken instead of this for typing things, but can be used to check whether an object is a token:
|
|
15
|
-
* ```ts
|
|
16
|
-
* if (group.prefix instanceof Token) {
|
|
17
|
-
* //...
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
* Only really takes care of setting the start/end position.
|
|
21
|
-
*/
|
|
22
|
-
export class Token<
|
|
23
|
-
TValid extends boolean = boolean,
|
|
24
|
-
TType extends
|
|
25
|
-
TValid extends true ? TOKEN_TYPE : never =
|
|
26
|
-
TValid extends true ? TOKEN_TYPE : never,
|
|
27
|
-
TValue extends
|
|
28
|
-
TValid extends true ? string : never =
|
|
29
|
-
TValid extends true ? string : never,
|
|
30
|
-
TExpected extends
|
|
31
|
-
TValid extends false ? TOKEN_TYPE[] : never =
|
|
32
|
-
TValid extends false ? TOKEN_TYPE[] : never,
|
|
33
|
-
> {
|
|
34
|
-
readonly type!: TType
|
|
35
|
-
|
|
36
|
-
readonly value!: TValue
|
|
37
|
-
|
|
38
|
-
readonly expected!: TExpected
|
|
39
|
-
|
|
40
|
-
readonly start!: number
|
|
41
|
-
|
|
42
|
-
readonly end!: number
|
|
43
|
-
|
|
44
|
-
get parent(): VariableNode |
|
|
45
|
-
GroupNode |
|
|
46
|
-
ExpressionNode |
|
|
47
|
-
ArrayNode |
|
|
48
|
-
ConditionNode {
|
|
49
|
-
return undefined as any
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
constructor(start: number, end: number) {
|
|
53
|
-
if (start === undefined || end === undefined) {
|
|
54
|
-
throw new BooleanParserLibraryError(ERROR_CODES.PARSER_POSITION_ERROR, { start, end })
|
|
55
|
-
}
|
|
56
|
-
this.start = start
|
|
57
|
-
this.end = end
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { ArrayNode } from "./ArrayNode.js"
|
|
2
|
-
import type { ConditionNode } from "./ConditionNode.js"
|
|
3
|
-
import type { ExpressionNode } from "./ExpressionNode.js"
|
|
4
|
-
import type { GroupNode } from "./GroupNode.js"
|
|
5
|
-
import { Token } from "./Token.js"
|
|
6
|
-
import type { VariableNode } from "./VariableNode.js"
|
|
7
|
-
|
|
8
|
-
import type { TOKEN_TYPE } from "../../types/ast.js"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The class for all *valid* tokens.
|
|
13
|
-
*
|
|
14
|
-
* Valid tokens always have a value, even if it might be an empty string.
|
|
15
|
-
*/
|
|
16
|
-
export class ValidToken<
|
|
17
|
-
TType extends TOKEN_TYPE = TOKEN_TYPE,
|
|
18
|
-
> extends Token<true, TType, string, never> {
|
|
19
|
-
readonly type: TType
|
|
20
|
-
|
|
21
|
-
readonly value: string
|
|
22
|
-
|
|
23
|
-
#parent: any
|
|
24
|
-
|
|
25
|
-
get parent():
|
|
26
|
-
| VariableNode
|
|
27
|
-
| GroupNode
|
|
28
|
-
| ExpressionNode
|
|
29
|
-
| ConditionNode
|
|
30
|
-
| ArrayNode {
|
|
31
|
-
return this.#parent
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
set parent(value:
|
|
35
|
-
| VariableNode
|
|
36
|
-
| GroupNode
|
|
37
|
-
| ExpressionNode
|
|
38
|
-
| ConditionNode
|
|
39
|
-
| ArrayNode,
|
|
40
|
-
) {
|
|
41
|
-
if (this.#parent) {throw new Error("parent property is readonly")}
|
|
42
|
-
this.#parent = value
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
constructor({ type, value, start, end }: {
|
|
46
|
-
type: TType
|
|
47
|
-
value: string
|
|
48
|
-
start: number
|
|
49
|
-
end: number
|
|
50
|
-
},
|
|
51
|
-
) {
|
|
52
|
-
super(start, end)
|
|
53
|
-
this.type = type
|
|
54
|
-
this.value = value
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { ArrayNode } from "./ArrayNode.js"
|
|
2
|
-
import type { ConditionNode } from "./ConditionNode.js"
|
|
3
|
-
import type { ErrorToken } from "./ErrorToken.js"
|
|
4
|
-
import { Node } from "./Node.js"
|
|
5
|
-
import { ValidToken } from "./ValidToken.js"
|
|
6
|
-
|
|
7
|
-
import { type AnyToken, AST_TYPE, type NodeDelimiters, type TOKEN_TYPE, type TokenQuoteTypes } from "../../types/ast.js"
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A variable represents **just** a string value (NOT it's boolean value).
|
|
11
|
-
*
|
|
12
|
-
* The parser will never return just a variable, they are always wrapped in an @see ConditionNode to give them a boolean value.
|
|
13
|
-
*
|
|
14
|
-
* A variable might or might not be quoted. If it is, the `quote` property will contain the quote tokens, @see ValidToken . While they will always be of the same quote type, one might be valid while the other might not (@see ErrorToken).
|
|
15
|
-
*
|
|
16
|
-
* `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. @see evaluate will take care of unescaping when needed.
|
|
17
|
-
*
|
|
18
|
-
* If `prefixableStrings` is true, the `prefix` property might contain a value token.
|
|
19
|
-
*/
|
|
20
|
-
export class VariableNode<
|
|
21
|
-
TValid extends boolean = boolean,
|
|
22
|
-
> extends Node<AST_TYPE.VARIABLE, TValid> {
|
|
23
|
-
readonly value: TValid extends boolean
|
|
24
|
-
? AnyToken<TOKEN_TYPE.VALUE>
|
|
25
|
-
: TValid extends true
|
|
26
|
-
? ValidToken<TOKEN_TYPE.VALUE>
|
|
27
|
-
: ErrorToken<TOKEN_TYPE.VALUE>
|
|
28
|
-
|
|
29
|
-
readonly prefix?: ValidToken<TOKEN_TYPE.VALUE> // todo
|
|
30
|
-
|
|
31
|
-
readonly quote?: NodeDelimiters<TokenQuoteTypes, TokenQuoteTypes>
|
|
32
|
-
|
|
33
|
-
#parent: any
|
|
34
|
-
|
|
35
|
-
#setParent: boolean = false
|
|
36
|
-
|
|
37
|
-
get parent(): ConditionNode | ArrayNode | undefined {
|
|
38
|
-
return this.#parent
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
set parent(value: ConditionNode | ArrayNode | undefined) {
|
|
42
|
-
if (this.#setParent) {throw new Error("parent property is readonly")}
|
|
43
|
-
this.#parent = value
|
|
44
|
-
this.#setParent = true
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
constructor({ prefix, value, quote, start, end }: {
|
|
48
|
-
prefix?: VariableNode<TValid>["prefix"]
|
|
49
|
-
value: VariableNode<TValid>["value"]
|
|
50
|
-
quote?: VariableNode<TValid>["quote"]
|
|
51
|
-
start: number
|
|
52
|
-
end: number
|
|
53
|
-
}) {
|
|
54
|
-
super(AST_TYPE.VARIABLE, start, end)
|
|
55
|
-
this.prefix = prefix
|
|
56
|
-
this.value = value
|
|
57
|
-
this.quote = quote
|
|
58
|
-
// @ts-expect-error ignore readonly
|
|
59
|
-
this.valid = (this.value instanceof ValidToken && (
|
|
60
|
-
this.quote === undefined ||
|
|
61
|
-
(
|
|
62
|
-
this.quote.left instanceof ValidToken &&
|
|
63
|
-
this.quote.right instanceof ValidToken
|
|
64
|
-
)
|
|
65
|
-
)) as TValid
|
|
66
|
-
}
|
|
67
|
-
}
|
package/src/ast/classes/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* Autogenerated Index [Ignore] */
|
|
2
|
-
|
|
3
|
-
export { ArrayNode } from "./ArrayNode.js"
|
|
4
|
-
export { Condition } from "./Condition.js"
|
|
5
|
-
export { ConditionNode } from "./ConditionNode.js"
|
|
6
|
-
export { ErrorToken } from "./ErrorToken.js"
|
|
7
|
-
export { Expression } from "./Expression.js"
|
|
8
|
-
export { ExpressionNode } from "./ExpressionNode.js"
|
|
9
|
-
export { GroupNode } from "./GroupNode.js"
|
|
10
|
-
export { Node } from "./Node.js"
|
|
11
|
-
export { Token } from "./Token.js"
|
|
12
|
-
export { ValidToken } from "./ValidToken.js"
|
|
13
|
-
export { VariableNode } from "./VariableNode.js"
|
package/src/helpers/index.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ArrayNode } from "../../ast/classes/ArrayNode.js"
|
|
2
|
-
import { ConditionNode } from "../../ast/classes/ConditionNode.js"
|
|
3
|
-
import { ExpressionNode } from "../../ast/classes/ExpressionNode.js"
|
|
4
|
-
import { GroupNode } from "../../ast/classes/GroupNode.js"
|
|
5
|
-
import { Node } from "../../ast/classes/Node.js"
|
|
6
|
-
import { VariableNode } from "../../ast/classes/VariableNode.js"
|
|
7
|
-
import type { Nodes } from "../../types/ast.js"
|
|
8
|
-
|
|
9
|
-
/** @internal */
|
|
10
|
-
export function assignParents(ast: Nodes): void {
|
|
11
|
-
if (ast instanceof VariableNode) {
|
|
12
|
-
if (ast.prefix) ast.prefix.parent = ast
|
|
13
|
-
if (ast.quote?.left) ast.quote.left.parent = ast
|
|
14
|
-
if (ast.quote?.right) ast.quote.right.parent = ast
|
|
15
|
-
if (ast.quote?.flags) ast.quote.flags.parent = ast
|
|
16
|
-
ast.value.parent = ast
|
|
17
|
-
} else if (ast instanceof ConditionNode) {
|
|
18
|
-
if (ast.operator) ast.operator.parent = ast
|
|
19
|
-
if (ast.property) {
|
|
20
|
-
ast.property.parent = ast
|
|
21
|
-
if (ast.property instanceof Node) assignParents(ast.property)
|
|
22
|
-
}
|
|
23
|
-
if (ast.propertyOperator) ast.propertyOperator.parent = ast
|
|
24
|
-
if (ast.sep?.left) ast.sep.left.parent = ast
|
|
25
|
-
if (ast.sep?.right) ast.sep.right.parent = ast
|
|
26
|
-
ast.value.parent = ast
|
|
27
|
-
if (ast.value instanceof Node) assignParents(ast.value)
|
|
28
|
-
} else if (ast instanceof ExpressionNode) {
|
|
29
|
-
if (ast.operator) ast.operator.parent = ast
|
|
30
|
-
ast.right.parent = ast
|
|
31
|
-
if (ast.right instanceof Node) assignParents(ast.right)
|
|
32
|
-
ast.left.parent = ast
|
|
33
|
-
if (ast.left instanceof Node) assignParents(ast.left)
|
|
34
|
-
} else if (ast instanceof GroupNode) {
|
|
35
|
-
if (ast.prefix) {
|
|
36
|
-
ast.prefix.parent = ast
|
|
37
|
-
if (ast.prefix instanceof Node) assignParents(ast.prefix)
|
|
38
|
-
}
|
|
39
|
-
if (ast.paren?.left) ast.paren.left.parent = ast
|
|
40
|
-
if (ast.paren?.right) ast.paren.right.parent = ast
|
|
41
|
-
ast.expression.parent = ast
|
|
42
|
-
if (ast.expression instanceof Node) assignParents(ast.expression)
|
|
43
|
-
} else if (ast instanceof ArrayNode) {
|
|
44
|
-
if (ast.bracket.left) ast.bracket.left.parent = ast
|
|
45
|
-
if (ast.bracket.right) ast.bracket.right.parent = ast
|
|
46
|
-
for (const val of ast.values) {
|
|
47
|
-
val.parent = ast
|
|
48
|
-
assignParents(val)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/* Autogenerated Index [Ignore] */
|
|
2
|
-
|
|
3
|
-
export { assignParents } from "./assignParents.js"
|
|
4
|
-
export { checkParserOpts } from "./checkParserOpts.js"
|
|
5
|
-
export { extractPosition } from "./extractPosition.js"
|
|
6
|
-
export { getUnclosedRightParenCount } from "./getUnclosedRightParenCount.js"
|
|
7
|
-
export { parseParserOptions } from "./parseParserOptions.js"
|
|
8
|
-
export { seal } from "./seal.js"
|
|
9
|
-
export { setParent } from "./setParent.js"
|
|
10
|
-
export { unescape } from "./unescape.js"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { assignParents } from "./assignParents.js"
|
|
2
|
-
|
|
3
|
-
import { Node } from "../../ast/classes/Node.js"
|
|
4
|
-
import type { AnyToken, Nodes } from "../../types/ast.js"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* set and "seals" all parent properties
|
|
8
|
-
*
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export function seal(ast: Nodes | AnyToken): void {
|
|
12
|
-
if (ast instanceof Node) assignParents(ast)
|
|
13
|
-
ast.parent = undefined
|
|
14
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|