@witchcraft/expressit 0.0.2 → 0.1.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 (124) hide show
  1. package/README.md +6 -4
  2. package/dist/Lexer.d.ts +146 -0
  3. package/dist/Lexer.d.ts.map +1 -0
  4. package/dist/Lexer.js +960 -0
  5. package/dist/Parser.d.ts +140 -0
  6. package/dist/Parser.d.ts.map +1 -0
  7. package/dist/Parser.js +668 -0
  8. package/dist/ast/builders/token.js +1 -1
  9. package/dist/ast/handlers.d.ts +3 -3
  10. package/dist/ast/handlers.d.ts.map +1 -1
  11. package/dist/ast/index.d.ts.map +1 -1
  12. package/dist/examples/index.d.ts +2 -0
  13. package/dist/examples/index.d.ts.map +1 -0
  14. package/dist/examples/index.js +4 -0
  15. package/dist/examples/shortcutContextParser.d.ts +2 -1
  16. package/dist/examples/shortcutContextParser.d.ts.map +1 -1
  17. package/dist/examples/shortcutContextParser.js +9 -5
  18. package/dist/helpers/errors.d.ts.map +1 -1
  19. package/dist/helpers/errors.js +3 -1
  20. package/dist/helpers/index.d.ts.map +1 -1
  21. package/dist/helpers/parser/checkParserOpts.d.ts.map +1 -1
  22. package/dist/helpers/parser/checkParserOpts.js +3 -2
  23. package/dist/helpers/parser/extractPosition.d.ts +2 -6
  24. package/dist/helpers/parser/extractPosition.d.ts.map +1 -1
  25. package/dist/helpers/parser/extractPosition.js +3 -3
  26. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +2 -3
  27. package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +1 -1
  28. package/dist/helpers/parser/getUnclosedRightParenCount.js +4 -4
  29. package/dist/index.d.ts +1 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +3 -5
  32. package/dist/methods/autocomplete.d.ts.map +1 -1
  33. package/dist/methods/autocomplete.js +1 -1
  34. package/dist/methods/autoreplace.js +1 -1
  35. package/dist/methods/autosuggest.js +1 -1
  36. package/dist/methods/evaluate.d.ts.map +1 -1
  37. package/dist/methods/evaluate.js +3 -1
  38. package/dist/methods/getIndexes.d.ts.map +1 -1
  39. package/dist/methods/getIndexes.js +2 -1
  40. package/dist/methods/normalize.d.ts +0 -2
  41. package/dist/methods/normalize.d.ts.map +1 -1
  42. package/dist/methods/normalize.js +2 -3
  43. package/dist/methods/validate.d.ts.map +1 -1
  44. package/dist/methods/validate.js +3 -1
  45. package/dist/package.json.js +44 -37
  46. package/dist/types/ast.d.ts +2 -8
  47. package/dist/types/ast.d.ts.map +1 -1
  48. package/dist/types/errors.d.ts +5 -17
  49. package/dist/types/errors.d.ts.map +1 -1
  50. package/dist/types/errors.js +0 -1
  51. package/dist/types/parser.d.ts +6 -2
  52. package/dist/types/parser.d.ts.map +1 -1
  53. package/dist/utils/extractTokens.js +1 -1
  54. package/dist/utils/getCursorInfo.d.ts +2 -2
  55. package/dist/utils/getCursorInfo.d.ts.map +1 -1
  56. package/dist/utils/getCursorInfo.js +3 -2
  57. package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
  58. package/dist/utils/getOppositeDelimiter.js +1 -1
  59. package/dist/utils/prettyAst.d.ts.map +1 -1
  60. package/dist/utils/prettyAst.js +15 -9
  61. package/package.json +42 -37
  62. package/src/Lexer.ts +704 -0
  63. package/src/Parser.ts +972 -0
  64. package/src/ast/builders/array.ts +2 -2
  65. package/src/ast/builders/condition.ts +1 -1
  66. package/src/ast/builders/expression.ts +1 -1
  67. package/src/ast/builders/group.ts +1 -1
  68. package/src/ast/builders/index.ts +1 -1
  69. package/src/ast/builders/pos.ts +1 -1
  70. package/src/ast/builders/token.ts +2 -2
  71. package/src/ast/builders/type.ts +1 -1
  72. package/src/ast/builders/variable.ts +1 -1
  73. package/src/ast/classes/ConditionNode.ts +1 -1
  74. package/src/ast/classes/ErrorToken.ts +1 -1
  75. package/src/ast/classes/ValidToken.ts +2 -2
  76. package/src/ast/classes/index.ts +1 -1
  77. package/src/ast/handlers.ts +6 -6
  78. package/src/ast/index.ts +2 -2
  79. package/src/examples/index.ts +3 -0
  80. package/src/examples/shortcutContextParser.ts +11 -6
  81. package/src/helpers/errors.ts +5 -3
  82. package/src/helpers/general/defaultConditionNormalizer.ts +1 -1
  83. package/src/helpers/general/index.ts +1 -1
  84. package/src/helpers/index.ts +3 -2
  85. package/src/helpers/parser/checkParserOpts.ts +13 -12
  86. package/src/helpers/parser/extractPosition.ts +4 -8
  87. package/src/helpers/parser/getUnclosedRightParenCount.ts +6 -6
  88. package/src/helpers/parser/index.ts +1 -1
  89. package/src/helpers/parser/parseParserOptions.ts +1 -1
  90. package/src/index.ts +2 -2
  91. package/src/methods/autocomplete.ts +5 -5
  92. package/src/methods/autoreplace.ts +2 -2
  93. package/src/methods/autosuggest.ts +3 -3
  94. package/src/methods/evaluate.ts +4 -2
  95. package/src/methods/getIndexes.ts +2 -1
  96. package/src/methods/normalize.ts +3 -4
  97. package/src/methods/validate.ts +4 -2
  98. package/src/types/ast.ts +2 -9
  99. package/src/types/errors.ts +12 -22
  100. package/src/types/parser.ts +6 -4
  101. package/src/utils/extractTokens.ts +1 -1
  102. package/src/utils/getCursorInfo.ts +6 -4
  103. package/src/utils/getOppositeDelimiter.ts +5 -2
  104. package/src/utils/prettyAst.ts +5 -3
  105. package/dist/examples/advancedValueComparer.d.ts +0 -3
  106. package/dist/examples/advancedValueComparer.d.ts.map +0 -1
  107. package/dist/examples/advancedValueComparer.js +0 -28
  108. package/dist/grammar/ParserBase.d.ts +0 -51
  109. package/dist/grammar/ParserBase.d.ts.map +0 -1
  110. package/dist/grammar/ParserBase.js +0 -516
  111. package/dist/grammar/createTokens.d.ts +0 -56
  112. package/dist/grammar/createTokens.d.ts.map +0 -1
  113. package/dist/grammar/createTokens.js +0 -843
  114. package/dist/grammar/index.d.ts +0 -3
  115. package/dist/grammar/index.d.ts.map +0 -1
  116. package/dist/grammar/index.js +0 -6
  117. package/dist/parser.d.ts +0 -58
  118. package/dist/parser.d.ts.map +0 -1
  119. package/dist/parser.js +0 -136
  120. package/src/examples/advancedValueComparer.ts +0 -31
  121. package/src/grammar/ParserBase.ts +0 -715
  122. package/src/grammar/createTokens.ts +0 -512
  123. package/src/grammar/index.ts +0 -4
  124. package/src/parser.ts +0 -183
@@ -1,4 +1,4 @@
1
- import type { Mutable } from "@alanscodelog/utils"
1
+ import type { Mutable } from "@alanscodelog/utils/types"
2
2
 
3
3
  import { token } from "./token.js"
4
4
 
@@ -11,7 +11,7 @@ export function array(
11
11
  values: VariableNode[],
12
12
  bracket: { left?: boolean, right?: boolean } = { right: true, left: true },
13
13
  parenLeftPos?: Position,
14
- parenRightPos?: Position
14
+ parenRightPos?: Position,
15
15
  ): ArrayNode {
16
16
  const node: Mutable<Partial<ArrayNode>> = {
17
17
  type: AST_TYPE.ARRAY,
@@ -29,7 +29,7 @@ export function condition(
29
29
  not: true | ValidToken<TOKEN_TYPE.NOT> = true,
30
30
  property?: VariableNode | ErrorToken<TOKEN_TYPE.VALUE>,
31
31
  propertyOperator?: AnyToken<TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.VALUE>,
32
- { right, left }: Partial<Record<"right" | "left", ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP>>> = { }
32
+ { right, left }: Partial<Record<"right" | "left", ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP>>> = { },
33
33
  ): ConditionNode {
34
34
  const position = pos(value satisfies Position)
35
35
  const notStart = not === true ? undefined : not.start
@@ -28,7 +28,7 @@ export function expression(
28
28
  ExpressionNode |
29
29
  GroupNode |
30
30
  ErrorToken<TOKEN_TYPE.VALUE> |
31
- undefined
31
+ undefined,
32
32
  ): ExpressionNode {
33
33
  const start =
34
34
  left?.start ??
@@ -32,7 +32,7 @@ export function group(
32
32
 
33
33
  paren: { left?: boolean, right?: boolean } = { right: true, left: true },
34
34
  parenLeftPos?: Position,
35
- parenRightPos?: Position
35
+ parenRightPos?: Position,
36
36
  ): GroupNode {
37
37
  if (expression === undefined) {
38
38
  expression = token(TOKEN_TYPE.VALUE, undefined, prefix?.end !== undefined ? { start: prefix.end } : undefined)
@@ -1,4 +1,4 @@
1
- /* Autogenerated Index */
1
+ /* Autogenerated Index [Ignore] */
2
2
 
3
3
  export { array } from "./array.js"
4
4
  export { condition } from "./condition.js"
@@ -31,7 +31,7 @@ export function pos<TItem extends Position | Partial<Position> | EmptyObj>(
31
31
  export function pos(start: number, end: number): Position
32
32
  export function pos(
33
33
  start: number | Position | Partial<Position> | EmptyObj | undefined,
34
- end?: number | { fill: boolean }
34
+ end?: number | { fill: boolean },
35
35
  ): Position | EmptyObj {
36
36
  if (typeof start === "number") {
37
37
  return { start, end: end as number }
@@ -1,4 +1,4 @@
1
- import { isArray } from "@alanscodelog/utils"
1
+ import { isArray } from "@alanscodelog/utils/isArray"
2
2
 
3
3
  import { pos } from "./pos.js"
4
4
 
@@ -21,7 +21,7 @@ export function token<
21
21
  >(
22
22
  type: TValue extends undefined ? TType | TType[] : TType,
23
23
  value: TValue,
24
- position: Position | Partial<Position> | EmptyObj = {}
24
+ position: Position | Partial<Position> | EmptyObj = {},
25
25
  ): TValue extends undefined
26
26
  ? ErrorToken<TType>
27
27
  : ValidToken<TType> {
@@ -3,7 +3,7 @@ import { type ExtractTokenType, TOKEN_TYPE } from "../../types/ast.js"
3
3
  * Given a the string value of an operator or single delimiter token, returns the corresponding @see ValidToken_TYPE .
4
4
  */
5
5
  export function type<T extends string>(
6
- operatorSymbol: T
6
+ operatorSymbol: T,
7
7
  ): ExtractTokenType<T> {
8
8
  switch (operatorSymbol) {
9
9
  case "`": return TOKEN_TYPE.BACKTICK as any
@@ -18,7 +18,7 @@ export function variable(
18
18
  prefix: ValidToken<TOKEN_TYPE.VALUE> | undefined,
19
19
  value: string | AnyToken<TOKEN_TYPE.VALUE>,
20
20
  quote?: { type: TokenQuoteTypes, left?: boolean, right?: boolean, flags?: string },
21
- position?: Position | EmptyObj
21
+ position?: Position | EmptyObj,
22
22
  ): VariableNode {
23
23
  if (typeof value === "string") {
24
24
  value = token(TOKEN_TYPE.VALUE, value, position)
@@ -86,7 +86,7 @@ export class ConditionNode<
86
86
 
87
87
  set parent(value: GroupNode |
88
88
  ExpressionNode |
89
- undefined
89
+ undefined,
90
90
  ) {
91
91
  if (this.#setParent) {throw new Error("parent property is readonly")}
92
92
  this.#parent = value
@@ -32,7 +32,7 @@ export class ErrorToken<
32
32
  set parent(value: VariableNode |
33
33
  GroupNode |
34
34
  ExpressionNode |
35
- ConditionNode
35
+ ConditionNode,
36
36
  ) {
37
37
  if (this.#parent) {throw new Error("parent property is readonly")}
38
38
  this.#parent = value
@@ -36,7 +36,7 @@ export class ValidToken<
36
36
  | GroupNode
37
37
  | ExpressionNode
38
38
  | ConditionNode
39
- | ArrayNode
39
+ | ArrayNode,
40
40
  ) {
41
41
  if (this.#parent) {throw new Error("parent property is readonly")}
42
42
  this.#parent = value
@@ -47,7 +47,7 @@ export class ValidToken<
47
47
  value: string
48
48
  start: number
49
49
  end: number
50
- }
50
+ },
51
51
  ) {
52
52
  super(start, end)
53
53
  this.type = type
@@ -1,4 +1,4 @@
1
- /* Autogenerated Index */
1
+ /* Autogenerated Index [Ignore] */
2
2
 
3
3
  export { ArrayNode } from "./ArrayNode.js"
4
4
  export { Condition } from "./Condition.js"
@@ -29,11 +29,11 @@ const delimiters = <T extends TokenDelimiterTypes>
29
29
  // check must be falsy, we want to return undefined when given ""
30
30
  value ? new ValidToken({ value, type, ...pos }) : undefined
31
31
 
32
- const maybeToken = <T extends TOKEN_TYPE>(type: T) => (value: string | undefined, pos: Position,): AnyToken<T> => {
32
+ const maybeToken = <T extends TOKEN_TYPE> (type: T) => <TVal extends string | undefined> (value: TVal, pos: Position): TVal extends string ? ValidToken<T> : ErrorToken<T> => {
33
33
  if (value === undefined) {
34
- return error(pos.end, [type])
34
+ return error(pos.end, [type]) as any
35
35
  } else {
36
- return new ValidToken({ value, type, ...pos })
36
+ return new ValidToken({ value, type, ...pos }) as any
37
37
  }
38
38
  }
39
39
 
@@ -68,7 +68,7 @@ export function variable(
68
68
  quoteL: AnyToken<TokenQuoteTypes> | null | undefined,
69
69
  value: AnyToken<TOKEN_TYPE.VALUE> | null | undefined,
70
70
  quoteR: AnyToken<TokenQuoteTypes> | null | undefined,
71
- flags?: ValidToken<TOKEN_TYPE.VALUE>
71
+ flags?: ValidToken<TOKEN_TYPE.VALUE>,
72
72
  ): VariableNode {
73
73
  const node: FirstConstructorParam<typeof VariableNode> = {
74
74
  prefix: prefix ?? undefined,
@@ -152,7 +152,7 @@ export function group(
152
152
  prefix: ConditionNode | null | undefined,
153
153
  parenL: ValidToken<TOKEN_TYPE.PARENL> | null | undefined,
154
154
  condition: GroupNode["expression"],
155
- parenR: ValidToken<TOKEN_TYPE.PARENR> | null | undefined
155
+ parenR: ValidToken<TOKEN_TYPE.PARENR> | null | undefined,
156
156
  ): GroupNode {
157
157
  const node: FirstConstructorParam<typeof GroupNode> = {
158
158
  prefix: prefix ?? operator ?? undefined,
@@ -172,7 +172,7 @@ export function group(
172
172
  export function array(
173
173
  bracketL: ValidToken<TOKEN_TYPE.BRACKETL>,
174
174
  values: VariableNode[],
175
- bracketR: ValidToken<TOKEN_TYPE.BRACKETR> | null | undefined
175
+ bracketR: ValidToken<TOKEN_TYPE.BRACKETR> | null | undefined,
176
176
  ): ArrayNode {
177
177
  const node: FirstConstructorParam<typeof ArrayNode> = {
178
178
  values,
package/src/ast/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- /* Autogenerated Index */
2
-
3
1
  export * as builders from "./builders/index.js"
4
2
  export * as classes from "./classes/index.js"
3
+ /* Autogenerated Index */
4
+
5
5
  export { token } from "./handlers.js"
@@ -0,0 +1,3 @@
1
+ /* Autogenerated Index */
2
+
3
+ export { ShortcutContextParser } from "./shortcutContextParser.js"
@@ -9,7 +9,7 @@
9
9
  * The validate function will return a list of positions with a list of errors which includes handling invalid or duplicate regex flags.
10
10
  */
11
11
 
12
- import { Parser } from "../parser.js"
12
+ import { Parser } from "../Parser.js"
13
13
  import type { Position } from "../types/ast.js"
14
14
  import type { ValueQuery } from "../types/parser.js"
15
15
 
@@ -24,7 +24,7 @@ export class ShortcutContextParser<T extends
24
24
 
25
25
  constructor(
26
26
  dummyContext: Record<string, any>,
27
- validRegexFlags: string[] = ["i", "u", "m"]
27
+ validRegexFlags: string[] = ["i", "u", "m"],
28
28
  ) {
29
29
  super({
30
30
  arrayValues: false,
@@ -43,11 +43,11 @@ export class ShortcutContextParser<T extends
43
43
  }
44
44
  return prefix + variable
45
45
  },
46
- valueComparer: (_condition, contextValue, query) => {
47
- if (query.isRegex) {
48
- return contextValue.match(new RegExp(query.value as string, query.regexFlags ?? "")) !== null
46
+ valueComparer: (condition, contextValue, _context) => {
47
+ if (condition.value instanceof RegExp) {
48
+ return contextValue.match(condition.value) !== null
49
49
  }
50
- return contextValue === query.value
50
+ return contextValue === condition.value
51
51
  },
52
52
  valueValidator: (_contextValue, query): T[] | void => {
53
53
  let tokens: T[] = []
@@ -123,6 +123,11 @@ export class ShortcutContextParser<T extends
123
123
  this._extractKeysFromContext(dummyContext)
124
124
  }
125
125
 
126
+ setContext(context: Record<string, any>): void {
127
+ this.validKeys = []
128
+ this._extractKeysFromContext(context)
129
+ }
130
+
126
131
  private _extractKeysFromContext(context: Record<string, any>, prev?: string): void {
127
132
  for (const key of Object.keys(context)) {
128
133
  if (typeof context[key] === "boolean") {
@@ -1,5 +1,7 @@
1
- import type { Keys } from "@alanscodelog/utils"
2
- import { crop, indent, pretty } from "@alanscodelog/utils"
1
+ import { crop } from "@alanscodelog/utils/crop"
2
+ import { indent } from "@alanscodelog/utils/indent"
3
+ import { pretty } from "@alanscodelog/utils/pretty"
4
+ import type { Keys } from "@alanscodelog/utils/types"
3
5
 
4
6
  // @ts-expect-error todo
5
7
  import { repository, version } from "../package.js"
@@ -38,7 +40,7 @@ function forceStringifyErrors(_key: string, value: any): any {
38
40
  key === "stack"
39
41
  ? value[key]!.split(/\n/)
40
42
  : value[key],
41
- ])
43
+ ]),
42
44
  )
43
45
  }
44
46
  return value
@@ -3,7 +3,7 @@ import type { ConditionNormalizer, ValueQuery } from "../../types/parser.js"
3
3
 
4
4
  export const defaultConditionNormalizer: ConditionNormalizer =
5
5
  function defaultConditionNormalizer(
6
- { value, operator, isNegated }: Pick<ValueQuery, "value" | "operator" | "isNegated">
6
+ { value, operator, isNegated }: Pick<ValueQuery, "value" | "operator" | "isNegated">,
7
7
  ) {
8
8
  return { value, operator, negate: isNegated }
9
9
  }
@@ -1,4 +1,4 @@
1
- /* Autogenerated Index */
1
+ /* Autogenerated Index [Ignore] */
2
2
 
3
3
  export { applyBoolean } from "./applyBoolean.js"
4
4
  export { applyPrefix } from "./applyPrefix.js"
@@ -1,5 +1,6 @@
1
- /* Autogenerated Index [Ignore] */
2
-
3
1
  export * as general from "./general/index.js"
4
2
  export * as parser from "./parser/index.js"
3
+
4
+ /* Autogenerated Index [Ignore] */
5
+
5
6
  export { BooleanParserLibraryError } from "./errors.js"
@@ -1,4 +1,5 @@
1
- import { isBlank, pushIfNotIn } from "@alanscodelog/utils"
1
+ import { isBlank } from "@alanscodelog/utils/isBlank"
2
+ import { pushIfNotIn } from "@alanscodelog/utils/pushIfNotIn"
2
3
 
3
4
  import { ERROR_CODES } from "../../types/errors.js"
4
5
  import type { FullParserOptions, ParserOptions } from "../../types/parser.js"
@@ -19,7 +20,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
19
20
  ]
20
21
  const extra: string[] = []
21
22
  if (opts.expandedPropertySeparator) extra.push(opts.expandedPropertySeparator)
22
- if (opts.customPropertyOperators) pushIfNotIn(extra, ...opts.customPropertyOperators)
23
+ if (opts.customPropertyOperators) pushIfNotIn(extra, opts.customPropertyOperators)
23
24
 
24
25
 
25
26
  /* #region Blank Operator Checks */
@@ -27,7 +28,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
27
28
  throw new BooleanParserLibraryError(
28
29
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
29
30
  { prohibited: [""], invalid: opts.expandedPropertySeparator },
30
- `expandedPropertySeparator cannot be blank`
31
+ `expandedPropertySeparator cannot be blank`,
31
32
  )
32
33
  }
33
34
  const customInvalid = opts.customPropertyOperators?.find(_ => isBlank(_))
@@ -35,7 +36,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
35
36
  throw new BooleanParserLibraryError(
36
37
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
37
38
  { prohibited: [""], invalid: customInvalid },
38
- `customPropertyOperators cannot contain blank entries`
39
+ `customPropertyOperators cannot contain blank entries`,
39
40
  )
40
41
  }
41
42
  const prefixInvalid = opts.prefixableStrings?.find(_ => isBlank(_))
@@ -43,7 +44,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
43
44
  throw new BooleanParserLibraryError(
44
45
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
45
46
  { prohibited: [""], invalid: prefixInvalid },
46
- `prefixableStrings cannot contain blank entries`
47
+ `prefixableStrings cannot contain blank entries`,
47
48
  )
48
49
  }
49
50
  for (const key of ["and", "or", "not"]) {
@@ -54,7 +55,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
54
55
  throw new BooleanParserLibraryError(
55
56
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
56
57
  { prohibited: [""], invalid },
57
- `keywords.${key} cannot contain entries with blank values`
58
+ `keywords.${key} cannot contain entries with blank values`,
58
59
  )
59
60
  }
60
61
  }
@@ -77,7 +78,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
77
78
  throw new BooleanParserLibraryError(
78
79
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
79
80
  { prohibited: all, invalid: invalidPrefixableString },
80
- `prefixableStrings ${messageInvalidAny} "${invalidPrefixableString}"`
81
+ `prefixableStrings ${messageInvalidAny} "${invalidPrefixableString}"`,
81
82
  )
82
83
  }
83
84
 
@@ -87,7 +88,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
87
88
  throw new BooleanParserLibraryError(
88
89
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
89
90
  { prohibited: allKeywords, invalid: invalidExpandedPropertySeparator },
90
- `expandedPropertySeparator ${messageInvalidBool} "${invalidExpandedPropertySeparator}"`
91
+ `expandedPropertySeparator ${messageInvalidBool} "${invalidExpandedPropertySeparator}"`,
91
92
  )
92
93
  }
93
94
 
@@ -98,7 +99,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
98
99
  throw new BooleanParserLibraryError(
99
100
  ERROR_CODES.PARSER_CONFLICTING_OPTIONS_ERROR,
100
101
  { prohibited: keywords, invalid: invalidCustomPropertyOperator },
101
- `customPropertyOperator ${messageInvalidBool} "${invalidCustomPropertyOperator}"`
102
+ `customPropertyOperator ${messageInvalidBool} "${invalidCustomPropertyOperator}"`,
102
103
  )
103
104
  }
104
105
  /* #regionend */
@@ -115,7 +116,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
115
116
  throw new BooleanParserLibraryError(
116
117
  ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
117
118
  { options: requireCustomNormalizer, requires: "conditionNormalizer" },
118
- `A custom conditionNormalizer function must be specified when using the following options: ${requireCustomNormalizer.join(", ")}`
119
+ `A custom conditionNormalizer function must be specified when using the following options: ${requireCustomNormalizer.join(", ")}`,
119
120
  )
120
121
  }
121
122
  const requireCustomComparer: (keyof ParserOptions)[] = [] as any
@@ -126,7 +127,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
126
127
  throw new BooleanParserLibraryError(
127
128
  ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
128
129
  { options: requireCustomComparer, requires: "valueComparer" },
129
- `A custom valueComparer function must be specified when using the following options: ${requireCustomComparer.join(", ")}`
130
+ `A custom valueComparer function must be specified when using the following options: ${requireCustomComparer.join(", ")}`,
130
131
  )
131
132
  }
132
133
  }
@@ -135,7 +136,7 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
135
136
  throw new BooleanParserLibraryError(
136
137
  ERROR_CODES.PARSER_OPTION_REQUIRED_ERROR,
137
138
  { requires: "valueValidator" },
138
- `A custom valueValidator function must be specified when using the validate method.`
139
+ `A custom valueValidator function must be specified when using the validate method.`,
139
140
  )
140
141
  }
141
142
  }
@@ -1,15 +1,11 @@
1
+ import type { Token } from "../../Lexer.js"
1
2
  import type { Position } from "../../types/ast.js"
2
3
 
3
4
 
4
- type ChevrotainLocation = {
5
- startOffset?: number
6
- endOffset?: number
7
- }
8
-
9
5
  /** @internal */
10
- export function extractPosition(loc: ChevrotainLocation, shift: number): Position {
6
+ export function extractPosition(pos: Pick<Token, "startOffset" | "endOffset">, shift: number): Position {
11
7
  return {
12
- start: loc.startOffset! - (shift ?? 0),
13
- end: loc.endOffset! + 1 - (shift ?? 0),
8
+ start: pos.startOffset! - (shift ?? 0),
9
+ end: pos.endOffset! + 1 - (shift ?? 0),
14
10
  }
15
11
  }
@@ -1,20 +1,20 @@
1
- import { type IToken, tokenMatcher } from "chevrotain"
2
-
3
- import type { createTokens } from "../../grammar/createTokens.js"
1
+ import { $T, type Token } from "../../Lexer.js"
4
2
 
5
3
 
6
4
  /** @internal */
7
- export function getUnclosedRightParenCount(tokens: IToken[], t: ReturnType<typeof createTokens>["tokens"]): number {
5
+
6
+
7
+ export function getUnclosedRightParenCount(tokens: Token[]): number {
8
8
  let open = 0
9
9
  let unclosed = 0
10
10
  for (const token of tokens) {
11
- if (tokenMatcher(token, t.PAREN_R)) {
11
+ if (token.type === $T.PAREN_R) {
12
12
  if (open > 0) {
13
13
  open--
14
14
  } else {
15
15
  unclosed++
16
16
  }
17
- } else if (tokenMatcher(token, t.PAREN_L)) {
17
+ } else if (token.type === $T.PAREN_L) {
18
18
  open++
19
19
  }
20
20
  }
@@ -1,4 +1,4 @@
1
- /* Autogenerated Index */
1
+ /* Autogenerated Index [Ignore] */
2
2
 
3
3
  export { assignParents } from "./assignParents.js"
4
4
  export { checkParserOpts } from "./checkParserOpts.js"
@@ -6,7 +6,7 @@ import { defaultValueComparer } from "../general/defaultValueComparer.js"
6
6
 
7
7
  /** @internal */
8
8
  export function parseParserOptions<T extends {} = {}>(
9
- options: ParserOptions<T>
9
+ options: ParserOptions<T>,
10
10
  ): FullParserOptions<T> {
11
11
  const opts: ParserOptions = {
12
12
  prefixApplier: defaultPrefixApplier,
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /* Manually Generated Index */
2
+
2
3
  export * as ast from "./ast/classes/index.js"
3
- export * as grammar from "./grammar/index.js"
4
- export { Parser } from "./parser.js"
4
+ export { Parser } from "./Parser.js"
5
5
  export * from "./types/index.js"
6
6
  export * as utils from "./utils/index.js"
7
7
 
@@ -1,8 +1,8 @@
1
- import { unreachable } from "@alanscodelog/utils"
1
+ import { unreachable } from "@alanscodelog/utils/unreachable"
2
2
 
3
3
  import { ConditionNode } from "../ast/classes/ConditionNode.js"
4
4
  import { VariableNode } from "../ast/classes/VariableNode.js"
5
- import type { Parser } from "../parser.js"
5
+ import type { Parser } from "../Parser.js"
6
6
  import { type Completion, type Suggestion, SUGGESTION_TYPE } from "../types/autocomplete.js"
7
7
  import type { FullParserOptions } from "../types/parser.js"
8
8
 
@@ -30,9 +30,9 @@ export class AutocompleteMixin<T extends {}> {
30
30
  "regexFlags" |
31
31
  "expandedPropertyOperators" |
32
32
  "customPropertyOperators", string[]>> & {
33
- quote?: string
34
- keywords?: FullParserOptions<T>["keywords"]
35
- } = {}
33
+ quote?: string
34
+ keywords?: FullParserOptions<T>["keywords"]
35
+ } = {},
36
36
  ): Completion[] {
37
37
  const self = (this as any as Parser<T>)
38
38
  return suggestions.map(suggestion => {
@@ -1,4 +1,4 @@
1
- import { insert } from "@alanscodelog/utils"
1
+ import { insert } from "@alanscodelog/utils/insert"
2
2
 
3
3
  import type { Completion } from "../types/autocomplete.js"
4
4
 
@@ -11,7 +11,7 @@ export class AutoreplaceMixin {
11
11
  */
12
12
  autoreplace(
13
13
  input: string,
14
- { value, suggestion }: Completion
14
+ { value, suggestion }: Completion,
15
15
  ): { replacement: string, cursor: number } {
16
16
  const isQuotedLeft = ["\"", "'", "`"].includes(value[0])
17
17
  const isQuotedRight = ["\"", "'", "`"].includes(value[value.length - 1])
@@ -1,5 +1,5 @@
1
- import type { DeepPartial } from "@alanscodelog/utils"
2
- import { unreachable } from "@alanscodelog/utils"
1
+ import type { DeepPartial } from "@alanscodelog/utils/types"
2
+ import { unreachable } from "@alanscodelog/utils/unreachable"
3
3
 
4
4
  import { pos } from "../ast/builders/pos.js"
5
5
  import { ArrayNode } from "../ast/classes/ArrayNode.js"
@@ -8,7 +8,7 @@ import { ErrorToken } from "../ast/classes/ErrorToken.js"
8
8
  import { GroupNode } from "../ast/classes/GroupNode.js"
9
9
  import type { ValidToken } from "../ast/classes/ValidToken.js"
10
10
  import { VariableNode } from "../ast/classes/VariableNode.js"
11
- import type { Parser } from "../parser.js"
11
+ import type { Parser } from "../Parser.js"
12
12
  import { type ParserResults, TOKEN_TYPE } from "../types/ast.js"
13
13
  import { type Suggestion, SUGGESTION_TYPE } from "../types/autocomplete.js"
14
14
  import type { KeywordEntry } from "../types/parser.js"
@@ -1,8 +1,10 @@
1
- import { type AddParameters, get, unreachable } from "@alanscodelog/utils"
1
+ import { get } from "@alanscodelog/utils/get"
2
+ import { type AddParameters } from "@alanscodelog/utils/types"
3
+ import { unreachable } from "@alanscodelog/utils/unreachable"
2
4
 
3
5
  import { Condition } from "../ast/classes/Condition.js"
4
6
  import { Expression } from "../ast/classes/Expression.js"
5
- import type { Parser } from "../parser.js"
7
+ import type { Parser } from "../Parser.js"
6
8
  import { TOKEN_TYPE } from "../types/ast.js"
7
9
 
8
10
 
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable no-labels */
2
2
 
3
- import { type AddParameters, unreachable } from "@alanscodelog/utils"
3
+ import { type AddParameters } from "@alanscodelog/utils/types"
4
+ import { unreachable } from "@alanscodelog/utils/unreachable"
4
5
 
5
6
  import { Condition } from "../ast/classes/Condition.js"
6
7
  import { Expression } from "../ast/classes/Expression.js"
@@ -1,4 +1,5 @@
1
- import { type AddParameters, unreachable } from "@alanscodelog/utils"
1
+ import { type AddParameters } from "@alanscodelog/utils/types"
2
+ import { unreachable } from "@alanscodelog/utils/unreachable"
2
3
 
3
4
  import { ArrayNode } from "../ast/classes/ArrayNode.js"
4
5
  import { Condition } from "../ast/classes/Condition.js"
@@ -11,7 +12,7 @@ import { ValidToken } from "../ast/classes/ValidToken.js"
11
12
  import { VariableNode } from "../ast/classes/VariableNode.js"
12
13
  import { applyBoolean } from "../helpers/general/applyBoolean.js"
13
14
  import { applyPrefix } from "../helpers/general/applyPrefix.js"
14
- import type { Parser } from "../parser.js"
15
+ import type { Parser } from "../Parser.js"
15
16
  import { type ParserResults, TOKEN_TYPE, type TokenBooleanTypes } from "../types/ast.js"
16
17
  import type { ValueQuery } from "../types/parser.js"
17
18
 
@@ -24,8 +25,6 @@ const OPPOSITE = {
24
25
  export class NormalizeMixin<T extends {}> {
25
26
  /**
26
27
  * Normalizes the ast by applying {@link GroupNode GroupNodes} and converting {@link ConditionNode ConditionNodes} to {@link NormalizedConditionNode NormalizedConditionNodes}.
27
- *
28
- * To do this, a
29
28
  */
30
29
  normalize<TType extends string, TValue>(ast: ParserResults): Condition<TType, TValue> | Expression<TType, TValue> {
31
30
  // @ts-expect-error private method
@@ -1,4 +1,6 @@
1
- import { type AddParameters, get, isArray } from "@alanscodelog/utils"
1
+ import { get } from "@alanscodelog/utils/get"
2
+ import { isArray } from "@alanscodelog/utils/isArray"
3
+ import { type AddParameters } from "@alanscodelog/utils/types"
2
4
 
3
5
  import { ArrayNode } from "../ast/classes/ArrayNode.js"
4
6
  import { ConditionNode } from "../ast/classes/ConditionNode.js"
@@ -9,7 +11,7 @@ import { ValidToken } from "../ast/classes/ValidToken.js"
9
11
  import { VariableNode } from "../ast/classes/VariableNode.js"
10
12
  import { applyBoolean } from "../helpers/general/applyBoolean.js"
11
13
  import { applyPrefix } from "../helpers/general/applyPrefix.js"
12
- import type { Parser } from "../parser.js"
14
+ import type { Parser } from "../Parser.js"
13
15
  import { type ParserResults, type Position, TOKEN_TYPE } from "../types/ast.js"
14
16
  import type { ValidationQuery } from "../types/parser.js"
15
17
 
package/src/types/ast.ts CHANGED
@@ -1,13 +1,6 @@
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"
1
+ import type { AnyFunction } from "@alanscodelog/utils/types"
10
2
 
3
+ import type { ArrayNode, ConditionNode, ErrorToken, ExpressionNode, GroupNode, ValidToken, VariableNode } from "../ast/classes/index.js"
11
4
 
12
5
  export type AddParameters<T extends AnyFunction, TExtra extends any[] = [boolean]> = (...args: [...Parameters<T>, ...TExtra]) => ReturnType<T>
13
6