@witchcraft/expressit 0.2.2 → 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 +1 -2
- package/dist/Lexer.d.ts +99 -94
- package/dist/Lexer.d.ts.map +1 -1
- package/dist/Lexer.js +211 -559
- package/dist/Parser.d.ts +26 -26
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +2 -1
- 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 +2 -2
- 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 +1 -1
- package/dist/examples/ParserWithSqlSupport.d.ts +5 -5
- package/dist/examples/ParserWithSqlSupport.d.ts.map +1 -1
- package/dist/examples/ParserWithSqlSupport.js +2 -0
- 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/checkParserOpts.js +11 -11
- package/dist/package.json.js +2 -60
- 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 +3 -3
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +2 -0
- 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 +13 -13
- package/src/Lexer.ts +98 -88
- package/src/Parser.ts +61 -61
- package/src/ast/builders/condition.ts +3 -3
- package/src/ast/builders/delim.ts +4 -4
- 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 +20 -20
- package/src/examples/ParserWithSqlSupport.ts +11 -5
- package/src/internal/ExpressitError.ts +3 -3
- package/src/internal/checkParserOpts.ts +11 -11
- 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 +3 -3
- 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
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type EnumLike } from "@alanscodelog/utils"
|
|
2
|
+
import { enumFromArray } from "@alanscodelog/utils/enumFromArray.js"
|
|
3
|
+
|
|
1
4
|
import type { AnyToken, Position, ValidToken } from "./ast.js"
|
|
2
5
|
|
|
3
6
|
|
|
@@ -82,35 +85,36 @@ export type CursorInfo = {
|
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
export
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
REGEX_FLAGS = "REGEX_FLAGS",
|
|
88
|
+
export const SUGGESTION_TYPE = enumFromArray([
|
|
89
|
+
"VARIABLE",
|
|
90
|
+
"ARRAY_VALUE",
|
|
91
|
+
"VALUE",
|
|
92
|
+
"PREFIX",
|
|
93
|
+
"BOOLEAN_WORD_OP",
|
|
94
|
+
"BOOLEAN_SYMBOL_OP",
|
|
95
|
+
"BACKTICK",
|
|
96
|
+
"DOUBLEQUOTE",
|
|
97
|
+
"SINGLEQUOTE",
|
|
98
|
+
"PARENL",
|
|
99
|
+
"PARENR",
|
|
100
|
+
"PROPERTY",
|
|
101
|
+
"EXPANDED_PROPERTY_OPERATOR",
|
|
102
|
+
"CUSTOM_PROPERTY_OPERATOR",
|
|
103
|
+
"PROPERTY_SEP",
|
|
104
|
+
"BRAKCETR",
|
|
105
|
+
"REGEX",
|
|
106
|
+
"REGEX_FLAGS",
|
|
105
107
|
/** This is not an oversight, I haven't figured out a fast way to detect left bracket errors. */
|
|
106
108
|
// BRAKCETL = "BRAKCETL",
|
|
107
|
-
|
|
109
|
+
])
|
|
110
|
+
|
|
111
|
+
export type SuggestionType = EnumLike<typeof SUGGESTION_TYPE>
|
|
108
112
|
|
|
109
113
|
/**
|
|
110
114
|
* A suggestion entry that describes a type of suggestion.
|
|
111
115
|
*/
|
|
112
116
|
export type Suggestion = {
|
|
113
|
-
type:
|
|
117
|
+
type: SuggestionType
|
|
114
118
|
/** The range the suggestion should replace / be inserted at. */
|
|
115
119
|
range: Position
|
|
116
120
|
/** {@link CursorInfo} */
|
package/src/types/errors.ts
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
+
import { type EnumLike } from "@alanscodelog/utils"
|
|
2
|
+
import { enumFromArray } from "@alanscodelog/utils/enumFromArray.js"
|
|
3
|
+
|
|
1
4
|
import type { ParserOptions } from "./parser.js"
|
|
2
5
|
|
|
3
6
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export const PARSER_ERROR = enumFromArray([
|
|
8
|
+
"POSITION_ERROR",
|
|
9
|
+
"CONFLICTING_OPTIONS_ERROR",
|
|
10
|
+
"OPTION_REQUIRED_ERROR",
|
|
11
|
+
], "PARSER.")
|
|
12
|
+
|
|
13
|
+
export type ParserError = EnumLike<typeof PARSER_ERROR>
|
|
9
14
|
|
|
10
15
|
|
|
11
|
-
export type ErrorInfo<T extends
|
|
12
|
-
T extends
|
|
13
|
-
?
|
|
16
|
+
export type ErrorInfo<T extends ParserError> =
|
|
17
|
+
T extends ParserError
|
|
18
|
+
? ErrorCodesInfo[T]
|
|
14
19
|
: never
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
export type
|
|
18
|
-
[
|
|
21
|
+
|
|
22
|
+
export type ErrorCodesInfo = {
|
|
23
|
+
[PARSER_ERROR.POSITION_ERROR]: {
|
|
19
24
|
start?: number
|
|
20
25
|
end?: number
|
|
21
26
|
}
|
|
22
|
-
[
|
|
27
|
+
[PARSER_ERROR.CONFLICTING_OPTIONS_ERROR]: {
|
|
23
28
|
prohibited: string[]
|
|
24
29
|
invalid: string
|
|
25
30
|
}
|
|
26
|
-
[
|
|
31
|
+
[PARSER_ERROR.OPTION_REQUIRED_ERROR]: {
|
|
27
32
|
options?: (keyof ParserOptions)[]
|
|
28
33
|
requires: keyof ParserOptions
|
|
29
34
|
}
|
package/src/types/parser.ts
CHANGED
|
@@ -443,9 +443,9 @@ export type ValueQuery
|
|
|
443
443
|
/** {@link ParserOptions}["valueValidator"] */
|
|
444
444
|
export type ValidationQuery = Omit<ValueQuery, "value" | "operator" | "prefix" | "regexFlags" | "property"> & {
|
|
445
445
|
value?: VariableNode | ArrayNode
|
|
446
|
-
operator?: ValidToken<TOKEN_TYPE.VALUE | TOKEN_TYPE.OP_CUSTOM>
|
|
447
|
-
prefix?: ValidToken<TOKEN_TYPE.VALUE>
|
|
448
|
-
regexFlags?: ValidToken<TOKEN_TYPE.VALUE>
|
|
446
|
+
operator?: ValidToken<typeof TOKEN_TYPE.VALUE | typeof TOKEN_TYPE.OP_CUSTOM>
|
|
447
|
+
prefix?: ValidToken<typeof TOKEN_TYPE.VALUE>
|
|
448
|
+
regexFlags?: ValidToken<typeof TOKEN_TYPE.VALUE>
|
|
449
449
|
property: VariableNode[]
|
|
450
450
|
/** The property as would be passed to the {@link ParserOptions}["valueComparer"] function (i.e. joined as a string using the {@link ParseOptions}["prefixApplier"] ) */
|
|
451
451
|
propertyName?: string
|
|
@@ -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
|
}
|