@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 +1 @@
1
- {"version":3,"file":"getCursorInfo.d.ts","sourceRoot":"","sources":["../../src/utils/getCursorInfo.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAG1D;;GAEG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,aAAa,GAAG,QAAQ,EAAE,EAC/B,KAAK,EAAE,MAAM,GACX,UAAU,CAoDZ"}
1
+ {"version":3,"file":"getCursorInfo.d.ts","sourceRoot":"","sources":["../../src/utils/getCursorInfo.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAG1D;;GAEG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,aAAa,GAAG,QAAQ,EAAE,EAC/B,KAAK,EAAE,MAAM,GACX,UAAU,CAoDZ"}
@@ -1,8 +1,6 @@
1
1
  import { isArray } from "@alanscodelog/utils/isArray.js";
2
2
  import { unreachable } from "@alanscodelog/utils/unreachable.js";
3
3
  import { extractTokens } from "./extractTokens.js";
4
- import { ErrorToken } from "../ast/classes/ErrorToken.js";
5
- import { ValidToken } from "../ast/classes/ValidToken.js";
6
4
  function getCursorInfo(input, ast, index) {
7
5
  const tokens = isArray(ast) ? ast : extractTokens(ast);
8
6
  if (input.length < index || index < 0) {
@@ -24,7 +22,7 @@ function getCursorInfo(input, ast, index) {
24
22
  };
25
23
  for (const token of tokens) {
26
24
  if (token.end <= index) {
27
- if (token instanceof ValidToken) {
25
+ if (token.valid) {
28
26
  info.prev = token;
29
27
  info.valid.prev = token;
30
28
  } else if (token.end !== index) {
@@ -32,7 +30,7 @@ function getCursorInfo(input, ast, index) {
32
30
  }
33
31
  }
34
32
  if (token.start < index && token.end > index) {
35
- if (token instanceof ErrorToken) {
33
+ if (!token.valid) {
36
34
  unreachable();
37
35
  } else {
38
36
  info.at = token;
@@ -40,7 +38,7 @@ function getCursorInfo(input, ast, index) {
40
38
  }
41
39
  if (token.start >= index) {
42
40
  info.next || (info.next = token);
43
- if (token instanceof ValidToken && !info.valid.next) {
41
+ if (token.valid && !info.valid.next) {
44
42
  info.valid.next = token;
45
43
  break;
46
44
  }
@@ -1,6 +1,7 @@
1
+ import type { generateParentsMap } from "./generateParentsMap.js";
1
2
  import { type AnyToken, type TokenDelimiterTypes } from "../types/ast.js";
2
3
  /**
3
4
  * 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).
4
5
  */
5
- export declare function getOppositeDelimiter(token: AnyToken): AnyToken<TokenDelimiterTypes> | undefined;
6
+ export declare function getOppositeDelimiter(token: AnyToken, parentsMap: ReturnType<typeof generateParentsMap>): AnyToken<TokenDelimiterTypes> | undefined;
6
7
  //# sourceMappingURL=getOppositeDelimiter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getOppositeDelimiter.d.ts","sourceRoot":"","sources":["../../src/utils/getOppositeDelimiter.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,QAAQ,EAAc,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,mBAAmB,CAAC,GAAG,SAAS,CAsB/F"}
1
+ {"version":3,"file":"getOppositeDelimiter.d.ts","sourceRoot":"","sources":["../../src/utils/getOppositeDelimiter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAMjE,OAAO,EAAE,KAAK,QAAQ,EAAiE,KAAK,mBAAmB,EAAqB,MAAM,iBAAiB,CAAA;AAE3J;;GAEG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,QAAQ,EACf,UAAU,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,GAC/C,QAAQ,CAAC,mBAAmB,CAAC,GAAG,SAAS,CAuB3C"}
@@ -4,25 +4,26 @@ import { isDelimiter } from "./isDelimiter.js";
4
4
  import { isParen } from "./isParen.js";
5
5
  import { isQuote } from "./isQuote.js";
6
6
  import { TOKEN_TYPE } from "../types/ast.js";
7
- function getOppositeDelimiter(token) {
7
+ function getOppositeDelimiter(token, parentsMap) {
8
+ const parent = parentsMap.get(token);
8
9
  if (!isDelimiter(token))
9
10
  throw new Error("Token is not a delimiter type.");
10
11
  if (isParen(token)) {
11
- const paren = token.parent.paren;
12
+ const paren = parent.paren;
12
13
  const opposite = paren.left === token ? "right" : "left";
13
14
  return paren[opposite];
14
15
  } else if (isBracket(token)) {
15
- const bracket = token.parent.bracket;
16
+ const bracket = parent.bracket;
16
17
  const opposite = bracket.left === token ? "right" : "left";
17
18
  return bracket[opposite];
18
19
  } else if (isQuote(token)) {
19
- const quotes = token.parent.quote;
20
+ const quotes = parent.quote;
20
21
  if (quotes === void 0)
21
22
  unreachable();
22
23
  const opposite = quotes.left === token ? "right" : "left";
23
24
  return quotes[opposite];
24
25
  } else if (token.type === TOKEN_TYPE.OP_EXPANDED_SEP) {
25
- const sep = token.parent.sep;
26
+ const sep = parent.sep;
26
27
  if (sep === void 0)
27
28
  unreachable();
28
29
  const opposite = sep.left === token ? "right" : "left";
@@ -0,0 +1,5 @@
1
+ import type { generateParentsMap } from "./generateParentsMap.js";
2
+ import type { AnyToken, ArrayNode, ConditionNode, ExpressionNode, GroupNode, ParentTypes, VariableNode } from "../types/ast.js";
3
+ /** See {@link generateParentsMap} */
4
+ export declare function getParent<T extends ExpressionNode | ConditionNode | GroupNode | VariableNode | ArrayNode | AnyToken | undefined>(node: T, map: ReturnType<typeof generateParentsMap>): ParentTypes<T> | undefined;
5
+ //# sourceMappingURL=getParent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getParent.d.ts","sourceRoot":"","sources":["../../src/utils/getParent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAC,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9H,qCAAqC;AACrC,wBAAgB,SAAS,CACxB,CAAC,SACC,cAAc,GACd,aAAa,GACb,SAAS,GACT,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,SAAS,EACV,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAEjF"}
@@ -0,0 +1,6 @@
1
+ function getParent(node, map) {
2
+ return map.get(node);
3
+ }
4
+ export {
5
+ getParent
6
+ };
@@ -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
  * ```
@@ -18,8 +18,7 @@
18
18
  * either insertion would fix the issue for either position would fix the issue, albeit with different results
19
19
  * ```
20
20
  */
21
- import { ErrorToken } from "../ast/classes/ErrorToken.js";
22
- import { type AnyToken } from "../types/ast.js";
21
+ import { type AnyToken, type ErrorToken } from "../types/ast.js";
23
22
  import type { CursorInfo } from "../types/autocomplete.js";
24
23
  export declare function getSurroundingErrors(tokens: AnyToken[], token: CursorInfo): ErrorToken[];
25
24
  //# sourceMappingURL=getSurroundingErrors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSurroundingErrors.d.ts","sourceRoot":"","sources":["../../src/utils/getSurroundingErrors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAc,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAG1D,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,CA8BxF"}
1
+ {"version":3,"file":"getSurroundingErrors.d.ts","sourceRoot":"","sources":["../../src/utils/getSurroundingErrors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAC,KAAK,UAAU,EAAa,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAG1D,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,CAgCxF"}
@@ -1,6 +1,6 @@
1
- import { ErrorToken } from "../ast/classes/ErrorToken.js";
2
1
  import { TOKEN_TYPE } from "../types/ast.js";
3
2
  function getSurroundingErrors(tokens, token) {
3
+ var _a, _b;
4
4
  if (token.at) {
5
5
  return [];
6
6
  }
@@ -8,11 +8,11 @@ function getSurroundingErrors(tokens, token) {
8
8
  let iNext = tokens[i] === token.next ? i : i + 1;
9
9
  let iPrev = tokens[i] === token.next ? i - 1 : i;
10
10
  const errors = [];
11
- while (tokens[iNext] instanceof ErrorToken) {
11
+ while (((_a = tokens[iNext]) == null ? void 0 : _a.valid) === false) {
12
12
  errors.push(tokens[iNext]);
13
13
  iNext++;
14
14
  }
15
- while (tokens[iPrev] instanceof ErrorToken) {
15
+ while (((_b = tokens[iPrev]) == null ? void 0 : _b.valid) === false) {
16
16
  errors.push(tokens[iPrev]);
17
17
  iPrev--;
18
18
  }
@@ -1,10 +1,14 @@
1
1
  export { extractTokens } from "./extractTokens.js";
2
+ export { generateParentsMap } from "./generateParentsMap.js";
2
3
  export { getCursorInfo } from "./getCursorInfo.js";
3
4
  export { getOppositeDelimiter } from "./getOppositeDelimiter.js";
5
+ export { getParent } from "./getParent.js";
4
6
  export { getSurroundingErrors } from "./getSurroundingErrors.js";
5
7
  export { isBracket } from "./isBracket.js";
6
8
  export { isDelimiter } from "./isDelimiter.js";
9
+ export { isNode } from "./isNode.js";
7
10
  export { isParen } from "./isParen.js";
8
11
  export { isQuote } from "./isQuote.js";
12
+ export { isToken } from "./isToken.js";
9
13
  export { prettyAst } from "./prettyAst.js";
10
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
@@ -1,20 +1,28 @@
1
1
  import { extractTokens } from "./extractTokens.js";
2
+ import { generateParentsMap } from "./generateParentsMap.js";
2
3
  import { getCursorInfo } from "./getCursorInfo.js";
3
4
  import { getOppositeDelimiter } from "./getOppositeDelimiter.js";
5
+ import { getParent } from "./getParent.js";
4
6
  import { getSurroundingErrors } from "./getSurroundingErrors.js";
5
7
  import { isBracket } from "./isBracket.js";
6
8
  import { isDelimiter } from "./isDelimiter.js";
9
+ import { isNode } from "./isNode.js";
7
10
  import { isParen } from "./isParen.js";
8
11
  import { isQuote } from "./isQuote.js";
12
+ import { isToken } from "./isToken.js";
9
13
  import { prettyAst } from "./prettyAst.js";
10
14
  export {
11
15
  extractTokens,
16
+ generateParentsMap,
12
17
  getCursorInfo,
13
18
  getOppositeDelimiter,
19
+ getParent,
14
20
  getSurroundingErrors,
15
21
  isBracket,
16
22
  isDelimiter,
23
+ isNode,
17
24
  isParen,
18
25
  isQuote,
26
+ isToken,
19
27
  prettyAst
20
28
  };
@@ -0,0 +1,10 @@
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 declare function isNode(node: any): node is Node;
10
+ //# sourceMappingURL=isNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNode.d.ts","sourceRoot":"","sources":["../../src/utils/isNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC3C;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,IAAI,CAE9C"}
@@ -0,0 +1,6 @@
1
+ function isNode(node) {
2
+ return (node == null ? void 0 : node.isNode) === true;
3
+ }
4
+ export {
5
+ isNode
6
+ };
@@ -0,0 +1,8 @@
1
+ import type { ErrorToken, ValidToken } from "../types/ast.js";
2
+ /**
3
+ * A simple wrapper around checking an object's `isToken` property that casts the object to a {@link ValidToken} or {@link ErrorToken} 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
+ export declare function isToken(token: any): token is ValidToken | ErrorToken;
8
+ //# sourceMappingURL=isToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isToken.d.ts","sourceRoot":"","sources":["../../src/utils/isToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE7D;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,UAAU,GAAG,UAAU,CAEpE"}
@@ -0,0 +1,6 @@
1
+ function isToken(token) {
2
+ return (token == null ? void 0 : token.isToken) === true;
3
+ }
4
+ export {
5
+ isToken
6
+ };
@@ -1,5 +1,4 @@
1
- import { ArrayNode, GroupNode, VariableNode } from "../ast/classes/index.js";
2
- import { type AnyToken, type ParserResults } from "../types/ast.js";
1
+ import { type AnyToken, type ArrayNode, type GroupNode, type ParserResults, type VariableNode } from "../types/ast.js";
3
2
  type Colors = {
4
3
  /** Color used to highlight the actual text content of the token nodes. */
5
4
  values: string;
@@ -1 +1 @@
1
- {"version":3,"file":"prettyAst.d.ts","sourceRoot":"","sources":["../../src/utils/prettyAst.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAA6C,SAAS,EAAc,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACnI,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAc,MAAM,iBAAiB,CAAA;AAG/E,KAAK,MAAM,GAAG;IACb,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAA;IACd,6NAA6N;IAC7N,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,mKAAmK;IACnK,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAA;CACb,CAAA;AAoBD;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,SAAS,CACxB,GAAG,EAAE,aAAa,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,EACpE,EAAE,MAAc,EAAE,QAAe,EAAE,IAAW,EAAE,MAAY,EAAE,KAAU,EAAE,GAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,EAAE,MAAM,CAAC,CAAM,EAC7J,MAAM,GAAE,OAAO,CAAC,MAAM,CAAC,GAAG,KAAU,GAClC,MAAM,CAyFR"}
1
+ {"version":3,"file":"prettyAst.d.ts","sourceRoot":"","sources":["../../src/utils/prettyAst.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAA8B,KAAK,SAAS,EAAE,KAAK,aAAa,EAAc,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9J,KAAK,MAAM,GAAG;IACb,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAA;IACd,6NAA6N;IAC7N,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,mKAAmK;IACnK,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAA;CACb,CAAA;AAoBD;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,SAAS,CACxB,GAAG,EAAE,aAAa,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,EACpE,EAAE,MAAc,EAAE,QAAe,EAAE,IAAW,EAAE,MAAY,EAAE,KAAU,EAAE,GAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,EAAE,MAAM,CAAC,CAAM,EAC7J,MAAM,GAAE,OAAO,CAAC,MAAM,CAAC,GAAG,KAAU,GAClC,MAAM,CA2FR"}
@@ -2,17 +2,8 @@ import * as color from "@alanscodelog/utils/colors.js";
2
2
  import { isBlank } from "@alanscodelog/utils/isBlank.js";
3
3
  import "@alanscodelog/utils/types";
4
4
  import { unreachable } from "@alanscodelog/utils/unreachable.js";
5
- import { ArrayNode } from "../ast/classes/ArrayNode.js";
6
- import { ConditionNode } from "../ast/classes/ConditionNode.js";
7
- import { ErrorToken } from "../ast/classes/ErrorToken.js";
8
- import { ExpressionNode } from "../ast/classes/ExpressionNode.js";
9
- import { GroupNode } from "../ast/classes/GroupNode.js";
10
- import "@alanscodelog/utils/crop.js";
11
- import "@alanscodelog/utils/indent.js";
12
- import "@alanscodelog/utils/pretty.js";
13
- import { ValidToken } from "../ast/classes/ValidToken.js";
14
- import { VariableNode } from "../ast/classes/VariableNode.js";
15
- import { TOKEN_TYPE } from "../types/ast.js";
5
+ import { isToken } from "./isToken.js";
6
+ import { AST_TYPE, TOKEN_TYPE } from "../types/ast.js";
16
7
  const defaultColors = {
17
8
  values: color.yellow,
18
9
  info: color.cyan,
@@ -42,23 +33,25 @@ function prettyAst(ast, { indent = " ", children = "├╴", last = "└╴",
42
33
  const ___ = __ + _ + branch;
43
34
  const __L = __ + _ + indent[0];
44
35
  const prettyAst_ = prettyAst;
45
- if (ast instanceof ValidToken) {
46
- const value = `${ast.value}`;
47
- return `TOKEN ${pos} ${c.values}${quote}${value}${quote}${c.reset}${extra}`;
36
+ if (isToken(ast)) {
37
+ if (ast.valid) {
38
+ const value = `${ast.value}`;
39
+ return `TOKEN ${pos} ${c.values}${quote}${value}${quote}${c.reset}${extra}`;
40
+ }
41
+ if (!ast.valid) {
42
+ const value = `[${ast.expected.join(", ")}]`;
43
+ return `ERROR ${pos} ${c.error}${value}${c.reset}${extra}`;
44
+ }
48
45
  }
49
- if (ast instanceof ErrorToken) {
50
- const value = `[${ast.expected.join(", ")}]`;
51
- return `ERROR ${pos} ${c.error}${value}${c.reset}${extra}`;
52
- }
53
- if (ast instanceof ConditionNode) {
46
+ if (ast.type === AST_TYPE.CONDITION) {
54
47
  const header = `${c.info}${ast.operator === void 0}${c.reset}`;
55
48
  const not = ast.operator ? prettyAst_(ast.operator, opts, c, ___, `(negation)`) : "";
56
49
  const property = ast.property ? prettyAst_(ast.property, opts, c, ___, `(property)`) : "";
57
50
  const sepL = ((_a = ast.sep) == null ? void 0 : _a.left) ? prettyAst_(ast.sep.left, opts, c, ___, `(separator)`) : "";
58
51
  const op = ast.propertyOperator ? prettyAst_(ast.propertyOperator, opts, c, ___, `(property operator)`) : "";
59
52
  const sepR = ((_b = ast.sep) == null ? void 0 : _b.right) ? prettyAst_(ast.sep.right, opts, c, ___, `(separator)`) : "";
60
- const isRegex = ast.value instanceof VariableNode && ((_c = ast.value.quote) == null ? void 0 : _c.left.type) === TOKEN_TYPE.REGEX;
61
- const isArray = ast.value instanceof ArrayNode;
53
+ const isRegex = ast.value.type === AST_TYPE.VARIABLE && ((_c = ast.value.quote) == null ? void 0 : _c.left.type) === TOKEN_TYPE.REGEX;
54
+ const isArray = ast.value.type === AST_TYPE.ARRAY;
62
55
  const variable = prettyAst_(ast.value, opts, c, __L, `(${property ? "value" : "variable/alone"}${isRegex ? " - regex" : isArray ? "- array" : ""})`);
63
56
  return [
64
57
  `CONDITION ${pos} ${header}${extra}`,
@@ -66,7 +59,7 @@ function prettyAst(ast, { indent = " ", children = "├╴", last = "└╴",
66
59
  ].join(`
67
60
  ${__}`);
68
61
  }
69
- if (ast instanceof VariableNode) {
62
+ if (ast.type === AST_TYPE.VARIABLE) {
70
63
  const prefix = ast.prefix ? prettyAst_(ast.prefix, opts, c, ___, `(value prefix)`) : "";
71
64
  const left = ((_d = ast.quote) == null ? void 0 : _d.left) ? prettyAst_(ast.quote.left, opts, c, ___, "") : "";
72
65
  const value = prettyAst_(ast.value, opts, c, !ast.quote ? __L : !((_e = ast.quote) == null ? void 0 : _e.right) ? __L : ___, "");
@@ -78,7 +71,7 @@ ${__}`);
78
71
  ].join(`
79
72
  ${__}`);
80
73
  }
81
- if (ast instanceof GroupNode) {
74
+ if (ast.type === AST_TYPE.GROUP) {
82
75
  const header = `${c.info}${ast.prefix === void 0 || ast.prefix.operator === void 0}${c.reset}`;
83
76
  const prefix = ast.prefix ? prettyAst_(ast.prefix, opts, c, ___, `(group prefix)`) : "";
84
77
  const expression = prettyAst_(ast.expression, opts, c, __L, "");
@@ -88,7 +81,7 @@ ${__}`);
88
81
  ].join(`
89
82
  ${__}`);
90
83
  }
91
- if (ast instanceof ArrayNode) {
84
+ if (ast.type === AST_TYPE.ARRAY) {
92
85
  const bracketL = ast.bracket.left ? prettyAst_(ast.bracket.left, opts, c, ast.values.length === 0 && !ast.bracket.right ? __L : ___, "") : "";
93
86
  const values = ast.values.length > 0 ? ast.values.map(
94
87
  (node, i) => prettyAst_(node, opts, c, !ast.bracket.right && i === ast.values.length - 1 ? __L : ___, "")
@@ -100,11 +93,11 @@ ${__}`);
100
93
  ].join(`
101
94
  ${__}`);
102
95
  }
103
- if (ast instanceof ExpressionNode) {
96
+ if (ast.type === AST_TYPE.EXPRESSION) {
104
97
  const left = prettyAst_(ast.left, opts, c, ___, "");
105
98
  const operator = prettyAst_(ast.operator, opts, c, ___, `(boolean operator)`);
106
99
  const right = prettyAst_(ast.right, opts, c, __L, "");
107
- const header = ast.operator instanceof ErrorToken ? `${c.info}[${ast.operator.expected.join(",")}]${c.reset}` : `${c.info}"${ast.operator.value}"${c.reset}`;
100
+ const header = !ast.operator.valid ? `${c.info}[${ast.operator.expected.join(",")}]${c.reset}` : `${c.info}"${ast.operator.value}"${c.reset}`;
108
101
  return [
109
102
  `EXPRESSION ${pos} ${header}${extra}`,
110
103
  ...toRows([left, operator, right], opts)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@witchcraft/expressit",
3
3
  "description": "A blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies like autocomplete.",
4
- "version": "0.1.2",
4
+ "version": "0.2.0",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
7
7
  "module": "./dist/index.js",
@@ -19,13 +19,13 @@
19
19
  "types": "./dist/ast/*",
20
20
  "import": "./dist/ast/*"
21
21
  },
22
- "./helpers": {
23
- "types": "./dist/helpers/index.d.ts",
24
- "import": "./dist/helpers/index.js"
22
+ "./internal": {
23
+ "types": "./dist/internal/index.d.ts",
24
+ "import": "./dist/internal/index.js"
25
25
  },
26
- "./helpers/*": {
27
- "types": "./dist/helpers/*",
28
- "import": "./dist/helpers/*"
26
+ "./internal/*": {
27
+ "types": "./dist/internal/*",
28
+ "import": "./dist/internal/*"
29
29
  },
30
30
  "./methods": {
31
31
  "types": "./dist/methods/index.d.ts",
package/src/Lexer.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { isBlank } from "@alanscodelog/utils/isBlank.js"
2
2
  import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn.js"
3
3
 
4
- import { checkParserOpts } from "./helpers/parser/checkParserOpts.js"
5
- import { parseParserOptions } from "./helpers/parser/parseParserOptions.js"
4
+ import { checkParserOpts } from "./internal/checkParserOpts.js"
5
+ import { parseParserOptions } from "./internal/parseParserOptions.js"
6
6
  import type { FullParserOptions } from "./types/index.js"
7
7
 
8
8
  const regexFlags = /^[a-zA-Z]+/