@witchcraft/expressit 0.2.1 → 0.3.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 (119) hide show
  1. package/README.md +6 -4
  2. package/dist/Lexer.d.ts +102 -99
  3. package/dist/Lexer.d.ts.map +1 -1
  4. package/dist/Lexer.js +211 -557
  5. package/dist/Parser.d.ts +27 -27
  6. package/dist/Parser.d.ts.map +1 -1
  7. package/dist/Parser.js +5 -2
  8. package/dist/ast/builders/condition.d.ts +1 -1
  9. package/dist/ast/builders/condition.d.ts.map +1 -1
  10. package/dist/ast/builders/condition.js +1 -0
  11. package/dist/ast/builders/delim.d.ts +3 -3
  12. package/dist/ast/builders/delim.d.ts.map +1 -1
  13. package/dist/ast/builders/error.d.ts +2 -2
  14. package/dist/ast/builders/error.d.ts.map +1 -1
  15. package/dist/ast/builders/expression.d.ts +2 -2
  16. package/dist/ast/builders/expression.d.ts.map +1 -1
  17. package/dist/ast/builders/expression.js +2 -6
  18. package/dist/ast/builders/group.d.ts +1 -1
  19. package/dist/ast/builders/group.d.ts.map +1 -1
  20. package/dist/ast/builders/group.js +1 -3
  21. package/dist/ast/builders/pos.d.ts +2 -2
  22. package/dist/ast/builders/pos.d.ts.map +1 -1
  23. package/dist/ast/builders/token.d.ts +2 -2
  24. package/dist/ast/builders/token.d.ts.map +1 -1
  25. package/dist/ast/builders/type.d.ts +2 -2
  26. package/dist/ast/builders/type.d.ts.map +1 -1
  27. package/dist/ast/builders/variable.d.ts +3 -3
  28. package/dist/ast/builders/variable.d.ts.map +1 -1
  29. package/dist/ast/createConditionNode.d.ts +1 -1
  30. package/dist/ast/createConditionNode.d.ts.map +1 -1
  31. package/dist/ast/createGroupNode.d.ts +1 -1
  32. package/dist/ast/createGroupNode.d.ts.map +1 -1
  33. package/dist/ast/createToken.d.ts +2 -2
  34. package/dist/ast/createToken.d.ts.map +1 -1
  35. package/dist/ast/createToken.js +2 -2
  36. package/dist/ast/error.d.ts +2 -2
  37. package/dist/ast/error.d.ts.map +1 -1
  38. package/dist/ast/error.js +1 -0
  39. package/dist/ast/handlers.d.ts +23 -23
  40. package/dist/ast/handlers.d.ts.map +1 -1
  41. package/dist/ast/handlers.js +4 -4
  42. package/dist/examples/ParserWithSqlSupport.d.ts +62 -0
  43. package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -0
  44. package/dist/examples/ParserWithSqlSupport.js +271 -0
  45. package/dist/examples/{shortcutContextParser.d.ts → ShortcutContextParser.d.ts} +5 -5
  46. package/dist/examples/ShortcutContextParser.d.ts.map +1 -0
  47. package/dist/examples/{shortcutContextParser.js → ShortcutContextParser.js} +2 -2
  48. package/dist/examples/index.d.ts +2 -1
  49. package/dist/examples/index.d.ts.map +1 -1
  50. package/dist/examples/index.js +3 -1
  51. package/dist/index.js +2 -2
  52. package/dist/internal/ExpressitError.d.ts +2 -2
  53. package/dist/internal/ExpressitError.d.ts.map +1 -1
  54. package/dist/internal/ExpressitError.js +2 -1
  55. package/dist/internal/checkParserOpts.d.ts +1 -1
  56. package/dist/internal/checkParserOpts.d.ts.map +1 -1
  57. package/dist/internal/checkParserOpts.js +11 -11
  58. package/dist/internal/parseParserOptions.d.ts +1 -1
  59. package/dist/internal/parseParserOptions.d.ts.map +1 -1
  60. package/dist/package.json.js +4 -195
  61. package/dist/types/ast.d.ts +60 -58
  62. package/dist/types/ast.d.ts.map +1 -1
  63. package/dist/types/ast.js +26 -27
  64. package/dist/types/autocomplete.d.ts +23 -21
  65. package/dist/types/autocomplete.d.ts.map +1 -1
  66. package/dist/types/autocomplete.js +24 -21
  67. package/dist/types/errors.d.ts +12 -10
  68. package/dist/types/errors.d.ts.map +1 -1
  69. package/dist/types/errors.js +8 -7
  70. package/dist/types/index.js +2 -2
  71. package/dist/types/parser.d.ts +9 -9
  72. package/dist/types/parser.d.ts.map +1 -1
  73. package/dist/utils/getCursorInfo.js +3 -1
  74. package/dist/utils/getOppositeDelimiter.d.ts +2 -2
  75. package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
  76. package/dist/utils/isDelimiter.d.ts +2 -2
  77. package/dist/utils/isDelimiter.d.ts.map +1 -1
  78. package/dist/utils/isParen.d.ts +2 -2
  79. package/dist/utils/isParen.d.ts.map +1 -1
  80. package/dist/utils/isQuote.d.ts +2 -2
  81. package/dist/utils/isQuote.d.ts.map +1 -1
  82. package/package.json +29 -27
  83. package/src/Lexer.ts +103 -92
  84. package/src/Parser.ts +70 -64
  85. package/src/ast/builders/condition.ts +3 -3
  86. package/src/ast/builders/delim.ts +5 -5
  87. package/src/ast/builders/error.ts +3 -3
  88. package/src/ast/builders/expression.ts +4 -8
  89. package/src/ast/builders/group.ts +2 -4
  90. package/src/ast/builders/pos.ts +3 -3
  91. package/src/ast/builders/token.ts +2 -2
  92. package/src/ast/builders/type.ts +2 -2
  93. package/src/ast/builders/variable.ts +5 -5
  94. package/src/ast/createConditionNode.ts +2 -2
  95. package/src/ast/createGroupNode.ts +4 -4
  96. package/src/ast/createToken.ts +6 -6
  97. package/src/ast/error.ts +2 -2
  98. package/src/ast/handlers.ts +23 -23
  99. package/src/examples/ParserWithSqlSupport.ts +371 -0
  100. package/src/examples/{shortcutContextParser.ts → ShortcutContextParser.ts} +14 -14
  101. package/src/examples/index.ts +2 -1
  102. package/src/internal/ExpressitError.ts +4 -4
  103. package/src/internal/checkParserOpts.ts +14 -14
  104. package/src/internal/parseParserOptions.ts +2 -2
  105. package/src/types/ast.ts +101 -96
  106. package/src/types/autocomplete.ts +26 -22
  107. package/src/types/errors.ts +18 -13
  108. package/src/types/parser.ts +9 -9
  109. package/src/utils/getCursorInfo.ts +1 -1
  110. package/src/utils/getOppositeDelimiter.ts +2 -2
  111. package/src/utils/getSurroundingErrors.ts +4 -4
  112. package/src/utils/isDelimiter.ts +3 -3
  113. package/src/utils/isParen.ts +2 -2
  114. package/src/utils/isQuote.ts +2 -2
  115. package/dist/examples/shortcutContextParser.d.ts.map +0 -1
  116. package/dist/global.d.js +0 -1
  117. package/dist/package.js +0 -7
  118. package/src/global.d.ts +0 -4
  119. package/src/package.js +0 -11
@@ -6,7 +6,7 @@ import { isDelimiter } from "./isDelimiter.js"
6
6
  import { isParen } from "./isParen.js"
7
7
  import { isQuote } from "./isQuote.js"
8
8
 
9
- import { type AnyToken, type ArrayNode, type ConditionNode,type GroupNode, TOKEN_TYPE, type TokenDelimiterTypes, type VariableNode } from "../types/ast.js"
9
+ import { type AnyToken, type ArrayNode, type ConditionNode,type GroupNode, TOKEN_TYPE, type TokenDelimiter, type VariableNode } from "../types/ast.js"
10
10
 
11
11
  /**
12
12
  * Given a delimiter token, returns it's opposite pair, or undefined if the type passed was not a delimiter token (so you can pass any type without checking).
@@ -14,7 +14,7 @@ import { type AnyToken, type ArrayNode, type ConditionNode,type GroupNode, TOKEN
14
14
  export function getOppositeDelimiter(
15
15
  token: AnyToken,
16
16
  parentsMap: ReturnType<typeof generateParentsMap>
17
- ): AnyToken<TokenDelimiterTypes> | undefined {
17
+ ): AnyToken<TokenDelimiter> | undefined {
18
18
  const parent = parentsMap.get(token)
19
19
  if (!isDelimiter(token)) throw new Error("Token is not a delimiter type.")
20
20
  if (isParen(token)) {
@@ -43,10 +43,10 @@ export function getSurroundingErrors(tokens: AnyToken[], token: CursorInfo): Err
43
43
  }
44
44
 
45
45
  return errors.sort((a, b) => {
46
- const aIsQuote = [TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.BACKTICK, TOKEN_TYPE.SINGLEQUOTE].includes(a.expected[0])
47
- const bIsQuote = [TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.BACKTICK, TOKEN_TYPE.SINGLEQUOTE].includes(b.expected[0])
48
- const aIsParen = [TOKEN_TYPE.PARENR, TOKEN_TYPE.PARENL].includes(a.expected[0])
49
- const bIsParen = [TOKEN_TYPE.PARENR, TOKEN_TYPE.PARENL].includes(b.expected[0])
46
+ const aIsQuote = ([TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.BACKTICK, TOKEN_TYPE.SINGLEQUOTE] as string[]).includes(a.expected[0])
47
+ const bIsQuote = ([TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.BACKTICK, TOKEN_TYPE.SINGLEQUOTE]as string[]).includes(b.expected[0])
48
+ const aIsParen = ([TOKEN_TYPE.PARENR, TOKEN_TYPE.PARENL] as string[]).includes(a.expected[0])
49
+ const bIsParen = ([TOKEN_TYPE.PARENR, TOKEN_TYPE.PARENL] as string[]).includes(b.expected[0])
50
50
  const aCloseness = Math.abs(i - tokens.indexOf(a))
51
51
  const bCloseness = Math.abs(i - tokens.indexOf(b))
52
52
  const closenessComparison = aCloseness - bCloseness
@@ -1,9 +1,9 @@
1
- import { type AnyToken, TOKEN_TYPE, type TokenDelimiterTypes } from "../types/ast.js"
1
+ import { type AnyToken, TOKEN_TYPE, type TokenDelimiter } from "../types/ast.js"
2
2
 
3
3
  /**
4
4
  * Returns whether token is a delimiter type (including if it's an expanded operator separator).
5
5
  */
6
- export function isDelimiter(token?: AnyToken): token is AnyToken<TokenDelimiterTypes> {
6
+ export function isDelimiter(token?: AnyToken): token is AnyToken<TokenDelimiter> {
7
7
  return ([
8
8
  TOKEN_TYPE.BACKTICK,
9
9
  TOKEN_TYPE.DOUBLEQUOTE,
@@ -14,5 +14,5 @@ export function isDelimiter(token?: AnyToken): token is AnyToken<TokenDelimiterT
14
14
  TOKEN_TYPE.BRACKETR,
15
15
  TOKEN_TYPE.OP_EXPANDED_SEP,
16
16
  TOKEN_TYPE.REGEX,
17
- ] as TokenDelimiterTypes[]).includes(token?.type as TokenDelimiterTypes)
17
+ ] as TokenDelimiter[]).includes(token?.type as TokenDelimiter)
18
18
  }
@@ -1,6 +1,6 @@
1
- import { type AnyToken, TOKEN_TYPE, type TokenParenTypes } from "../types/ast.js"
1
+ import { type AnyToken, TOKEN_TYPE, type TokenParen } from "../types/ast.js"
2
2
 
3
3
 
4
- export function isParen(token?: AnyToken): token is AnyToken<TokenParenTypes> {
4
+ export function isParen(token?: AnyToken): token is AnyToken<TokenParen> {
5
5
  return ([TOKEN_TYPE.PARENL, TOKEN_TYPE.PARENR] as any[]).includes(token?.type)
6
6
  }
@@ -1,6 +1,6 @@
1
- import { type AnyToken, TOKEN_TYPE, type TokenQuoteTypes } from "../types/ast.js"
1
+ import { type AnyToken, TOKEN_TYPE, type TokenQuote } from "../types/ast.js"
2
2
 
3
3
  /** Returns if the token is a quote token. This includes regex delimiters. */
4
- export function isQuote(token?: AnyToken): token is AnyToken<TokenQuoteTypes> {
4
+ export function isQuote(token?: AnyToken): token is AnyToken<TokenQuote> {
5
5
  return ([TOKEN_TYPE.BACKTICK, TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.SINGLEQUOTE, TOKEN_TYPE.REGEX] as any[]).includes(token?.type)
6
6
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"shortcutContextParser.d.ts","sourceRoot":"","sources":["../../src/examples/shortcutContextParser.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAI/C,qBAAa,qBAAqB,CAAC,CAAC,SACnC,QAAQ,GAAG;IAAE,IAAI,EAAE,CAAC,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC,CAAA;CAAE,GAClG,QAAQ,GAAG;IAAE,IAAI,EAAE,CAAC,YAAY,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC,CAAA;CAAE,CACjG,SAAQ,MAAM,CAAC,CAAC,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAK;IAExB,aAAa,EAAE,MAAM,EAAE,CAAK;gBAG3B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,eAAe,GAAE,MAAM,EAAoB;IAmG5C,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAK9C,OAAO,CAAC,uBAAuB;CAa/B"}
package/dist/global.d.js DELETED
@@ -1 +0,0 @@
1
-
package/dist/package.js DELETED
@@ -1,7 +0,0 @@
1
- import pkg from "./package.json.js";
2
- const version = pkg.version;
3
- const repository = pkg.repository;
4
- export {
5
- repository,
6
- version
7
- };
package/src/global.d.ts DELETED
@@ -1,4 +0,0 @@
1
- declare module "./package.js" {
2
- export const version: string
3
- export const repository: string
4
- }
package/src/package.js DELETED
@@ -1,11 +0,0 @@
1
- import pkg from "../package.json"
2
-
3
- /**
4
- * This library imports it's own package.json for inserting the version number into errors. Doing this is not a problem normally (because babel is used to transpile the typescript instead of tsc), but when tsc is used to output the types, the output is nested (dist-types/src/*) because of the json import being outside the src dir. There is a way around this but it's complicated. The easier way is to just cheat and do the importing in this js file. Typescript consumes it none the wiser and babel transpiles it to cjs/es accordingly.
5
- *
6
- * The values could be inlined, but there are no battle tested actively maintained babel plugins for this, and problems would be hard to debug (given when developing, the package.json never contains the real version because the library is semantically released.)
7
- */
8
-
9
-
10
- export const version = pkg.version
11
- export const repository = pkg.repository