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