@witchcraft/expressit 0.0.2

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 (307) hide show
  1. package/README.md +86 -0
  2. package/dist/ast/builders/array.d.ts +8 -0
  3. package/dist/ast/builders/array.d.ts.map +1 -0
  4. package/dist/ast/builders/array.js +31 -0
  5. package/dist/ast/builders/condition.d.ts +20 -0
  6. package/dist/ast/builders/condition.d.ts.map +1 -0
  7. package/dist/ast/builders/condition.js +28 -0
  8. package/dist/ast/builders/delim.d.ts +11 -0
  9. package/dist/ast/builders/delim.d.ts.map +1 -0
  10. package/dist/ast/builders/delim.js +20 -0
  11. package/dist/ast/builders/error.d.ts +9 -0
  12. package/dist/ast/builders/error.d.ts.map +1 -0
  13. package/dist/ast/builders/error.js +16 -0
  14. package/dist/ast/builders/expression.d.ts +12 -0
  15. package/dist/ast/builders/expression.d.ts.map +1 -0
  16. package/dist/ast/builders/expression.js +31 -0
  17. package/dist/ast/builders/group.d.ts +20 -0
  18. package/dist/ast/builders/group.d.ts.map +1 -0
  19. package/dist/ast/builders/group.js +47 -0
  20. package/dist/ast/builders/index.d.ts +12 -0
  21. package/dist/ast/builders/index.d.ts.map +1 -0
  22. package/dist/ast/builders/index.js +24 -0
  23. package/dist/ast/builders/isFullPos.d.ts +6 -0
  24. package/dist/ast/builders/isFullPos.d.ts.map +1 -0
  25. package/dist/ast/builders/isFullPos.js +6 -0
  26. package/dist/ast/builders/pos.d.ts +21 -0
  27. package/dist/ast/builders/pos.d.ts.map +1 -0
  28. package/dist/ast/builders/pos.js +28 -0
  29. package/dist/ast/builders/token.d.ts +12 -0
  30. package/dist/ast/builders/token.d.ts.map +1 -0
  31. package/dist/ast/builders/token.js +26 -0
  32. package/dist/ast/builders/type.d.ts +6 -0
  33. package/dist/ast/builders/type.d.ts.map +1 -0
  34. package/dist/ast/builders/type.js +37 -0
  35. package/dist/ast/builders/variable.d.ts +17 -0
  36. package/dist/ast/builders/variable.d.ts.map +1 -0
  37. package/dist/ast/builders/variable.js +62 -0
  38. package/dist/ast/classes/ArrayNode.d.ts +18 -0
  39. package/dist/ast/classes/ArrayNode.d.ts.map +1 -0
  40. package/dist/ast/classes/ArrayNode.js +55 -0
  41. package/dist/ast/classes/Condition.d.ts +13 -0
  42. package/dist/ast/classes/Condition.d.ts.map +1 -0
  43. package/dist/ast/classes/Condition.js +21 -0
  44. package/dist/ast/classes/ConditionNode.d.ts +73 -0
  45. package/dist/ast/classes/ConditionNode.d.ts.map +1 -0
  46. package/dist/ast/classes/ConditionNode.js +101 -0
  47. package/dist/ast/classes/ErrorToken.d.ts +27 -0
  48. package/dist/ast/classes/ErrorToken.d.ts.map +1 -0
  49. package/dist/ast/classes/ErrorToken.js +47 -0
  50. package/dist/ast/classes/Expression.d.ts +13 -0
  51. package/dist/ast/classes/Expression.d.ts.map +1 -0
  52. package/dist/ast/classes/Expression.js +19 -0
  53. package/dist/ast/classes/ExpressionNode.d.ts +21 -0
  54. package/dist/ast/classes/ExpressionNode.d.ts.map +1 -0
  55. package/dist/ast/classes/ExpressionNode.js +57 -0
  56. package/dist/ast/classes/GroupNode.d.ts +64 -0
  57. package/dist/ast/classes/GroupNode.d.ts.map +1 -0
  58. package/dist/ast/classes/GroupNode.js +69 -0
  59. package/dist/ast/classes/Node.d.ts +22 -0
  60. package/dist/ast/classes/Node.d.ts.map +1 -0
  61. package/dist/ast/classes/Node.js +28 -0
  62. package/dist/ast/classes/Token.d.ts +27 -0
  63. package/dist/ast/classes/Token.d.ts.map +1 -0
  64. package/dist/ast/classes/Token.js +28 -0
  65. package/dist/ast/classes/ValidToken.d.ts +26 -0
  66. package/dist/ast/classes/ValidToken.d.ts.map +1 -0
  67. package/dist/ast/classes/ValidToken.js +49 -0
  68. package/dist/ast/classes/VariableNode.d.ts +33 -0
  69. package/dist/ast/classes/VariableNode.d.ts.map +1 -0
  70. package/dist/ast/classes/VariableNode.js +58 -0
  71. package/dist/ast/classes/index.d.ts +12 -0
  72. package/dist/ast/classes/index.d.ts.map +1 -0
  73. package/dist/ast/classes/index.js +24 -0
  74. package/dist/ast/handlers.d.ts +42 -0
  75. package/dist/ast/handlers.d.ts.map +1 -0
  76. package/dist/ast/handlers.js +150 -0
  77. package/dist/ast/index.d.ts +4 -0
  78. package/dist/ast/index.d.ts.map +1 -0
  79. package/dist/ast/index.js +8 -0
  80. package/dist/examples/advancedValueComparer.d.ts +3 -0
  81. package/dist/examples/advancedValueComparer.d.ts.map +1 -0
  82. package/dist/examples/advancedValueComparer.js +28 -0
  83. package/dist/examples/shortcutContextParser.d.ts +22 -0
  84. package/dist/examples/shortcutContextParser.d.ts.map +1 -0
  85. package/dist/examples/shortcutContextParser.js +126 -0
  86. package/dist/global.d.js +1 -0
  87. package/dist/grammar/ParserBase.d.ts +51 -0
  88. package/dist/grammar/ParserBase.d.ts.map +1 -0
  89. package/dist/grammar/ParserBase.js +516 -0
  90. package/dist/grammar/createTokens.d.ts +56 -0
  91. package/dist/grammar/createTokens.d.ts.map +1 -0
  92. package/dist/grammar/createTokens.js +843 -0
  93. package/dist/grammar/index.d.ts +3 -0
  94. package/dist/grammar/index.d.ts.map +1 -0
  95. package/dist/grammar/index.js +6 -0
  96. package/dist/helpers/errors.d.ts +9 -0
  97. package/dist/helpers/errors.d.ts.map +1 -0
  98. package/dist/helpers/errors.js +41 -0
  99. package/dist/helpers/general/applyBoolean.d.ts +3 -0
  100. package/dist/helpers/general/applyBoolean.d.ts.map +1 -0
  101. package/dist/helpers/general/applyBoolean.js +17 -0
  102. package/dist/helpers/general/applyPrefix.d.ts +4 -0
  103. package/dist/helpers/general/applyPrefix.d.ts.map +1 -0
  104. package/dist/helpers/general/applyPrefix.js +9 -0
  105. package/dist/helpers/general/defaultConditionNormalizer.d.ts +3 -0
  106. package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +1 -0
  107. package/dist/helpers/general/defaultConditionNormalizer.js +6 -0
  108. package/dist/helpers/general/defaultKeyParser.d.ts +3 -0
  109. package/dist/helpers/general/defaultKeyParser.d.ts.map +1 -0
  110. package/dist/helpers/general/defaultKeyParser.js +8 -0
  111. package/dist/helpers/general/defaultPrefixApplier.d.ts +3 -0
  112. package/dist/helpers/general/defaultPrefixApplier.d.ts.map +1 -0
  113. package/dist/helpers/general/defaultPrefixApplier.js +6 -0
  114. package/dist/helpers/general/defaultValueComparer.d.ts +3 -0
  115. package/dist/helpers/general/defaultValueComparer.d.ts.map +1 -0
  116. package/dist/helpers/general/defaultValueComparer.js +6 -0
  117. package/dist/helpers/general/index.d.ts +7 -0
  118. package/dist/helpers/general/index.d.ts.map +1 -0
  119. package/dist/helpers/general/index.js +14 -0
  120. package/dist/helpers/index.d.ts +4 -0
  121. package/dist/helpers/index.d.ts.map +1 -0
  122. package/dist/helpers/index.js +8 -0
  123. package/dist/helpers/parser/assignParents.d.ts +4 -0
  124. package/dist/helpers/parser/assignParents.d.ts.map +1 -0
  125. package/dist/helpers/parser/assignParents.js +71 -0
  126. package/dist/helpers/parser/checkParserOpts.d.ts +3 -0
  127. package/dist/helpers/parser/checkParserOpts.d.ts.map +1 -0
  128. package/dist/helpers/parser/checkParserOpts.js +126 -0
  129. package/dist/helpers/parser/extractPosition.d.ts +9 -0
  130. package/dist/helpers/parser/extractPosition.d.ts.map +1 -0
  131. package/dist/helpers/parser/extractPosition.js +9 -0
  132. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +5 -0
  133. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +1 -0
  134. package/dist/helpers/parser/getUnclosedRightParenCount.js +20 -0
  135. package/dist/helpers/parser/index.d.ts +9 -0
  136. package/dist/helpers/parser/index.d.ts.map +1 -0
  137. package/dist/helpers/parser/index.js +18 -0
  138. package/dist/helpers/parser/parseParserOptions.d.ts +4 -0
  139. package/dist/helpers/parser/parseParserOptions.d.ts.map +1 -0
  140. package/dist/helpers/parser/parseParserOptions.js +45 -0
  141. package/dist/helpers/parser/seal.d.ts +8 -0
  142. package/dist/helpers/parser/seal.d.ts.map +1 -0
  143. package/dist/helpers/parser/seal.js +10 -0
  144. package/dist/helpers/parser/setParent.d.ts +6 -0
  145. package/dist/helpers/parser/setParent.d.ts.map +1 -0
  146. package/dist/helpers/parser/setParent.js +4 -0
  147. package/dist/helpers/parser/unescape.d.ts +3 -0
  148. package/dist/helpers/parser/unescape.d.ts.map +1 -0
  149. package/dist/helpers/parser/unescape.js +6 -0
  150. package/dist/index.d.ts +6 -0
  151. package/dist/index.d.ts.map +1 -0
  152. package/dist/index.js +17 -0
  153. package/dist/methods/autocomplete.d.ts +18 -0
  154. package/dist/methods/autocomplete.d.ts.map +1 -0
  155. package/dist/methods/autocomplete.js +109 -0
  156. package/dist/methods/autoreplace.d.ts +13 -0
  157. package/dist/methods/autoreplace.d.ts.map +1 -0
  158. package/dist/methods/autoreplace.js +36 -0
  159. package/dist/methods/autosuggest.d.ts +28 -0
  160. package/dist/methods/autosuggest.d.ts.map +1 -0
  161. package/dist/methods/autosuggest.js +371 -0
  162. package/dist/methods/evaluate.d.ts +11 -0
  163. package/dist/methods/evaluate.d.ts.map +1 -0
  164. package/dist/methods/evaluate.js +30 -0
  165. package/dist/methods/getBestIndex.d.ts +19 -0
  166. package/dist/methods/getBestIndex.d.ts.map +1 -0
  167. package/dist/methods/getBestIndex.js +53 -0
  168. package/dist/methods/getIndexes.d.ts +17 -0
  169. package/dist/methods/getIndexes.d.ts.map +1 -0
  170. package/dist/methods/getIndexes.js +97 -0
  171. package/dist/methods/index.d.ts +9 -0
  172. package/dist/methods/index.d.ts.map +1 -0
  173. package/dist/methods/index.js +18 -0
  174. package/dist/methods/normalize.d.ts +12 -0
  175. package/dist/methods/normalize.d.ts.map +1 -0
  176. package/dist/methods/normalize.js +99 -0
  177. package/dist/methods/validate.d.ts +11 -0
  178. package/dist/methods/validate.d.ts.map +1 -0
  179. package/dist/methods/validate.js +111 -0
  180. package/dist/package.js +7 -0
  181. package/dist/package.json.js +193 -0
  182. package/dist/parser.d.ts +58 -0
  183. package/dist/parser.d.ts.map +1 -0
  184. package/dist/parser.js +136 -0
  185. package/dist/types/ast.d.ts +70 -0
  186. package/dist/types/ast.d.ts.map +1 -0
  187. package/dist/types/ast.js +29 -0
  188. package/dist/types/autocomplete.d.ts +143 -0
  189. package/dist/types/autocomplete.d.ts.map +1 -0
  190. package/dist/types/autocomplete.js +24 -0
  191. package/dist/types/errors.d.ts +34 -0
  192. package/dist/types/errors.d.ts.map +1 -0
  193. package/dist/types/errors.js +10 -0
  194. package/dist/types/index.d.ts +5 -0
  195. package/dist/types/index.d.ts.map +1 -0
  196. package/dist/types/index.js +9 -0
  197. package/dist/types/parser.d.ts +451 -0
  198. package/dist/types/parser.d.ts.map +1 -0
  199. package/dist/types/parser.js +1 -0
  200. package/dist/utils/extractTokens.d.ts +8 -0
  201. package/dist/utils/extractTokens.d.ts.map +1 -0
  202. package/dist/utils/extractTokens.js +50 -0
  203. package/dist/utils/getCursorInfo.d.ts +7 -0
  204. package/dist/utils/getCursorInfo.d.ts.map +1 -0
  205. package/dist/utils/getCursorInfo.js +86 -0
  206. package/dist/utils/getOppositeDelimiter.d.ts +6 -0
  207. package/dist/utils/getOppositeDelimiter.d.ts.map +1 -0
  208. package/dist/utils/getOppositeDelimiter.js +35 -0
  209. package/dist/utils/getSurroundingErrors.d.ts +25 -0
  210. package/dist/utils/getSurroundingErrors.d.ts.map +1 -0
  211. package/dist/utils/getSurroundingErrors.js +37 -0
  212. package/dist/utils/index.d.ts +10 -0
  213. package/dist/utils/index.d.ts.map +1 -0
  214. package/dist/utils/index.js +20 -0
  215. package/dist/utils/isBracket.d.ts +3 -0
  216. package/dist/utils/isBracket.d.ts.map +1 -0
  217. package/dist/utils/isBracket.js +7 -0
  218. package/dist/utils/isDelimiter.d.ts +6 -0
  219. package/dist/utils/isDelimiter.d.ts.map +1 -0
  220. package/dist/utils/isDelimiter.js +17 -0
  221. package/dist/utils/isParen.d.ts +3 -0
  222. package/dist/utils/isParen.d.ts.map +1 -0
  223. package/dist/utils/isParen.js +7 -0
  224. package/dist/utils/isQuote.d.ts +4 -0
  225. package/dist/utils/isQuote.d.ts.map +1 -0
  226. package/dist/utils/isQuote.js +7 -0
  227. package/dist/utils/prettyAst.d.ts +35 -0
  228. package/dist/utils/prettyAst.d.ts.map +1 -0
  229. package/dist/utils/prettyAst.js +112 -0
  230. package/package.json +152 -0
  231. package/src/ast/builders/array.ts +45 -0
  232. package/src/ast/builders/condition.ts +56 -0
  233. package/src/ast/builders/delim.ts +39 -0
  234. package/src/ast/builders/error.ts +22 -0
  235. package/src/ast/builders/expression.ts +66 -0
  236. package/src/ast/builders/group.ts +79 -0
  237. package/src/ast/builders/index.ts +13 -0
  238. package/src/ast/builders/isFullPos.ts +10 -0
  239. package/src/ast/builders/pos.ts +57 -0
  240. package/src/ast/builders/token.ts +46 -0
  241. package/src/ast/builders/type.ts +32 -0
  242. package/src/ast/builders/variable.ts +89 -0
  243. package/src/ast/classes/ArrayNode.ts +46 -0
  244. package/src/ast/classes/Condition.ts +22 -0
  245. package/src/ast/classes/ConditionNode.ts +141 -0
  246. package/src/ast/classes/ErrorToken.ts +49 -0
  247. package/src/ast/classes/Expression.ts +26 -0
  248. package/src/ast/classes/ExpressionNode.ts +62 -0
  249. package/src/ast/classes/GroupNode.ts +127 -0
  250. package/src/ast/classes/Node.ts +47 -0
  251. package/src/ast/classes/Token.ts +59 -0
  252. package/src/ast/classes/ValidToken.ts +56 -0
  253. package/src/ast/classes/VariableNode.ts +67 -0
  254. package/src/ast/classes/index.ts +13 -0
  255. package/src/ast/handlers.ts +190 -0
  256. package/src/ast/index.ts +5 -0
  257. package/src/examples/advancedValueComparer.ts +31 -0
  258. package/src/examples/shortcutContextParser.ts +140 -0
  259. package/src/global.d.ts +4 -0
  260. package/src/grammar/ParserBase.ts +715 -0
  261. package/src/grammar/createTokens.ts +512 -0
  262. package/src/grammar/index.ts +4 -0
  263. package/src/helpers/errors.ts +45 -0
  264. package/src/helpers/general/applyBoolean.ts +9 -0
  265. package/src/helpers/general/applyPrefix.ts +7 -0
  266. package/src/helpers/general/defaultConditionNormalizer.ts +9 -0
  267. package/src/helpers/general/defaultKeyParser.ts +8 -0
  268. package/src/helpers/general/defaultPrefixApplier.ts +7 -0
  269. package/src/helpers/general/defaultValueComparer.ts +7 -0
  270. package/src/helpers/general/index.ts +8 -0
  271. package/src/helpers/index.ts +5 -0
  272. package/src/helpers/parser/assignParents.ts +51 -0
  273. package/src/helpers/parser/checkParserOpts.ts +143 -0
  274. package/src/helpers/parser/extractPosition.ts +15 -0
  275. package/src/helpers/parser/getUnclosedRightParenCount.ts +22 -0
  276. package/src/helpers/parser/index.ts +10 -0
  277. package/src/helpers/parser/parseParserOptions.ts +54 -0
  278. package/src/helpers/parser/seal.ts +14 -0
  279. package/src/helpers/parser/setParent.ts +5 -0
  280. package/src/helpers/parser/unescape.ts +4 -0
  281. package/src/index.ts +7 -0
  282. package/src/methods/autocomplete.ts +128 -0
  283. package/src/methods/autoreplace.ts +46 -0
  284. package/src/methods/autosuggest.ts +543 -0
  285. package/src/methods/evaluate.ts +37 -0
  286. package/src/methods/getBestIndex.ts +53 -0
  287. package/src/methods/getIndexes.ts +99 -0
  288. package/src/methods/index.ts +10 -0
  289. package/src/methods/normalize.ts +138 -0
  290. package/src/methods/validate.ts +141 -0
  291. package/src/package.js +11 -0
  292. package/src/parser.ts +183 -0
  293. package/src/types/ast.ts +148 -0
  294. package/src/types/autocomplete.ts +152 -0
  295. package/src/types/errors.ts +40 -0
  296. package/src/types/index.ts +6 -0
  297. package/src/types/parser.ts +479 -0
  298. package/src/utils/extractTokens.ts +67 -0
  299. package/src/utils/getCursorInfo.ts +106 -0
  300. package/src/utils/getOppositeDelimiter.ts +36 -0
  301. package/src/utils/getSurroundingErrors.ts +57 -0
  302. package/src/utils/index.ts +11 -0
  303. package/src/utils/isBracket.ts +6 -0
  304. package/src/utils/isDelimiter.ts +18 -0
  305. package/src/utils/isParen.ts +6 -0
  306. package/src/utils/isQuote.ts +6 -0
  307. package/src/utils/prettyAst.ts +152 -0
@@ -0,0 +1,148 @@
1
+ import type { AnyFunction } from "@alanscodelog/utils"
2
+
3
+ import type { ArrayNode } from "../ast/classes/ArrayNode.js"
4
+ import type { ConditionNode } from "../ast/classes/ConditionNode.js"
5
+ import type { ErrorToken } from "../ast/classes/ErrorToken.js"
6
+ import type { ExpressionNode } from "../ast/classes/ExpressionNode.js"
7
+ import type { GroupNode } from "../ast/classes/GroupNode.js"
8
+ import type { ValidToken } from "../ast/classes/ValidToken.js"
9
+ import type { VariableNode } from "../ast/classes/VariableNode.js"
10
+
11
+
12
+ export type AddParameters<T extends AnyFunction, TExtra extends any[] = [boolean]> = (...args: [...Parameters<T>, ...TExtra]) => ReturnType<T>
13
+
14
+ export enum TOKEN_TYPE {
15
+ VALUE = "VALUE",
16
+ AND = "AND",
17
+ OR = "OR",
18
+ NOT = "NOT",
19
+ BACKTICK = "BACKTICK",
20
+ SINGLEQUOTE = "SINGLEQUOTE",
21
+ DOUBLEQUOTE = "DOUBLEQUOTE",
22
+ PARENL = "PARENL",
23
+ PARENR = "PARENR",
24
+ BRACKETL = "BRACKETL",
25
+ BRACKETR = "BRACKETR",
26
+ OP_EXPANDED_SEP = "OP_EXPANDED",
27
+ OP_CUSTOM = "OP_CUSTOM",
28
+ REGEX = "REGEX",
29
+ }
30
+
31
+ /**
32
+ * @internal
33
+ * Note if the negation operator, `!`, is used as a propertyOperator, this will return the wrong type.
34
+ */
35
+ export type ExtractTokenType<T extends string> =
36
+ T extends "`"
37
+ ? TOKEN_TYPE.BACKTICK
38
+ : T extends `'`
39
+ ? TOKEN_TYPE.SINGLEQUOTE
40
+ : T extends `"`
41
+ ? TOKEN_TYPE.DOUBLEQUOTE
42
+ : T extends `/`
43
+ ? TOKEN_TYPE.REGEX
44
+ : T extends `(`
45
+ ? TOKEN_TYPE.PARENL
46
+ : T extends `)`
47
+ ? TOKEN_TYPE.PARENR
48
+ : T extends `[`
49
+ ? TOKEN_TYPE.BRACKETL
50
+ : T extends `]`
51
+ ? TOKEN_TYPE.BRACKETR
52
+ : T extends `and`
53
+ ? TOKEN_TYPE.AND
54
+ : T extends `&&`
55
+ ? TOKEN_TYPE.AND
56
+ : T extends `&`
57
+ ? TOKEN_TYPE.AND
58
+ : T extends `or`
59
+ ? TOKEN_TYPE.OR
60
+ : T extends `||`
61
+ ? TOKEN_TYPE.OR
62
+ : T extends `|`
63
+ ? TOKEN_TYPE.OR
64
+ : T extends `not`
65
+ ? TOKEN_TYPE.NOT
66
+ : T extends `!`
67
+ ? TOKEN_TYPE.NOT
68
+ : TOKEN_TYPE.VALUE
69
+
70
+ export type TokenParenTypes =
71
+ | TOKEN_TYPE.PARENL
72
+ | TOKEN_TYPE.PARENR
73
+ export type TokenBracketTypes =
74
+ | TOKEN_TYPE.BRACKETL
75
+ | TOKEN_TYPE.BRACKETR
76
+
77
+ export type TokenDelimiterTypes =
78
+ | TokenParenTypes
79
+ | TokenQuoteTypes
80
+ | TokenBracketTypes
81
+ | TOKEN_TYPE.OP_EXPANDED_SEP
82
+
83
+ export type TokenQuoteTypes =
84
+ | TOKEN_TYPE.BACKTICK
85
+ | TOKEN_TYPE.SINGLEQUOTE
86
+ | TOKEN_TYPE.DOUBLEQUOTE
87
+ | TOKEN_TYPE.REGEX
88
+
89
+ export type TokenBooleanTypes =
90
+ | TOKEN_TYPE.AND
91
+ | TOKEN_TYPE.OR
92
+
93
+ export type TokenOperatorTypes =
94
+ | TokenBooleanTypes
95
+ | TOKEN_TYPE.NOT
96
+
97
+ export type TokenPropertyOperatorTypes =
98
+ | TOKEN_TYPE.OP_CUSTOM
99
+ | TOKEN_TYPE.OP_EXPANDED_SEP
100
+
101
+
102
+ // export type EmptyObj = Record<"start"|"end", undefined>
103
+ export type EmptyObj = Record<any, never>
104
+ export type FirstConstructorParam<T extends new (...args: any) => any> = ConstructorParameters<T>["0"]
105
+
106
+ export type Position = {
107
+ start: number
108
+ end: number
109
+ }
110
+
111
+ export enum AST_TYPE {
112
+ EXPRESSION = "EXPRESSION",
113
+ GROUP = "GROUP",
114
+ ARRAY = "ARRAY",
115
+ CONDITION = "CONDITION",
116
+ VARIABLE = "VARIABLE",
117
+ }
118
+
119
+ // #region AST nodes
120
+
121
+ /**
122
+ * For more easily typing tokens that might or might not be valid.
123
+ *
124
+ * Using @see Token does not work well in certain situations and is also more complex because it has so many generics.
125
+ */
126
+ export type AnyToken<
127
+ TType extends TOKEN_TYPE = TOKEN_TYPE,
128
+ > =
129
+ | ValidToken<TType>
130
+ | ErrorToken<TType>
131
+
132
+ export type ParserResults = ExpressionNode | ConditionNode | GroupNode | ErrorToken<TOKEN_TYPE.VALUE>
133
+ /* eslint-disable @typescript-eslint/naming-convention */
134
+
135
+
136
+ export type Nodes = ExpressionNode | ConditionNode | GroupNode | VariableNode | ArrayNode
137
+
138
+ /**
139
+ * Contains any delimiter tokens some AST nodes ( @see GroupNode and @see VariableNode ) can have.
140
+ *
141
+ * These are usually not important for evaluating an expression but are useful for syntax highlighting.
142
+ */
143
+ export type NodeDelimiters<TLEFT extends TOKEN_TYPE, TRIGHT extends TOKEN_TYPE = TLEFT> = {
144
+ left: AnyToken<TLEFT>
145
+ right: AnyToken<TRIGHT>
146
+ /** Only exists if regexes are enabled and this is a regex value. */
147
+ flags?: ValidToken<TOKEN_TYPE.VALUE>
148
+ }
@@ -0,0 +1,152 @@
1
+ import type { AnyToken, Position } from "./ast.js"
2
+
3
+ import type { ValidToken } from "../ast/classes/ValidToken.js"
4
+
5
+
6
+ /**
7
+ * Contains information regarding the tokens around a cursor position. Mostly for internally use by @see autosuggest.
8
+ *
9
+ * Notes:
10
+ *
11
+ * - 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.
12
+ * - 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:
13
+ * ```ts
14
+ * let i = tokens.findIndex(t => t === info.next)
15
+ * while (tokens[i] instanceof ErrorToken) {...}
16
+ * ```
17
+ *
18
+ * Examples:
19
+ *
20
+ * ```js
21
+ * aaaa| bbbb // tokens: ["aaaa", TokenError(operator), "bbbb"]
22
+ * ^
23
+ * {
24
+ * index: 4, // cursor position
25
+ * at: undefined, // it's not inside a token
26
+ * prev: "aaaa",
27
+ * next: TokenError, // operator is missing to the right
28
+ * // closest valid tokens to either side
29
+ * valid: {
30
+ * prev: "aaaa",
31
+ * next: "bbbb",
32
+ * },
33
+ * // whether there is whitespace between the cursor and the next/prev valid tokens or start/end of input
34
+ * whitespace: {
35
+ * prev: false,
36
+ * next: true,
37
+ * }
38
+ * }
39
+ * ```
40
+ * ```js
41
+ * aaaa || bb|bb && cccc
42
+ * ^
43
+ * {
44
+ * index: 10,
45
+ * at: "bbbb", // it's inside a token
46
+ * prev: "||",
47
+ * next: "&&",
48
+ * valid: {
49
+ * prev: "||",
50
+ * next: "&&",
51
+ * },
52
+ * whitespace: {
53
+ * prev: true,
54
+ * next: true,
55
+ * }
56
+ * }
57
+ * ```
58
+ */
59
+ export type CursorInfo = {
60
+ index: number
61
+ /**
62
+ * The token the cursor is inside of. By "inside", we mean the ends of the token are before/after the cursor respectively (e.g. `a|a`, but NOT `|aa` or `aa|`). This token, if defined, is always a valid token, since error tokens have no length.
63
+ *
64
+ * Note though that there are cases where one might be inside a variable but not inside a token because quotes are their own tokens (e.g. `"|var"` or `"var|"`).
65
+ */
66
+ at?: ValidToken
67
+ /** The first token, valid or invalid, that starts at or after the index position. */
68
+ next?: AnyToken
69
+ /** The first token (going backwards), valid or invalid, that ends at or before the index position. */
70
+ prev?: AnyToken
71
+ /** Closest valid tokens. */
72
+ valid: {
73
+ /** Closest prev valid token. */
74
+ next?: ValidToken
75
+ /** Closest next valid token. */
76
+ prev?: ValidToken
77
+ }
78
+ /** Whether there is whitespace between the cursor and the next/prev valid tokens or start/end of the input. */
79
+ whitespace: {
80
+ /** Whether there is whitespace between the cursor and the next valid token or the end of the input. */
81
+ next: boolean
82
+ /** Whether there is whitespace between the cursor and the prev valid token or the start of the input. */
83
+ prev: boolean
84
+ }
85
+ }
86
+
87
+ export enum SUGGESTION_TYPE {
88
+ // can ignore whitespace requirement if replacing with quoted
89
+ VARIABLE = "VARIABLE",
90
+ ARRAY_VALUE = "ARRAY_VALUE",
91
+ VALUE = "VALUE",
92
+ PREFIX = "PREFIX",
93
+ BOOLEAN_WORD_OP = "BOOLEAN_WORD_OP",
94
+ BOOLEAN_SYMBOL_OP = "BOOLEAN_SYMBOL_OP",
95
+ BACKTICK = "BACKTICK",
96
+ DOUBLEQUOTE = "DOUBLEQUOTE",
97
+ SINGLEQUOTE = "SINGLEQUOTE",
98
+ PARENL = "PARENL",
99
+ PARENR = "PARENR",
100
+ PROPERTY = "PROPERTY",
101
+ EXPANDED_PROPERTY_OPERATOR = "EXPANDED_PROPERTY_OPERATOR",
102
+ CUSTOM_PROPERTY_OPERATOR = "CUSTOM_PROPERTY_OPERATOR",
103
+ PROPERTY_SEP = "PROPERTY_SEP",
104
+ BRAKCETR = "BRAKCETR",
105
+ REGEX = "REGEX",
106
+ REGEX_FLAGS = "REGEX_FLAGS",
107
+ /** This is not an oversight, I haven't figured out a fast way to detect left bracket errors. */
108
+ // BRAKCETL = "BRAKCETL",
109
+ }
110
+
111
+ /**
112
+ * A suggestion entry that describes a type of suggestion.
113
+ */
114
+ export type Suggestion = {
115
+ type: SUGGESTION_TYPE
116
+ /** The range the suggestion should replace / be inserted at. */
117
+ range: Position
118
+ /** @see CursorInfo */
119
+ cursorInfo: CursorInfo
120
+ /** Tells us any additional requirements for inserting the suggestion. */
121
+ requires: {
122
+ /**
123
+ * Whether the suggestions requires inserting whitespace before/after to keep the intent of the expression consistent. For example, an unquoted variable needs a space between it and a non-symbol operator.
124
+ *
125
+ * In the case of variables this requirement can be ignored though if you insert a quoted value.
126
+ */
127
+ whitespace: {
128
+ after: boolean
129
+ before: boolean
130
+ }
131
+ /**
132
+ * If prefixableGroups is enabled, a suggestion can be a prefix suggestion and this tells us whether `()` needs to be inserted at the end in the case it does not already exist.
133
+ *
134
+ * For example, a user might choose to insert a prefix in this situation `a && |` and we want the result to be `a && prefix()` because without the `()` the prefix will probably be an invalid variable name on insertion.
135
+ *
136
+ * The opposite happens with an existing prefix where the user might want to replace it. `a && existing|(...)`. We want the result to be `a && replacement(...)` not `a && replacement()(...)`.
137
+ */
138
+ group: boolean
139
+ /** If `prefixableValues` is enabled and a value is prefixed, contains the prefix it was prefixed with. Note that the prefix is included in the range. This way you can choose to suggest/replace just the prefix, just the value or both. */
140
+ prefix: string | false
141
+ }
142
+ /**
143
+ * Whether the suggestion was created because there was an error token there and it would fix it.
144
+ */
145
+ isError: boolean
146
+ }
147
+
148
+
149
+ export type Completion = {
150
+ suggestion: Suggestion
151
+ value: string
152
+ }
@@ -0,0 +1,40 @@
1
+ import type { DeepPartial } from "@alanscodelog/utils"
2
+ import type { ILexingError, IRecognitionException, IToken } from "chevrotain"
3
+
4
+ import type { ParserOptions } from "./parser.js"
5
+
6
+
7
+ export enum ERROR_CODES {
8
+ "PARSER_ERROR" = "PARSER.ERROR",
9
+ "PARSER_POSITION_ERROR" = "PARSER.POSITION",
10
+ "PARSER_CONFLICTING_OPTIONS_ERROR" = "PARSER.OPTIONS.CONFLICTING",
11
+ "PARSER_OPTION_REQUIRED_ERROR" = "PARSER.OPTIONS.CUSTOM_REQUIRED",
12
+ }
13
+ export type ErrorInfo<T extends keyof ErrorInfos> = ErrorInfos[T]
14
+ export type ErrorInfos = {
15
+ [ERROR_CODES.PARSER_ERROR]: {
16
+ input: string
17
+ options: DeepPartial<ParserOptions> | undefined
18
+ // eslint-disable-next-line @typescript-eslint/naming-convention
19
+ "parsed options": ParserOptions
20
+ error: Error
21
+ // eslint-disable-next-line @typescript-eslint/naming-convention
22
+ "lexer errors": ILexingError[]
23
+ // eslint-disable-next-line @typescript-eslint/naming-convention
24
+ "lexed tokens": IToken[]
25
+ // eslint-disable-next-line @typescript-eslint/naming-convention
26
+ "parser errors": IRecognitionException[]
27
+ }
28
+ [ERROR_CODES.PARSER_POSITION_ERROR]: {
29
+ start?: number
30
+ end?: number
31
+ }
32
+ [ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR]: {
33
+ prohibited: string[]
34
+ invalid: string
35
+ }
36
+ [ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR]: {
37
+ options?: (keyof ParserOptions)[]
38
+ requires: keyof ParserOptions
39
+ }
40
+ }
@@ -0,0 +1,6 @@
1
+ /* Autogenerated Index [Types] */
2
+
3
+ export * from "./ast.js"
4
+ export * from "./autocomplete.js"
5
+ export * from "./errors.js"
6
+ export * from "./parser.js"