@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.
- package/README.md +6 -4
- package/dist/Lexer.d.ts +102 -99
- package/dist/Lexer.d.ts.map +1 -1
- package/dist/Lexer.js +211 -557
- package/dist/Parser.d.ts +27 -27
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +5 -2
- package/dist/ast/builders/condition.d.ts +1 -1
- package/dist/ast/builders/condition.d.ts.map +1 -1
- package/dist/ast/builders/condition.js +1 -0
- package/dist/ast/builders/delim.d.ts +3 -3
- package/dist/ast/builders/delim.d.ts.map +1 -1
- package/dist/ast/builders/error.d.ts +2 -2
- package/dist/ast/builders/error.d.ts.map +1 -1
- package/dist/ast/builders/expression.d.ts +2 -2
- package/dist/ast/builders/expression.d.ts.map +1 -1
- package/dist/ast/builders/expression.js +2 -6
- package/dist/ast/builders/group.d.ts +1 -1
- package/dist/ast/builders/group.d.ts.map +1 -1
- package/dist/ast/builders/group.js +1 -3
- package/dist/ast/builders/pos.d.ts +2 -2
- package/dist/ast/builders/pos.d.ts.map +1 -1
- package/dist/ast/builders/token.d.ts +2 -2
- package/dist/ast/builders/token.d.ts.map +1 -1
- package/dist/ast/builders/type.d.ts +2 -2
- package/dist/ast/builders/type.d.ts.map +1 -1
- package/dist/ast/builders/variable.d.ts +3 -3
- package/dist/ast/builders/variable.d.ts.map +1 -1
- package/dist/ast/createConditionNode.d.ts +1 -1
- package/dist/ast/createConditionNode.d.ts.map +1 -1
- package/dist/ast/createGroupNode.d.ts +1 -1
- package/dist/ast/createGroupNode.d.ts.map +1 -1
- package/dist/ast/createToken.d.ts +2 -2
- package/dist/ast/createToken.d.ts.map +1 -1
- package/dist/ast/createToken.js +2 -2
- package/dist/ast/error.d.ts +2 -2
- package/dist/ast/error.d.ts.map +1 -1
- package/dist/ast/error.js +1 -0
- package/dist/ast/handlers.d.ts +23 -23
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +4 -4
- package/dist/examples/ParserWithSqlSupport.d.ts +62 -0
- package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -0
- package/dist/examples/ParserWithSqlSupport.js +271 -0
- package/dist/examples/{shortcutContextParser.d.ts → ShortcutContextParser.d.ts} +5 -5
- package/dist/examples/ShortcutContextParser.d.ts.map +1 -0
- package/dist/examples/{shortcutContextParser.js → ShortcutContextParser.js} +2 -2
- package/dist/examples/index.d.ts +2 -1
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +3 -1
- package/dist/index.js +2 -2
- package/dist/internal/ExpressitError.d.ts +2 -2
- package/dist/internal/ExpressitError.d.ts.map +1 -1
- package/dist/internal/ExpressitError.js +2 -1
- package/dist/internal/checkParserOpts.d.ts +1 -1
- package/dist/internal/checkParserOpts.d.ts.map +1 -1
- package/dist/internal/checkParserOpts.js +11 -11
- package/dist/internal/parseParserOptions.d.ts +1 -1
- package/dist/internal/parseParserOptions.d.ts.map +1 -1
- package/dist/package.json.js +4 -195
- package/dist/types/ast.d.ts +60 -58
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +26 -27
- package/dist/types/autocomplete.d.ts +23 -21
- package/dist/types/autocomplete.d.ts.map +1 -1
- package/dist/types/autocomplete.js +24 -21
- package/dist/types/errors.d.ts +12 -10
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +8 -7
- package/dist/types/index.js +2 -2
- package/dist/types/parser.d.ts +9 -9
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +3 -1
- package/dist/utils/getOppositeDelimiter.d.ts +2 -2
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/isDelimiter.d.ts +2 -2
- package/dist/utils/isDelimiter.d.ts.map +1 -1
- package/dist/utils/isParen.d.ts +2 -2
- package/dist/utils/isParen.d.ts.map +1 -1
- package/dist/utils/isQuote.d.ts +2 -2
- package/dist/utils/isQuote.d.ts.map +1 -1
- package/package.json +29 -27
- package/src/Lexer.ts +103 -92
- package/src/Parser.ts +70 -64
- package/src/ast/builders/condition.ts +3 -3
- package/src/ast/builders/delim.ts +5 -5
- package/src/ast/builders/error.ts +3 -3
- package/src/ast/builders/expression.ts +4 -8
- package/src/ast/builders/group.ts +2 -4
- package/src/ast/builders/pos.ts +3 -3
- package/src/ast/builders/token.ts +2 -2
- package/src/ast/builders/type.ts +2 -2
- package/src/ast/builders/variable.ts +5 -5
- package/src/ast/createConditionNode.ts +2 -2
- package/src/ast/createGroupNode.ts +4 -4
- package/src/ast/createToken.ts +6 -6
- package/src/ast/error.ts +2 -2
- package/src/ast/handlers.ts +23 -23
- package/src/examples/ParserWithSqlSupport.ts +371 -0
- package/src/examples/{shortcutContextParser.ts → ShortcutContextParser.ts} +14 -14
- package/src/examples/index.ts +2 -1
- package/src/internal/ExpressitError.ts +4 -4
- package/src/internal/checkParserOpts.ts +14 -14
- package/src/internal/parseParserOptions.ts +2 -2
- package/src/types/ast.ts +101 -96
- package/src/types/autocomplete.ts +26 -22
- package/src/types/errors.ts +18 -13
- package/src/types/parser.ts +9 -9
- package/src/utils/getCursorInfo.ts +1 -1
- package/src/utils/getOppositeDelimiter.ts +2 -2
- package/src/utils/getSurroundingErrors.ts +4 -4
- package/src/utils/isDelimiter.ts +3 -3
- package/src/utils/isParen.ts +2 -2
- package/src/utils/isQuote.ts +2 -2
- package/dist/examples/shortcutContextParser.d.ts.map +0 -1
- package/dist/global.d.js +0 -1
- package/dist/package.js +0 -7
- package/src/global.d.ts +0 -4
- 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
|
|
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<
|
|
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
|
package/src/utils/isDelimiter.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type AnyToken, TOKEN_TYPE, type
|
|
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<
|
|
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
|
|
17
|
+
] as TokenDelimiter[]).includes(token?.type as TokenDelimiter)
|
|
18
18
|
}
|
package/src/utils/isParen.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type AnyToken, TOKEN_TYPE, type
|
|
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<
|
|
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
|
}
|
package/src/utils/isQuote.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type AnyToken, TOKEN_TYPE, type
|
|
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<
|
|
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
package/src/global.d.ts
DELETED
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
|