@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.
Files changed (285) hide show
  1. package/README.md +9 -5
  2. package/dist/Lexer.js +2 -2
  3. package/dist/Parser.d.ts +14 -29
  4. package/dist/Parser.d.ts.map +1 -1
  5. package/dist/Parser.js +120 -135
  6. package/dist/ast/builders/array.d.ts +1 -3
  7. package/dist/ast/builders/array.d.ts.map +1 -1
  8. package/dist/ast/builders/array.js +3 -5
  9. package/dist/ast/builders/condition.d.ts +5 -11
  10. package/dist/ast/builders/condition.d.ts.map +1 -1
  11. package/dist/ast/builders/condition.js +2 -3
  12. package/dist/ast/builders/delim.d.ts +1 -1
  13. package/dist/ast/builders/error.d.ts +3 -4
  14. package/dist/ast/builders/error.d.ts.map +1 -1
  15. package/dist/ast/builders/error.js +6 -2
  16. package/dist/ast/builders/expression.d.ts +3 -7
  17. package/dist/ast/builders/expression.d.ts.map +1 -1
  18. package/dist/ast/builders/expression.js +3 -5
  19. package/dist/ast/builders/group.d.ts +3 -8
  20. package/dist/ast/builders/group.d.ts.map +1 -1
  21. package/dist/ast/builders/group.js +3 -3
  22. package/dist/ast/builders/pos.d.ts +1 -2
  23. package/dist/ast/builders/pos.d.ts.map +1 -1
  24. package/dist/ast/builders/token.d.ts +3 -5
  25. package/dist/ast/builders/token.d.ts.map +1 -1
  26. package/dist/ast/builders/token.js +3 -4
  27. package/dist/ast/builders/type.d.ts +1 -1
  28. package/dist/ast/builders/variable.d.ts +3 -5
  29. package/dist/ast/builders/variable.d.ts.map +1 -1
  30. package/dist/ast/builders/variable.js +2 -3
  31. package/dist/ast/createArrayNode.d.ts +3 -0
  32. package/dist/ast/createArrayNode.d.ts.map +1 -0
  33. package/dist/ast/createArrayNode.js +12 -0
  34. package/dist/ast/createConditionNode.d.ts +11 -0
  35. package/dist/ast/createConditionNode.d.ts.map +1 -0
  36. package/dist/ast/createConditionNode.js +18 -0
  37. package/dist/ast/createExpressionNode.d.ts +3 -0
  38. package/dist/ast/createExpressionNode.d.ts.map +1 -0
  39. package/dist/ast/createExpressionNode.js +14 -0
  40. package/dist/ast/createGroupNode.d.ts +5 -0
  41. package/dist/ast/createGroupNode.d.ts.map +1 -0
  42. package/dist/ast/createGroupNode.js +14 -0
  43. package/dist/ast/createNormalizedCondition.d.ts +3 -0
  44. package/dist/ast/createNormalizedCondition.d.ts.map +1 -0
  45. package/dist/ast/createNormalizedCondition.js +10 -0
  46. package/dist/ast/createNormalizedExpression.d.ts +3 -0
  47. package/dist/ast/createNormalizedExpression.d.ts.map +1 -0
  48. package/dist/ast/createNormalizedExpression.js +10 -0
  49. package/dist/ast/createToken.d.ts +6 -0
  50. package/dist/ast/createToken.d.ts.map +1 -0
  51. package/dist/ast/createToken.js +15 -0
  52. package/dist/ast/createVariableNode.d.ts +3 -0
  53. package/dist/ast/createVariableNode.d.ts.map +1 -0
  54. package/dist/ast/createVariableNode.js +12 -0
  55. package/dist/ast/error.d.ts +3 -0
  56. package/dist/ast/error.d.ts.map +1 -0
  57. package/dist/ast/error.js +9 -0
  58. package/dist/ast/handlers.d.ts +5 -12
  59. package/dist/ast/handlers.d.ts.map +1 -1
  60. package/dist/ast/handlers.js +21 -29
  61. package/dist/ast/index.d.ts +9 -1
  62. package/dist/ast/index.d.ts.map +1 -1
  63. package/dist/ast/index.js +18 -2
  64. package/dist/defaults/defaultConditionNormalizer.d.ts +3 -0
  65. package/dist/defaults/defaultConditionNormalizer.d.ts.map +1 -0
  66. package/dist/defaults/defaultKeyParser.d.ts +3 -0
  67. package/dist/defaults/defaultKeyParser.d.ts.map +1 -0
  68. package/dist/defaults/defaultPrefixApplier.d.ts +3 -0
  69. package/dist/defaults/defaultPrefixApplier.d.ts.map +1 -0
  70. package/dist/defaults/defaultValueComparer.d.ts +3 -0
  71. package/dist/defaults/defaultValueComparer.d.ts.map +1 -0
  72. package/dist/{helpers/general → defaults}/index.d.ts +0 -2
  73. package/dist/defaults/index.d.ts.map +1 -0
  74. package/dist/{helpers/general → defaults}/index.js +0 -4
  75. package/dist/index.d.ts +2 -1
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +3 -1
  78. package/dist/{helpers/errors.d.ts → internal/ExpressitError.d.ts} +3 -2
  79. package/dist/internal/ExpressitError.d.ts.map +1 -0
  80. package/dist/{helpers/errors.js → internal/ExpressitError.js} +2 -2
  81. package/dist/internal/applyBoolean.d.ts.map +1 -0
  82. package/dist/{helpers/general → internal}/applyPrefix.d.ts +1 -1
  83. package/dist/internal/applyPrefix.d.ts.map +1 -0
  84. package/dist/{helpers/parser → internal}/checkParserOpts.d.ts +2 -1
  85. package/dist/internal/checkParserOpts.d.ts.map +1 -0
  86. package/dist/{helpers/parser → internal}/checkParserOpts.js +14 -14
  87. package/dist/internal/escapeVariableOrPrefix.d.ts +2 -0
  88. package/dist/internal/escapeVariableOrPrefix.d.ts.map +1 -0
  89. package/dist/internal/escapeVariableOrPrefix.js +38 -0
  90. package/dist/internal/extractPosition.d.ts +5 -0
  91. package/dist/internal/extractPosition.d.ts.map +1 -0
  92. package/dist/internal/getUnclosedRightParenCount.d.ts +4 -0
  93. package/dist/internal/getUnclosedRightParenCount.d.ts.map +1 -0
  94. package/dist/{helpers/parser → internal}/getUnclosedRightParenCount.js +1 -1
  95. package/dist/{helpers/parser → internal}/parseParserOptions.d.ts +1 -1
  96. package/dist/internal/parseParserOptions.d.ts.map +1 -0
  97. package/dist/{helpers/parser → internal}/parseParserOptions.js +4 -4
  98. package/dist/internal/unescape.d.ts.map +1 -0
  99. package/dist/package.json.js +7 -7
  100. package/dist/types/ast.d.ts +195 -6
  101. package/dist/types/ast.d.ts.map +1 -1
  102. package/dist/types/ast.js +2 -0
  103. package/dist/types/autocomplete.d.ts +5 -6
  104. package/dist/types/autocomplete.d.ts.map +1 -1
  105. package/dist/types/parser.d.ts +17 -22
  106. package/dist/types/parser.d.ts.map +1 -1
  107. package/dist/utils/extractTokens.d.ts +2 -4
  108. package/dist/utils/extractTokens.d.ts.map +1 -1
  109. package/dist/utils/extractTokens.js +14 -18
  110. package/dist/utils/generateParentsMap.d.ts +10 -0
  111. package/dist/utils/generateParentsMap.d.ts.map +1 -0
  112. package/dist/utils/generateParentsMap.js +73 -0
  113. package/dist/utils/getCursorInfo.d.ts +1 -1
  114. package/dist/utils/getCursorInfo.d.ts.map +1 -1
  115. package/dist/utils/getCursorInfo.js +3 -5
  116. package/dist/utils/getOppositeDelimiter.d.ts +2 -1
  117. package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
  118. package/dist/utils/getOppositeDelimiter.js +6 -5
  119. package/dist/utils/getParent.d.ts +5 -0
  120. package/dist/utils/getParent.d.ts.map +1 -0
  121. package/dist/utils/getParent.js +6 -0
  122. package/dist/utils/getSurroundingErrors.d.ts +3 -4
  123. package/dist/utils/getSurroundingErrors.d.ts.map +1 -1
  124. package/dist/utils/getSurroundingErrors.js +3 -3
  125. package/dist/utils/index.d.ts +4 -0
  126. package/dist/utils/index.d.ts.map +1 -1
  127. package/dist/utils/index.js +8 -0
  128. package/dist/utils/isNode.d.ts +10 -0
  129. package/dist/utils/isNode.d.ts.map +1 -0
  130. package/dist/utils/isNode.js +6 -0
  131. package/dist/utils/isToken.d.ts +8 -0
  132. package/dist/utils/isToken.d.ts.map +1 -0
  133. package/dist/utils/isToken.js +6 -0
  134. package/dist/utils/prettyAst.d.ts +1 -2
  135. package/dist/utils/prettyAst.d.ts.map +1 -1
  136. package/dist/utils/prettyAst.js +19 -26
  137. package/package.json +7 -7
  138. package/src/Lexer.ts +2 -2
  139. package/src/Parser.ts +158 -165
  140. package/src/ast/builders/array.ts +4 -9
  141. package/src/ast/builders/condition.ts +10 -15
  142. package/src/ast/builders/delim.ts +1 -1
  143. package/src/ast/builders/error.ts +10 -6
  144. package/src/ast/builders/expression.ts +17 -23
  145. package/src/ast/builders/group.ts +7 -11
  146. package/src/ast/builders/pos.ts +2 -3
  147. package/src/ast/builders/token.ts +6 -7
  148. package/src/ast/builders/type.ts +1 -1
  149. package/src/ast/builders/variable.ts +6 -8
  150. package/src/ast/createArrayNode.ts +17 -0
  151. package/src/ast/createConditionNode.ts +58 -0
  152. package/src/ast/createExpressionNode.ts +21 -0
  153. package/src/ast/createGroupNode.ts +46 -0
  154. package/src/ast/createNormalizedCondition.ts +12 -0
  155. package/src/ast/createNormalizedExpression.ts +9 -0
  156. package/src/ast/createToken.ts +26 -0
  157. package/src/ast/createVariableNode.ts +18 -0
  158. package/src/ast/error.ts +9 -0
  159. package/src/ast/handlers.ts +26 -37
  160. package/src/ast/index.ts +9 -1
  161. package/src/{helpers/general → defaults}/defaultConditionNormalizer.ts +1 -1
  162. package/src/{helpers/general → defaults}/defaultKeyParser.ts +1 -1
  163. package/src/{helpers/general → defaults}/defaultPrefixApplier.ts +1 -1
  164. package/src/{helpers/general → defaults}/defaultValueComparer.ts +1 -1
  165. package/src/{helpers/general → defaults}/index.ts +0 -2
  166. package/src/index.ts +2 -1
  167. package/src/{helpers/errors.ts → internal/ExpressitError.ts} +2 -2
  168. package/src/{helpers/general → internal}/applyPrefix.ts +1 -1
  169. package/src/{helpers/parser → internal}/checkParserOpts.ts +16 -15
  170. package/src/internal/escapeVariableOrPrefix.ts +36 -0
  171. package/src/{helpers/parser → internal}/extractPosition.ts +2 -2
  172. package/src/{helpers/parser → internal}/getUnclosedRightParenCount.ts +1 -2
  173. package/src/{helpers/parser → internal}/parseParserOptions.ts +5 -5
  174. package/src/types/ast.ts +292 -7
  175. package/src/types/autocomplete.ts +5 -7
  176. package/src/types/parser.ts +17 -22
  177. package/src/utils/extractTokens.ts +16 -20
  178. package/src/utils/generateParentsMap.ts +60 -0
  179. package/src/utils/getCursorInfo.ts +4 -6
  180. package/src/utils/getOppositeDelimiter.ts +11 -10
  181. package/src/utils/getParent.ts +16 -0
  182. package/src/utils/getSurroundingErrors.ts +10 -9
  183. package/src/utils/index.ts +4 -0
  184. package/src/utils/isNode.ts +12 -0
  185. package/src/utils/isToken.ts +10 -0
  186. package/src/utils/prettyAst.ts +20 -17
  187. package/dist/ast/classes/ArrayNode.d.ts +0 -18
  188. package/dist/ast/classes/ArrayNode.d.ts.map +0 -1
  189. package/dist/ast/classes/ArrayNode.js +0 -55
  190. package/dist/ast/classes/Condition.d.ts +0 -13
  191. package/dist/ast/classes/Condition.d.ts.map +0 -1
  192. package/dist/ast/classes/Condition.js +0 -21
  193. package/dist/ast/classes/ConditionNode.d.ts +0 -73
  194. package/dist/ast/classes/ConditionNode.d.ts.map +0 -1
  195. package/dist/ast/classes/ConditionNode.js +0 -101
  196. package/dist/ast/classes/ErrorToken.d.ts +0 -27
  197. package/dist/ast/classes/ErrorToken.d.ts.map +0 -1
  198. package/dist/ast/classes/ErrorToken.js +0 -47
  199. package/dist/ast/classes/Expression.d.ts +0 -13
  200. package/dist/ast/classes/Expression.d.ts.map +0 -1
  201. package/dist/ast/classes/Expression.js +0 -19
  202. package/dist/ast/classes/ExpressionNode.d.ts +0 -21
  203. package/dist/ast/classes/ExpressionNode.d.ts.map +0 -1
  204. package/dist/ast/classes/ExpressionNode.js +0 -57
  205. package/dist/ast/classes/GroupNode.d.ts +0 -64
  206. package/dist/ast/classes/GroupNode.d.ts.map +0 -1
  207. package/dist/ast/classes/GroupNode.js +0 -69
  208. package/dist/ast/classes/Node.d.ts +0 -22
  209. package/dist/ast/classes/Node.d.ts.map +0 -1
  210. package/dist/ast/classes/Node.js +0 -28
  211. package/dist/ast/classes/Token.d.ts +0 -27
  212. package/dist/ast/classes/Token.d.ts.map +0 -1
  213. package/dist/ast/classes/Token.js +0 -28
  214. package/dist/ast/classes/ValidToken.d.ts +0 -26
  215. package/dist/ast/classes/ValidToken.d.ts.map +0 -1
  216. package/dist/ast/classes/ValidToken.js +0 -49
  217. package/dist/ast/classes/VariableNode.d.ts +0 -33
  218. package/dist/ast/classes/VariableNode.d.ts.map +0 -1
  219. package/dist/ast/classes/VariableNode.js +0 -58
  220. package/dist/ast/classes/index.d.ts +0 -12
  221. package/dist/ast/classes/index.d.ts.map +0 -1
  222. package/dist/ast/classes/index.js +0 -24
  223. package/dist/helpers/errors.d.ts.map +0 -1
  224. package/dist/helpers/general/applyBoolean.d.ts.map +0 -1
  225. package/dist/helpers/general/applyPrefix.d.ts.map +0 -1
  226. package/dist/helpers/general/defaultConditionNormalizer.d.ts +0 -3
  227. package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +0 -1
  228. package/dist/helpers/general/defaultKeyParser.d.ts +0 -3
  229. package/dist/helpers/general/defaultKeyParser.d.ts.map +0 -1
  230. package/dist/helpers/general/defaultPrefixApplier.d.ts +0 -3
  231. package/dist/helpers/general/defaultPrefixApplier.d.ts.map +0 -1
  232. package/dist/helpers/general/defaultValueComparer.d.ts +0 -3
  233. package/dist/helpers/general/defaultValueComparer.d.ts.map +0 -1
  234. package/dist/helpers/general/index.d.ts.map +0 -1
  235. package/dist/helpers/index.d.ts +0 -4
  236. package/dist/helpers/index.d.ts.map +0 -1
  237. package/dist/helpers/index.js +0 -8
  238. package/dist/helpers/parser/assignParents.d.ts +0 -4
  239. package/dist/helpers/parser/assignParents.d.ts.map +0 -1
  240. package/dist/helpers/parser/assignParents.js +0 -71
  241. package/dist/helpers/parser/checkParserOpts.d.ts.map +0 -1
  242. package/dist/helpers/parser/extractPosition.d.ts +0 -5
  243. package/dist/helpers/parser/extractPosition.d.ts.map +0 -1
  244. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +0 -4
  245. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +0 -1
  246. package/dist/helpers/parser/index.d.ts +0 -9
  247. package/dist/helpers/parser/index.d.ts.map +0 -1
  248. package/dist/helpers/parser/index.js +0 -18
  249. package/dist/helpers/parser/parseParserOptions.d.ts.map +0 -1
  250. package/dist/helpers/parser/seal.d.ts +0 -8
  251. package/dist/helpers/parser/seal.d.ts.map +0 -1
  252. package/dist/helpers/parser/seal.js +0 -10
  253. package/dist/helpers/parser/setParent.d.ts +0 -6
  254. package/dist/helpers/parser/setParent.d.ts.map +0 -1
  255. package/dist/helpers/parser/setParent.js +0 -4
  256. package/dist/helpers/parser/unescape.d.ts.map +0 -1
  257. package/src/ast/classes/ArrayNode.ts +0 -46
  258. package/src/ast/classes/Condition.ts +0 -22
  259. package/src/ast/classes/ConditionNode.ts +0 -141
  260. package/src/ast/classes/ErrorToken.ts +0 -49
  261. package/src/ast/classes/Expression.ts +0 -26
  262. package/src/ast/classes/ExpressionNode.ts +0 -62
  263. package/src/ast/classes/GroupNode.ts +0 -127
  264. package/src/ast/classes/Node.ts +0 -47
  265. package/src/ast/classes/Token.ts +0 -59
  266. package/src/ast/classes/ValidToken.ts +0 -56
  267. package/src/ast/classes/VariableNode.ts +0 -67
  268. package/src/ast/classes/index.ts +0 -13
  269. package/src/helpers/index.ts +0 -6
  270. package/src/helpers/parser/assignParents.ts +0 -51
  271. package/src/helpers/parser/index.ts +0 -10
  272. package/src/helpers/parser/seal.ts +0 -14
  273. package/src/helpers/parser/setParent.ts +0 -5
  274. /package/dist/{helpers/general → defaults}/defaultConditionNormalizer.js +0 -0
  275. /package/dist/{helpers/general → defaults}/defaultKeyParser.js +0 -0
  276. /package/dist/{helpers/general → defaults}/defaultPrefixApplier.js +0 -0
  277. /package/dist/{helpers/general → defaults}/defaultValueComparer.js +0 -0
  278. /package/dist/{helpers/general → internal}/applyBoolean.d.ts +0 -0
  279. /package/dist/{helpers/general → internal}/applyBoolean.js +0 -0
  280. /package/dist/{helpers/general → internal}/applyPrefix.js +0 -0
  281. /package/dist/{helpers/parser → internal}/extractPosition.js +0 -0
  282. /package/dist/{helpers/parser → internal}/unescape.d.ts +0 -0
  283. /package/dist/{helpers/parser → internal}/unescape.js +0 -0
  284. /package/src/{helpers/general → internal}/applyBoolean.ts +0 -0
  285. /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
-
@@ -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
- }
@@ -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
- }
@@ -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"
@@ -1,6 +0,0 @@
1
- export * as general from "./general/index.js"
2
- export * as parser from "./parser/index.js"
3
-
4
- /* Autogenerated Index [Ignore] */
5
-
6
- export { BooleanParserLibraryError } from "./errors.js"
@@ -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
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * @internal
3
- * @see assignParents
4
- */
5
- export const setParent: unique symbol = Symbol("private set parent key")
File without changes
File without changes
File without changes