@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
@@ -3,14 +3,12 @@ import { unreachable } from "@alanscodelog/utils/unreachable.js"
3
3
 
4
4
  import { extractTokens } from "./extractTokens.js"
5
5
 
6
- import { ErrorToken } from "../ast/classes/ErrorToken.js"
7
- import { ValidToken } from "../ast/classes/ValidToken.js"
8
6
  import { type AnyToken, type ParserResults } from "../types/ast.js"
9
7
  import { type CursorInfo } from "../types/autocomplete.js"
10
8
 
11
9
 
12
10
  /**
13
- * Returns a @see CursorInfo object, see it for details.
11
+ * Returns a {@link CursorInfo} object, see it for details.
14
12
  */
15
13
  export function getCursorInfo(
16
14
  input: string,
@@ -42,7 +40,7 @@ export function getCursorInfo(
42
40
  for (const token of tokens) {
43
41
  // assign valid tokens until maybe real previous token overwrites it
44
42
  if (token.end <= index) {
45
- if (token instanceof ValidToken) {
43
+ if (token.valid) {
46
44
  info.prev = token
47
45
  info.valid.prev = token
48
46
  } else if (token.end !== index) {
@@ -51,7 +49,7 @@ export function getCursorInfo(
51
49
  }
52
50
  }
53
51
  if (token.start < index && token.end > index) {
54
- if (token instanceof ErrorToken) {
52
+ if (!token.valid) {
55
53
  unreachable()
56
54
  } else {
57
55
  info.at = token
@@ -59,7 +57,7 @@ export function getCursorInfo(
59
57
  }
60
58
  if (token.start >= index) {
61
59
  info.next ||= token
62
- if (token instanceof ValidToken && !info.valid.next) {
60
+ if (token.valid && !info.valid.next) {
63
61
  info.valid.next = token
64
62
  break
65
63
  }
@@ -1,36 +1,37 @@
1
1
  import { unreachable } from "@alanscodelog/utils/unreachable.js"
2
2
 
3
+ import type { generateParentsMap } from "./generateParentsMap.js"
3
4
  import { isBracket } from "./isBracket.js"
4
5
  import { isDelimiter } from "./isDelimiter.js"
5
6
  import { isParen } from "./isParen.js"
6
7
  import { isQuote } from "./isQuote.js"
7
8
 
8
- import type { ArrayNode } from "../ast/classes/ArrayNode.js"
9
- import type { ConditionNode } from "../ast/classes/ConditionNode.js"
10
- import type { GroupNode } from "../ast/classes/GroupNode.js"
11
- import type { VariableNode } from "../ast/classes/VariableNode.js"
12
- import { type AnyToken, TOKEN_TYPE, type TokenDelimiterTypes } from "../types/ast.js"
9
+ import { type AnyToken, type ArrayNode, type ConditionNode,type GroupNode, TOKEN_TYPE, type TokenDelimiterTypes, type VariableNode } from "../types/ast.js"
13
10
 
14
11
  /**
15
12
  * Given a delimiter token, returns it's opposite pair, or undefined if the type passed was not a delimiter token (so you can pass any type without checking).
16
13
  */
17
- export function getOppositeDelimiter(token: AnyToken): AnyToken<TokenDelimiterTypes> | undefined {
14
+ export function getOppositeDelimiter(
15
+ token: AnyToken,
16
+ parentsMap: ReturnType<typeof generateParentsMap>
17
+ ): AnyToken<TokenDelimiterTypes> | undefined {
18
+ const parent = parentsMap.get(token)
18
19
  if (!isDelimiter(token)) throw new Error("Token is not a delimiter type.")
19
20
  if (isParen(token)) {
20
- const paren = (token.parent as GroupNode).paren
21
+ const paren = (parent as GroupNode).paren
21
22
  const opposite = paren.left === token ? "right" : "left"
22
23
  return paren[opposite]
23
24
  } else if (isBracket(token)) {
24
- const bracket = (token.parent as ArrayNode).bracket
25
+ const bracket = (parent as ArrayNode).bracket
25
26
  const opposite = bracket.left === token ? "right" : "left"
26
27
  return bracket[opposite]
27
28
  } else if (isQuote(token)) {
28
- const quotes = (token.parent as VariableNode).quote
29
+ const quotes = (parent as VariableNode).quote
29
30
  if (quotes === undefined) unreachable()
30
31
  const opposite = quotes.left === token ? "right" : "left"
31
32
  return quotes[opposite]
32
33
  } else if (token.type === TOKEN_TYPE.OP_EXPANDED_SEP) {
33
- const sep = (token.parent as ConditionNode).sep
34
+ const sep = (parent as ConditionNode).sep
34
35
  if (sep === undefined) unreachable()
35
36
  const opposite = sep.left === token ? "right" : "left"
36
37
  return sep[opposite]
@@ -0,0 +1,16 @@
1
+ import type { generateParentsMap } from "./generateParentsMap.js"
2
+
3
+ import type { AnyToken, ArrayNode, ConditionNode, ExpressionNode, GroupNode,ParentTypes, VariableNode } from "../types/ast.js"
4
+ /** See {@link generateParentsMap} */
5
+ export function getParent<
6
+ T extends
7
+ | ExpressionNode
8
+ | ConditionNode
9
+ | GroupNode
10
+ | VariableNode
11
+ | ArrayNode
12
+ | AnyToken
13
+ | undefined,
14
+ >(node: T, map: ReturnType<typeof generateParentsMap>): ParentTypes<T> | undefined {
15
+ return map.get(node as any) as ParentTypes<T>
16
+ }
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Mostly for internal use by @see autosuggest.
2
+ * Mostly for internal use by {@link autosuggest}.
3
3
  *
4
4
  * Returns all error tokens immediately before/after cursor (since there might be multiple error tokens one after the other).
5
5
  *
6
- * The errors are sorted by closeness to the given cursor (inside @see CursorInfo), with quote errors having priority, then paren errors, then any other errors. They can be sorted by closeness because although two errors might follow each other, their positions might be different because of whitespace, but they can still be fixed from any cursor position between their ends.
6
+ * The errors are sorted by closeness to the given cursor (inside {@link CursorInfo}), with quote errors having priority, then paren errors, then any other errors. They can be sorted by closeness because although two errors might follow each other, their positions might be different because of whitespace, but they can still be fixed from any cursor position between their ends.
7
7
  *
8
8
  * For example:
9
9
  * ```
@@ -19,8 +19,7 @@
19
19
  * ```
20
20
  */
21
21
 
22
- import { ErrorToken } from "../ast/classes/ErrorToken.js"
23
- import { type AnyToken, TOKEN_TYPE } from "../types/ast.js"
22
+ import { type AnyToken,type ErrorToken,TOKEN_TYPE } from "../types/ast.js"
24
23
  import type { CursorInfo } from "../types/autocomplete.js"
25
24
 
26
25
 
@@ -31,13 +30,15 @@ export function getSurroundingErrors(tokens: AnyToken[], token: CursorInfo): Err
31
30
  let iNext: number = tokens[i] === token.next ? i : i + 1
32
31
  let iPrev: number = tokens[i] === token.next ? i - 1 : i
33
32
 
34
- const errors = []
35
- while (tokens[iNext] instanceof ErrorToken) {
36
- errors.push(tokens[iNext])
33
+ const errors: ErrorToken[] = []
34
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
35
+ while (tokens[iNext]?.valid === false) {
36
+ errors.push(tokens[iNext] as ErrorToken)
37
37
  iNext++
38
38
  }
39
- while (tokens[iPrev] instanceof ErrorToken) {
40
- errors.push(tokens[iPrev])
39
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
40
+ while (tokens[iPrev]?.valid === false) {
41
+ errors.push(tokens[iPrev] as ErrorToken)
41
42
  iPrev--
42
43
  }
43
44
 
@@ -1,11 +1,15 @@
1
1
  /* Autogenerated Index */
2
2
 
3
3
  export { extractTokens } from "./extractTokens.js"
4
+ export { generateParentsMap } from "./generateParentsMap.js"
4
5
  export { getCursorInfo } from "./getCursorInfo.js"
5
6
  export { getOppositeDelimiter } from "./getOppositeDelimiter.js"
7
+ export { getParent } from "./getParent.js"
6
8
  export { getSurroundingErrors } from "./getSurroundingErrors.js"
7
9
  export { isBracket } from "./isBracket.js"
8
10
  export { isDelimiter } from "./isDelimiter.js"
11
+ export { isNode } from "./isNode.js"
9
12
  export { isParen } from "./isParen.js"
10
13
  export { isQuote } from "./isQuote.js"
14
+ export { isToken } from "./isToken.js"
11
15
  export { prettyAst } from "./prettyAst.js"
@@ -0,0 +1,12 @@
1
+ import type { Node } from "../types/ast.js"
2
+ /**
3
+ * A simple wrapper around checking an object's `isNode` property that casts the object to a {@link Nodes} type for typescript.
4
+ *
5
+ * Does not actually do any checking of the object, and assumes the object was created using one of the `create*` functions.
6
+ *
7
+ * Also note that passing a NormalizedCondition or NormalizedExpression will return false even though they have their own {@link AST_TYPE} since they are not technically nodes (with positions).
8
+ */
9
+ export function isNode(node: any): node is Node {
10
+ return node?.isNode === true
11
+ }
12
+
@@ -0,0 +1,10 @@
1
+ import type { ErrorToken, ValidToken } from "../types/ast.js"
2
+
3
+ /**
4
+ * A simple wrapper around checking an object's `isToken` property that casts the object to a {@link ValidToken} or {@link ErrorToken} for typescript.
5
+ *
6
+ * Does not actually do any checking of the object, and assumes the object was created using one of the `create*` functions.
7
+ */
8
+ export function isToken(token: any): token is ValidToken | ErrorToken {
9
+ return token?.isToken === true
10
+ }
@@ -4,8 +4,9 @@ import { isBlank } from "@alanscodelog/utils/isBlank.js"
4
4
  import { type AddParameters } from "@alanscodelog/utils/types"
5
5
  import { unreachable } from "@alanscodelog/utils/unreachable.js"
6
6
 
7
- import { ArrayNode, ConditionNode, ErrorToken, ExpressionNode, GroupNode, ValidToken, VariableNode } from "../ast/classes/index.js"
8
- import { type AnyToken, type ParserResults, TOKEN_TYPE } from "../types/ast.js"
7
+ import { isToken } from "./isToken.js"
8
+
9
+ import { type AnyToken, type ArrayNode, AST_TYPE,type ConditionNode,type GroupNode, type ParserResults, TOKEN_TYPE, type VariableNode } from "../types/ast.js"
9
10
 
10
11
 
11
12
  type Colors = {
@@ -80,30 +81,32 @@ export function prettyAst(
80
81
  typeof __,
81
82
  typeof extra,
82
83
  ]>
83
- if (ast instanceof ValidToken) {
84
- const value = `${ast.value}`
85
- return `TOKEN ${pos} ${c.values}${quote}${value}${quote}${c.reset}${extra}`
86
- }
87
- if (ast instanceof ErrorToken) {
88
- const value = `[${ast.expected.join(", ")}]`
89
- return `ERROR ${pos} ${c.error}${value}${c.reset}${extra}`
84
+ if (isToken(ast)) {
85
+ if (ast.valid) {
86
+ const value = `${ast.value}`
87
+ return `TOKEN ${pos} ${c.values}${quote}${value}${quote}${c.reset}${extra}`
88
+ }
89
+ if (!ast.valid) {
90
+ const value = `[${ast.expected.join(", ")}]`
91
+ return `ERROR ${pos} ${c.error}${value}${c.reset}${extra}`
92
+ }
90
93
  }
91
- if (ast instanceof ConditionNode) {
94
+ if (ast.type === AST_TYPE.CONDITION) {
92
95
  const header = `${c.info}${ast.operator === undefined}${c.reset}`
93
96
  const not = ast.operator ? prettyAst_(ast.operator, opts, c, ___, `(negation)`) : ""
94
97
  const property = ast.property ? prettyAst_(ast.property, opts, c, ___, `(property)`) : ""
95
98
  const sepL = ast.sep?.left ? prettyAst_(ast.sep.left, opts, c, ___, `(separator)`) : ""
96
99
  const op = ast.propertyOperator ? prettyAst_(ast.propertyOperator, opts, c, ___, `(property operator)`) : ""
97
100
  const sepR = ast.sep?.right ? prettyAst_(ast.sep.right, opts, c, ___, `(separator)`) : ""
98
- const isRegex = ast.value instanceof VariableNode && ast.value.quote?.left.type === TOKEN_TYPE.REGEX
99
- const isArray = ast.value instanceof ArrayNode
101
+ const isRegex = ast.value.type === AST_TYPE.VARIABLE && ast.value.quote?.left.type === TOKEN_TYPE.REGEX
102
+ const isArray = ast.value.type === AST_TYPE.ARRAY
100
103
  const variable = prettyAst_(ast.value, opts, c, __L, `(${property ? "value" : "variable/alone"}${isRegex ? " - regex" : isArray ? "- array" : ""})`)
101
104
  return [
102
105
  `CONDITION ${pos} ${header}${extra}`,
103
106
  ...toRows([not, property, sepL, op, sepR, variable], opts),
104
107
  ].join(`\n${__}`)
105
108
  }
106
- if (ast instanceof VariableNode) {
109
+ if (ast.type === AST_TYPE.VARIABLE) {
107
110
  const prefix = ast.prefix ? prettyAst_(ast.prefix, opts, c, ___, `(value prefix)`) : ""
108
111
  const left = ast.quote?.left ? prettyAst_(ast.quote.left, opts, c, ___, "") : ""
109
112
  const value = prettyAst_(ast.value, opts, c, !ast.quote ? __L : !ast.quote?.right ? __L : ___, "")
@@ -115,7 +118,7 @@ export function prettyAst(
115
118
  ...toRows([prefix, left, value, right, flags], opts),
116
119
  ].join(`\n${__}`)
117
120
  }
118
- if (ast instanceof GroupNode) {
121
+ if (ast.type === AST_TYPE.GROUP) {
119
122
  const header = `${c.info}${ast.prefix === undefined || (ast.prefix as ConditionNode).operator === undefined}${c.reset}`
120
123
  const prefix = ast.prefix ? prettyAst_(ast.prefix, opts, c, ___, `(group prefix)`) : ""
121
124
  const expression = prettyAst_(ast.expression, opts, c, __L, "")
@@ -124,7 +127,7 @@ export function prettyAst(
124
127
  ...toRows([prefix, expression], opts),
125
128
  ].join(`\n${__}`)
126
129
  }
127
- if (ast instanceof ArrayNode) {
130
+ if (ast.type === AST_TYPE.ARRAY) {
128
131
  const bracketL = ast.bracket.left ? prettyAst_(ast.bracket.left, opts, c, ast.values.length === 0 && !ast.bracket.right ? __L : ___, "") : ""
129
132
  const values = ast.values.length > 0
130
133
  ? ast.values.map((node, i) =>
@@ -137,12 +140,12 @@ export function prettyAst(
137
140
  ...toRows([bracketL, ...values, bracketR], opts),
138
141
  ].join(`\n${__}`)
139
142
  }
140
- if (ast instanceof ExpressionNode) {
143
+ if (ast.type === AST_TYPE.EXPRESSION) {
141
144
  const left = prettyAst_(ast.left, opts, c, ___, "")
142
145
  const operator = prettyAst_(ast.operator, opts, c, ___, `(boolean operator)`)
143
146
  const right = prettyAst_(ast.right, opts, c, __L, "")
144
147
 
145
- const header = ast.operator instanceof ErrorToken
148
+ const header = !ast.operator.valid
146
149
  ? `${c.info}[${ast.operator.expected.join(",")}]${c.reset}`
147
150
  : `${c.info}"${ast.operator.value}"${c.reset}`
148
151
  return [
@@ -1,18 +0,0 @@
1
- import type { ConditionNode } from "./ConditionNode.js";
2
- import { Node } from "./Node.js";
3
- import type { VariableNode } from "./VariableNode.js";
4
- import { AST_TYPE, type NodeDelimiters, type TOKEN_TYPE } from "../../types/ast.js";
5
- export declare class ArrayNode<TValid extends boolean = boolean> extends Node<AST_TYPE.ARRAY> {
6
- #private;
7
- readonly values: VariableNode[];
8
- readonly bracket: NodeDelimiters<TOKEN_TYPE.BRACKETL, TOKEN_TYPE.BRACKETR>;
9
- get parent(): ConditionNode | undefined;
10
- set parent(value: ConditionNode | undefined);
11
- constructor({ values, bracket, start, end }: {
12
- values: ArrayNode<TValid>["values"];
13
- bracket: ArrayNode<TValid>["bracket"];
14
- start: number;
15
- end: number;
16
- });
17
- }
18
- //# sourceMappingURL=ArrayNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ArrayNode.d.ts","sourceRoot":"","sources":["../../../src/ast/classes/ArrayNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAGnF,qBAAa,SAAS,CACrB,MAAM,SAAS,OAAO,GAAG,OAAO,CAC/B,SAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;;IAC7B,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,CAAA;IAE/B,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;IAM1E,IAAI,MAAM,IAAI,aAAa,GAAG,SAAS,CAEtC;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,EAI1C;gBAEW,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAC5C,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAA;QACnC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAA;QACrC,KAAK,EAAE,MAAM,CAAA;QACb,GAAG,EAAE,MAAM,CAAA;KACX;CAWD"}
@@ -1,55 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- var __accessCheck = (obj, member, msg) => {
8
- if (!member.has(obj))
9
- throw TypeError("Cannot " + msg);
10
- };
11
- var __privateGet = (obj, member, getter) => {
12
- __accessCheck(obj, member, "read from private field");
13
- return getter ? getter.call(obj) : member.get(obj);
14
- };
15
- var __privateAdd = (obj, member, value) => {
16
- if (member.has(obj))
17
- throw TypeError("Cannot add the same private member more than once");
18
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
19
- };
20
- var __privateSet = (obj, member, value, setter) => {
21
- __accessCheck(obj, member, "write to private field");
22
- setter ? setter.call(obj, value) : member.set(obj, value);
23
- return value;
24
- };
25
- var _parent, _setParent;
26
- import { Node } from "./Node.js";
27
- import { ValidToken } from "./ValidToken.js";
28
- import { AST_TYPE } from "../../types/ast.js";
29
- class ArrayNode extends Node {
30
- constructor({ values, bracket, start, end }) {
31
- super(AST_TYPE.ARRAY, start, end);
32
- __publicField(this, "values");
33
- __publicField(this, "bracket");
34
- __privateAdd(this, _parent, void 0);
35
- __privateAdd(this, _setParent, false);
36
- this.values = values;
37
- this.bracket = bracket;
38
- this.valid = this.values.every((val) => val.valid) && this.bracket.left instanceof ValidToken && this.bracket.right instanceof ValidToken;
39
- }
40
- get parent() {
41
- return __privateGet(this, _parent);
42
- }
43
- set parent(value) {
44
- if (__privateGet(this, _setParent)) {
45
- throw new Error("parent property is readonly");
46
- }
47
- __privateSet(this, _parent, value);
48
- __privateSet(this, _setParent, true);
49
- }
50
- }
51
- _parent = new WeakMap();
52
- _setParent = new WeakMap();
53
- export {
54
- ArrayNode
55
- };
@@ -1,13 +0,0 @@
1
- export declare class Condition<TOp extends string = string, TValue = any> {
2
- readonly value: TValue;
3
- readonly operator?: TOp;
4
- readonly property: string[];
5
- readonly negate: boolean;
6
- constructor({ property, operator, value, negate }: {
7
- property: Condition<TOp, TValue>["property"];
8
- operator: Condition<TOp, TValue>["operator"];
9
- value: Condition<TOp, TValue>["value"];
10
- negate: Condition<TOp, TValue>["negate"];
11
- });
12
- }
13
- //# sourceMappingURL=Condition.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Condition.d.ts","sourceRoot":"","sources":["../../../src/ast/classes/Condition.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,GAAG;IAC/D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IAEtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;IAEvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAE3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;gBAEZ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAClD,QAAQ,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;QAC5C,QAAQ,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;QAC5C,KAAK,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,CAAA;QACtC,MAAM,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAA;KACxC;CAMD"}
@@ -1,21 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- class Condition {
8
- constructor({ property, operator, value, negate }) {
9
- __publicField(this, "value");
10
- __publicField(this, "operator");
11
- __publicField(this, "property");
12
- __publicField(this, "negate");
13
- this.value = value;
14
- this.operator = operator;
15
- this.property = property;
16
- this.negate = negate;
17
- }
18
- }
19
- export {
20
- Condition
21
- };
@@ -1,73 +0,0 @@
1
- import type { ArrayNode } from "./ArrayNode.js";
2
- import type { ErrorToken } from "./ErrorToken.js";
3
- import type { ExpressionNode } from "./ExpressionNode.js";
4
- import type { GroupNode } from "./GroupNode.js";
5
- import { Node } from "./Node.js";
6
- import { ValidToken } from "./ValidToken.js";
7
- import { VariableNode } from "./VariableNode.js";
8
- import { type AnyToken, AST_TYPE, type TOKEN_TYPE } from "../../types/ast.js";
9
- /**
10
- * A condition is composed of a `variable`, @see Variable , and, if it's negated, a "not" `operator` token, @see ValidToken .
11
- *
12
- * The `value` property refers to the boolean value of the condition (not to the string value of the variable). See the `operator` property.
13
- */
14
- export declare class ConditionNode<TValid extends boolean = boolean, TOperator extends ValidToken<TOKEN_TYPE.NOT> | undefined = ValidToken<TOKEN_TYPE.NOT> | undefined> extends Node<AST_TYPE.CONDITION> {
15
- #private;
16
- /**
17
- * Contains a value node which could be a variable, an array node (if enabled), or a group.
18
- *
19
- * Might be an error in cases like:
20
- * - just passing a negation operator
21
- * - 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.
22
- */
23
- readonly value: VariableNode<TValid> | ArrayNode<TValid> | GroupNode<TValid> | (TValid extends false ? ErrorToken<TOKEN_TYPE.VALUE> : never);
24
- /**
25
- * If the condition was negated, contains the "not" token, @see ValidToken , the condition was negated with.
26
- */
27
- readonly operator?: ValidToken<TOKEN_TYPE.NOT>;
28
- /**
29
- * 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).
30
- *
31
- * While the property is a variable and can be a quoted variable, it cannot be a prefixed variable string.
32
- *
33
- * See the corresponding @see ParserOptions for more details.
34
- */
35
- readonly property?: VariableNode | (TValid extends false ? ErrorToken<TOKEN_TYPE.VALUE> : never);
36
- /**
37
- * If condition property operators are used, this will contain the operator.
38
- *
39
- * If a "short" form was used, this will contain an `OP_CUSTOM` type token, and the condition's `sep` will always be undefined.
40
- *
41
- * 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.
42
- *
43
- * See the corresponding @see ParserOptions for more details.
44
- */
45
- readonly propertyOperator?: AnyToken<TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.VALUE>;
46
- /**
47
- * If "long/expanded" form condition property operators are used, this will contain the separators, otherwise it is undefined.
48
- *
49
- * 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.
50
- *
51
- * 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`.
52
- *
53
- * 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).
54
- *
55
- * See the corresponding @see ParserOptions for more details.
56
- */
57
- readonly sep?: {
58
- left?: AnyToken<TOKEN_TYPE.OP_EXPANDED_SEP>;
59
- right?: AnyToken<TOKEN_TYPE.OP_EXPANDED_SEP>;
60
- };
61
- get parent(): GroupNode | ExpressionNode | undefined;
62
- set parent(value: GroupNode | ExpressionNode | undefined);
63
- constructor({ property, propertyOperator, sep, value, start, end, operator }: {
64
- operator?: TOperator;
65
- property?: ConditionNode<TValid>["property"];
66
- propertyOperator?: ConditionNode<TValid>["propertyOperator"];
67
- sep?: ConditionNode<TValid>["sep"];
68
- value: ConditionNode<TValid>["value"];
69
- start: number;
70
- end: number;
71
- });
72
- }
73
- //# sourceMappingURL=ConditionNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConditionNode.d.ts","sourceRoot":"","sources":["../../../src/ast/classes/ConditionNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,EAAE,KAAK,QAAQ,EAAE,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAG7E;;;;GAIG;AACH,qBAAa,aAAa,CACzB,MAAM,SAAS,OAAO,GAAG,OAAO,EAChC,SAAS,SACR,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,SAAS,GACtC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,SAAS,CACtC,SAAQ,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EACZ,YAAY,CAAC,MAAM,CAAC,GACpB,SAAS,CAAC,MAAM,CAAC,GACjB,SAAS,CAAC,MAAM,CAAC,GACjB,CAAC,MAAM,SAAS,KAAK,GAAG,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAA;IAE/D;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IAE9C;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,CAAC,MAAM,SAAS,KAAK,GAAG,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAA;IAEhG;;;;;;;;OAQG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;IAE7E;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE;QACd,IAAI,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;QAC3C,KAAK,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;KAC5C,CAAA;IAMD,IAAI,MAAM,IAAI,SAAS,GACvB,cAAc,GACd,SAAS,CAER;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,GAC3B,cAAc,GACd,SAAS,EAKR;gBAEW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;QAC7E,QAAQ,CAAC,EAAE,SAAS,CAAA;QACpB,QAAQ,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAA;QAC5C,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAA;QAC5D,GAAG,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAA;QAClC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAA;QACrC,KAAK,EAAE,MAAM,CAAA;QACb,GAAG,EAAE,MAAM,CAAA;KACX;CAoCD"}
@@ -1,101 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- var __accessCheck = (obj, member, msg) => {
8
- if (!member.has(obj))
9
- throw TypeError("Cannot " + msg);
10
- };
11
- var __privateGet = (obj, member, getter) => {
12
- __accessCheck(obj, member, "read from private field");
13
- return getter ? getter.call(obj) : member.get(obj);
14
- };
15
- var __privateAdd = (obj, member, value) => {
16
- if (member.has(obj))
17
- throw TypeError("Cannot add the same private member more than once");
18
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
19
- };
20
- var __privateSet = (obj, member, value, setter) => {
21
- __accessCheck(obj, member, "write to private field");
22
- setter ? setter.call(obj, value) : member.set(obj, value);
23
- return value;
24
- };
25
- var _parent, _setParent;
26
- import { Node } from "./Node.js";
27
- import { ValidToken } from "./ValidToken.js";
28
- import { VariableNode } from "./VariableNode.js";
29
- import { AST_TYPE } from "../../types/ast.js";
30
- class ConditionNode extends Node {
31
- constructor({ property, propertyOperator, sep, value, start, end, operator }) {
32
- var _a, _b;
33
- super(AST_TYPE.CONDITION, start, end);
34
- /**
35
- * Contains a value node which could be a variable, an array node (if enabled), or a group.
36
- *
37
- * Might be an error in cases like:
38
- * - just passing a negation operator
39
- * - 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.
40
- */
41
- __publicField(this, "value");
42
- /**
43
- * If the condition was negated, contains the "not" token, @see ValidToken , the condition was negated with.
44
- */
45
- __publicField(this, "operator");
46
- /**
47
- * 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).
48
- *
49
- * While the property is a variable and can be a quoted variable, it cannot be a prefixed variable string.
50
- *
51
- * See the corresponding @see ParserOptions for more details.
52
- */
53
- __publicField(this, "property");
54
- /**
55
- * If condition property operators are used, this will contain the operator.
56
- *
57
- * If a "short" form was used, this will contain an `OP_CUSTOM` type token, and the condition's `sep` will always be undefined.
58
- *
59
- * 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.
60
- *
61
- * See the corresponding @see ParserOptions for more details.
62
- */
63
- __publicField(this, "propertyOperator");
64
- /**
65
- * If "long/expanded" form condition property operators are used, this will contain the separators, otherwise it is undefined.
66
- *
67
- * 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.
68
- *
69
- * 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`.
70
- *
71
- * 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).
72
- *
73
- * See the corresponding @see ParserOptions for more details.
74
- */
75
- __publicField(this, "sep");
76
- __privateAdd(this, _parent, void 0);
77
- __privateAdd(this, _setParent, false);
78
- this.value = value;
79
- this.operator = operator;
80
- this.property = property;
81
- this.propertyOperator = propertyOperator;
82
- this.sep = sep;
83
- this.operator = operator;
84
- this.valid = (this.operator === void 0 || this.operator instanceof ValidToken) && this.value instanceof Node && this.value.valid && (this.property === void 0 && this.propertyOperator === void 0 && this.sep === void 0 || this.property instanceof VariableNode && (this.propertyOperator instanceof ValidToken || ((_a = this.sep) == null ? void 0 : _a.left) instanceof ValidToken && (this.sep.right === void 0 || ((_b = this.sep) == null ? void 0 : _b.right) instanceof ValidToken)));
85
- }
86
- get parent() {
87
- return __privateGet(this, _parent);
88
- }
89
- set parent(value) {
90
- if (__privateGet(this, _setParent)) {
91
- throw new Error("parent property is readonly");
92
- }
93
- __privateSet(this, _parent, value);
94
- __privateSet(this, _setParent, true);
95
- }
96
- }
97
- _parent = new WeakMap();
98
- _setParent = new WeakMap();
99
- export {
100
- ConditionNode
101
- };
@@ -1,27 +0,0 @@
1
- import type { ConditionNode } from "./ConditionNode.js";
2
- import type { ExpressionNode } from "./ExpressionNode.js";
3
- import type { GroupNode } from "./GroupNode.js";
4
- import { Token } from "./Token.js";
5
- import type { VariableNode } from "./VariableNode.js";
6
- import type { TOKEN_TYPE } from "../../types/ast.js";
7
- /**
8
- * The class for invalid recovery tokens.
9
- *
10
- * Unlike valid tokens, error tokens:
11
- *
12
- * - Have no value.
13
- * - Contain an extra property, `expected` with an array of tokens *that would have fixed the issue* (NOT every possible token that could be there).
14
- * - The start end positions will always be equal. An invalid token has no length.
15
- */
16
- export declare class ErrorToken<TExpected extends TOKEN_TYPE = TOKEN_TYPE> extends Token<false, never, never, TExpected[]> {
17
- #private;
18
- readonly expected: TExpected[];
19
- get parent(): VariableNode | GroupNode | ExpressionNode | ConditionNode;
20
- set parent(value: VariableNode | GroupNode | ExpressionNode | ConditionNode);
21
- constructor({ expected, start, end }: {
22
- expected: TExpected[];
23
- start: number;
24
- end: number;
25
- });
26
- }
27
- //# sourceMappingURL=ErrorToken.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ErrorToken.d.ts","sourceRoot":"","sources":["../../../src/ast/classes/ErrorToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;;;;;;;GAQG;AACH,qBAAa,UAAU,CACtB,SAAS,SAAS,UAAU,GAAG,UAAU,CACxC,SAAQ,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;;IAChD,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAA;IAI9B,IAAI,MAAM,IAAI,YAAY,GAC1B,SAAS,GACT,cAAc,GACd,aAAa,CAEZ;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,YAAY,GAC9B,SAAS,GACT,cAAc,GACd,aAAa,EAIZ;gBAEW,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrC,QAAQ,EAAE,SAAS,EAAE,CAAA;QACrB,KAAK,EAAE,MAAM,CAAA;QACb,GAAG,EAAE,MAAM,CAAA;KACX;CAID"}