@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.
- package/README.md +9 -5
- package/dist/Lexer.js +2 -2
- package/dist/Parser.d.ts +14 -29
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +120 -135
- package/dist/ast/builders/array.d.ts +1 -3
- package/dist/ast/builders/array.d.ts.map +1 -1
- package/dist/ast/builders/array.js +3 -5
- package/dist/ast/builders/condition.d.ts +5 -11
- package/dist/ast/builders/condition.d.ts.map +1 -1
- package/dist/ast/builders/condition.js +2 -3
- package/dist/ast/builders/delim.d.ts +1 -1
- package/dist/ast/builders/error.d.ts +3 -4
- package/dist/ast/builders/error.d.ts.map +1 -1
- package/dist/ast/builders/error.js +6 -2
- package/dist/ast/builders/expression.d.ts +3 -7
- package/dist/ast/builders/expression.d.ts.map +1 -1
- package/dist/ast/builders/expression.js +3 -5
- package/dist/ast/builders/group.d.ts +3 -8
- package/dist/ast/builders/group.d.ts.map +1 -1
- package/dist/ast/builders/group.js +3 -3
- package/dist/ast/builders/pos.d.ts +1 -2
- package/dist/ast/builders/pos.d.ts.map +1 -1
- package/dist/ast/builders/token.d.ts +3 -5
- package/dist/ast/builders/token.d.ts.map +1 -1
- package/dist/ast/builders/token.js +3 -4
- package/dist/ast/builders/type.d.ts +1 -1
- package/dist/ast/builders/variable.d.ts +3 -5
- package/dist/ast/builders/variable.d.ts.map +1 -1
- package/dist/ast/builders/variable.js +2 -3
- package/dist/ast/createArrayNode.d.ts +3 -0
- package/dist/ast/createArrayNode.d.ts.map +1 -0
- package/dist/ast/createArrayNode.js +12 -0
- package/dist/ast/createConditionNode.d.ts +11 -0
- package/dist/ast/createConditionNode.d.ts.map +1 -0
- package/dist/ast/createConditionNode.js +18 -0
- package/dist/ast/createExpressionNode.d.ts +3 -0
- package/dist/ast/createExpressionNode.d.ts.map +1 -0
- package/dist/ast/createExpressionNode.js +14 -0
- package/dist/ast/createGroupNode.d.ts +5 -0
- package/dist/ast/createGroupNode.d.ts.map +1 -0
- package/dist/ast/createGroupNode.js +14 -0
- package/dist/ast/createNormalizedCondition.d.ts +3 -0
- package/dist/ast/createNormalizedCondition.d.ts.map +1 -0
- package/dist/ast/createNormalizedCondition.js +10 -0
- package/dist/ast/createNormalizedExpression.d.ts +3 -0
- package/dist/ast/createNormalizedExpression.d.ts.map +1 -0
- package/dist/ast/createNormalizedExpression.js +10 -0
- package/dist/ast/createToken.d.ts +6 -0
- package/dist/ast/createToken.d.ts.map +1 -0
- package/dist/ast/createToken.js +15 -0
- package/dist/ast/createVariableNode.d.ts +3 -0
- package/dist/ast/createVariableNode.d.ts.map +1 -0
- package/dist/ast/createVariableNode.js +12 -0
- package/dist/ast/error.d.ts +3 -0
- package/dist/ast/error.d.ts.map +1 -0
- package/dist/ast/error.js +9 -0
- package/dist/ast/handlers.d.ts +5 -12
- package/dist/ast/handlers.d.ts.map +1 -1
- package/dist/ast/handlers.js +21 -29
- package/dist/ast/index.d.ts +9 -1
- package/dist/ast/index.d.ts.map +1 -1
- package/dist/ast/index.js +18 -2
- package/dist/defaults/defaultConditionNormalizer.d.ts +3 -0
- package/dist/defaults/defaultConditionNormalizer.d.ts.map +1 -0
- package/dist/defaults/defaultKeyParser.d.ts +3 -0
- package/dist/defaults/defaultKeyParser.d.ts.map +1 -0
- package/dist/defaults/defaultPrefixApplier.d.ts +3 -0
- package/dist/defaults/defaultPrefixApplier.d.ts.map +1 -0
- package/dist/defaults/defaultValueComparer.d.ts +3 -0
- package/dist/defaults/defaultValueComparer.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.d.ts +0 -2
- package/dist/defaults/index.d.ts.map +1 -0
- package/dist/{helpers/general → defaults}/index.js +0 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/{helpers/errors.d.ts → internal/ExpressitError.d.ts} +3 -2
- package/dist/internal/ExpressitError.d.ts.map +1 -0
- package/dist/{helpers/errors.js → internal/ExpressitError.js} +2 -2
- package/dist/internal/applyBoolean.d.ts.map +1 -0
- package/dist/{helpers/general → internal}/applyPrefix.d.ts +1 -1
- package/dist/internal/applyPrefix.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.d.ts +2 -1
- package/dist/internal/checkParserOpts.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/checkParserOpts.js +14 -14
- package/dist/internal/escapeVariableOrPrefix.d.ts +2 -0
- package/dist/internal/escapeVariableOrPrefix.d.ts.map +1 -0
- package/dist/internal/escapeVariableOrPrefix.js +38 -0
- package/dist/internal/extractPosition.d.ts +5 -0
- package/dist/internal/extractPosition.d.ts.map +1 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts +4 -0
- package/dist/internal/getUnclosedRightParenCount.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/getUnclosedRightParenCount.js +1 -1
- package/dist/{helpers/parser → internal}/parseParserOptions.d.ts +1 -1
- package/dist/internal/parseParserOptions.d.ts.map +1 -0
- package/dist/{helpers/parser → internal}/parseParserOptions.js +4 -4
- package/dist/internal/unescape.d.ts.map +1 -0
- package/dist/package.json.js +7 -7
- package/dist/types/ast.d.ts +195 -6
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +2 -0
- package/dist/types/autocomplete.d.ts +5 -6
- package/dist/types/autocomplete.d.ts.map +1 -1
- package/dist/types/parser.d.ts +17 -22
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/utils/extractTokens.d.ts +2 -4
- package/dist/utils/extractTokens.d.ts.map +1 -1
- package/dist/utils/extractTokens.js +14 -18
- package/dist/utils/generateParentsMap.d.ts +10 -0
- package/dist/utils/generateParentsMap.d.ts.map +1 -0
- package/dist/utils/generateParentsMap.js +73 -0
- package/dist/utils/getCursorInfo.d.ts +1 -1
- package/dist/utils/getCursorInfo.d.ts.map +1 -1
- package/dist/utils/getCursorInfo.js +3 -5
- package/dist/utils/getOppositeDelimiter.d.ts +2 -1
- package/dist/utils/getOppositeDelimiter.d.ts.map +1 -1
- package/dist/utils/getOppositeDelimiter.js +6 -5
- package/dist/utils/getParent.d.ts +5 -0
- package/dist/utils/getParent.d.ts.map +1 -0
- package/dist/utils/getParent.js +6 -0
- package/dist/utils/getSurroundingErrors.d.ts +3 -4
- package/dist/utils/getSurroundingErrors.d.ts.map +1 -1
- package/dist/utils/getSurroundingErrors.js +3 -3
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -0
- package/dist/utils/isNode.d.ts +10 -0
- package/dist/utils/isNode.d.ts.map +1 -0
- package/dist/utils/isNode.js +6 -0
- package/dist/utils/isToken.d.ts +8 -0
- package/dist/utils/isToken.d.ts.map +1 -0
- package/dist/utils/isToken.js +6 -0
- package/dist/utils/prettyAst.d.ts +1 -2
- package/dist/utils/prettyAst.d.ts.map +1 -1
- package/dist/utils/prettyAst.js +19 -26
- package/package.json +7 -7
- package/src/Lexer.ts +2 -2
- package/src/Parser.ts +158 -165
- package/src/ast/builders/array.ts +4 -9
- package/src/ast/builders/condition.ts +10 -15
- package/src/ast/builders/delim.ts +1 -1
- package/src/ast/builders/error.ts +10 -6
- package/src/ast/builders/expression.ts +17 -23
- package/src/ast/builders/group.ts +7 -11
- package/src/ast/builders/pos.ts +2 -3
- package/src/ast/builders/token.ts +6 -7
- package/src/ast/builders/type.ts +1 -1
- package/src/ast/builders/variable.ts +6 -8
- package/src/ast/createArrayNode.ts +17 -0
- package/src/ast/createConditionNode.ts +58 -0
- package/src/ast/createExpressionNode.ts +21 -0
- package/src/ast/createGroupNode.ts +46 -0
- package/src/ast/createNormalizedCondition.ts +12 -0
- package/src/ast/createNormalizedExpression.ts +9 -0
- package/src/ast/createToken.ts +26 -0
- package/src/ast/createVariableNode.ts +18 -0
- package/src/ast/error.ts +9 -0
- package/src/ast/handlers.ts +26 -37
- package/src/ast/index.ts +9 -1
- package/src/{helpers/general → defaults}/defaultConditionNormalizer.ts +1 -1
- package/src/{helpers/general → defaults}/defaultKeyParser.ts +1 -1
- package/src/{helpers/general → defaults}/defaultPrefixApplier.ts +1 -1
- package/src/{helpers/general → defaults}/defaultValueComparer.ts +1 -1
- package/src/{helpers/general → defaults}/index.ts +0 -2
- package/src/index.ts +2 -1
- package/src/{helpers/errors.ts → internal/ExpressitError.ts} +2 -2
- package/src/{helpers/general → internal}/applyPrefix.ts +1 -1
- package/src/{helpers/parser → internal}/checkParserOpts.ts +16 -15
- package/src/internal/escapeVariableOrPrefix.ts +36 -0
- package/src/{helpers/parser → internal}/extractPosition.ts +2 -2
- package/src/{helpers/parser → internal}/getUnclosedRightParenCount.ts +1 -2
- package/src/{helpers/parser → internal}/parseParserOptions.ts +5 -5
- package/src/types/ast.ts +292 -7
- package/src/types/autocomplete.ts +5 -7
- package/src/types/parser.ts +17 -22
- package/src/utils/extractTokens.ts +16 -20
- package/src/utils/generateParentsMap.ts +60 -0
- package/src/utils/getCursorInfo.ts +4 -6
- package/src/utils/getOppositeDelimiter.ts +11 -10
- package/src/utils/getParent.ts +16 -0
- package/src/utils/getSurroundingErrors.ts +10 -9
- package/src/utils/index.ts +4 -0
- package/src/utils/isNode.ts +12 -0
- package/src/utils/isToken.ts +10 -0
- package/src/utils/prettyAst.ts +20 -17
- package/dist/ast/classes/ArrayNode.d.ts +0 -18
- package/dist/ast/classes/ArrayNode.d.ts.map +0 -1
- package/dist/ast/classes/ArrayNode.js +0 -55
- package/dist/ast/classes/Condition.d.ts +0 -13
- package/dist/ast/classes/Condition.d.ts.map +0 -1
- package/dist/ast/classes/Condition.js +0 -21
- package/dist/ast/classes/ConditionNode.d.ts +0 -73
- package/dist/ast/classes/ConditionNode.d.ts.map +0 -1
- package/dist/ast/classes/ConditionNode.js +0 -101
- package/dist/ast/classes/ErrorToken.d.ts +0 -27
- package/dist/ast/classes/ErrorToken.d.ts.map +0 -1
- package/dist/ast/classes/ErrorToken.js +0 -47
- package/dist/ast/classes/Expression.d.ts +0 -13
- package/dist/ast/classes/Expression.d.ts.map +0 -1
- package/dist/ast/classes/Expression.js +0 -19
- package/dist/ast/classes/ExpressionNode.d.ts +0 -21
- package/dist/ast/classes/ExpressionNode.d.ts.map +0 -1
- package/dist/ast/classes/ExpressionNode.js +0 -57
- package/dist/ast/classes/GroupNode.d.ts +0 -64
- package/dist/ast/classes/GroupNode.d.ts.map +0 -1
- package/dist/ast/classes/GroupNode.js +0 -69
- package/dist/ast/classes/Node.d.ts +0 -22
- package/dist/ast/classes/Node.d.ts.map +0 -1
- package/dist/ast/classes/Node.js +0 -28
- package/dist/ast/classes/Token.d.ts +0 -27
- package/dist/ast/classes/Token.d.ts.map +0 -1
- package/dist/ast/classes/Token.js +0 -28
- package/dist/ast/classes/ValidToken.d.ts +0 -26
- package/dist/ast/classes/ValidToken.d.ts.map +0 -1
- package/dist/ast/classes/ValidToken.js +0 -49
- package/dist/ast/classes/VariableNode.d.ts +0 -33
- package/dist/ast/classes/VariableNode.d.ts.map +0 -1
- package/dist/ast/classes/VariableNode.js +0 -58
- package/dist/ast/classes/index.d.ts +0 -12
- package/dist/ast/classes/index.d.ts.map +0 -1
- package/dist/ast/classes/index.js +0 -24
- package/dist/helpers/errors.d.ts.map +0 -1
- package/dist/helpers/general/applyBoolean.d.ts.map +0 -1
- package/dist/helpers/general/applyPrefix.d.ts.map +0 -1
- package/dist/helpers/general/defaultConditionNormalizer.d.ts +0 -3
- package/dist/helpers/general/defaultConditionNormalizer.d.ts.map +0 -1
- package/dist/helpers/general/defaultKeyParser.d.ts +0 -3
- package/dist/helpers/general/defaultKeyParser.d.ts.map +0 -1
- package/dist/helpers/general/defaultPrefixApplier.d.ts +0 -3
- package/dist/helpers/general/defaultPrefixApplier.d.ts.map +0 -1
- package/dist/helpers/general/defaultValueComparer.d.ts +0 -3
- package/dist/helpers/general/defaultValueComparer.d.ts.map +0 -1
- package/dist/helpers/general/index.d.ts.map +0 -1
- package/dist/helpers/index.d.ts +0 -4
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -8
- package/dist/helpers/parser/assignParents.d.ts +0 -4
- package/dist/helpers/parser/assignParents.d.ts.map +0 -1
- package/dist/helpers/parser/assignParents.js +0 -71
- package/dist/helpers/parser/checkParserOpts.d.ts.map +0 -1
- package/dist/helpers/parser/extractPosition.d.ts +0 -5
- package/dist/helpers/parser/extractPosition.d.ts.map +0 -1
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts +0 -4
- package/dist/helpers/parser/getUnclosedRightParenCount.d.ts.map +0 -1
- package/dist/helpers/parser/index.d.ts +0 -9
- package/dist/helpers/parser/index.d.ts.map +0 -1
- package/dist/helpers/parser/index.js +0 -18
- package/dist/helpers/parser/parseParserOptions.d.ts.map +0 -1
- package/dist/helpers/parser/seal.d.ts +0 -8
- package/dist/helpers/parser/seal.d.ts.map +0 -1
- package/dist/helpers/parser/seal.js +0 -10
- package/dist/helpers/parser/setParent.d.ts +0 -6
- package/dist/helpers/parser/setParent.d.ts.map +0 -1
- package/dist/helpers/parser/setParent.js +0 -4
- package/dist/helpers/parser/unescape.d.ts.map +0 -1
- package/src/ast/classes/ArrayNode.ts +0 -46
- package/src/ast/classes/Condition.ts +0 -22
- package/src/ast/classes/ConditionNode.ts +0 -141
- package/src/ast/classes/ErrorToken.ts +0 -49
- package/src/ast/classes/Expression.ts +0 -26
- package/src/ast/classes/ExpressionNode.ts +0 -62
- package/src/ast/classes/GroupNode.ts +0 -127
- package/src/ast/classes/Node.ts +0 -47
- package/src/ast/classes/Token.ts +0 -59
- package/src/ast/classes/ValidToken.ts +0 -56
- package/src/ast/classes/VariableNode.ts +0 -67
- package/src/ast/classes/index.ts +0 -13
- package/src/helpers/index.ts +0 -6
- package/src/helpers/parser/assignParents.ts +0 -51
- package/src/helpers/parser/index.ts +0 -10
- package/src/helpers/parser/seal.ts +0 -14
- package/src/helpers/parser/setParent.ts +0 -5
- /package/dist/{helpers/general → defaults}/defaultConditionNormalizer.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultKeyParser.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultPrefixApplier.js +0 -0
- /package/dist/{helpers/general → defaults}/defaultValueComparer.js +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.d.ts +0 -0
- /package/dist/{helpers/general → internal}/applyBoolean.js +0 -0
- /package/dist/{helpers/general → internal}/applyPrefix.js +0 -0
- /package/dist/{helpers/parser → internal}/extractPosition.js +0 -0
- /package/dist/{helpers/parser → internal}/unescape.d.ts +0 -0
- /package/dist/{helpers/parser → internal}/unescape.js +0 -0
- /package/src/{helpers/general → internal}/applyBoolean.ts +0 -0
- /package/src/{helpers/parser → internal}/unescape.ts +0 -0
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { Mutable } from "@alanscodelog/utils/types"
|
|
2
|
-
|
|
3
1
|
import { token } from "./token.js"
|
|
4
2
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { VariableNode } from "../classes/VariableNode.js"
|
|
3
|
+
import { type ArrayNode, type FirstParam,type Position, TOKEN_TYPE, type VariableNode } from "../../types/ast.js"
|
|
4
|
+
import { createArrayNode } from "../createArrayNode.js"
|
|
8
5
|
|
|
9
6
|
|
|
10
7
|
export function array(
|
|
@@ -13,8 +10,7 @@ export function array(
|
|
|
13
10
|
parenLeftPos?: Position,
|
|
14
11
|
parenRightPos?: Position,
|
|
15
12
|
): ArrayNode {
|
|
16
|
-
const node:
|
|
17
|
-
type: AST_TYPE.ARRAY,
|
|
13
|
+
const node: Partial<FirstParam<typeof createArrayNode>> = {
|
|
18
14
|
values,
|
|
19
15
|
}
|
|
20
16
|
|
|
@@ -40,6 +36,5 @@ export function array(
|
|
|
40
36
|
node.start = node.bracket!.left?.start ?? start ?? node.bracket?.right.start
|
|
41
37
|
node.end = node.bracket?.right?.end ?? end ?? node.bracket!.left.end
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
return instance
|
|
39
|
+
return createArrayNode(node as any)
|
|
45
40
|
}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { pos } from "./pos.js"
|
|
2
2
|
|
|
3
|
-
import { type AnyToken, type Position, type TOKEN_TYPE } from "../../types/ast.js"
|
|
4
|
-
import
|
|
5
|
-
import { ConditionNode } from "../classes/ConditionNode.js"
|
|
6
|
-
import type { ErrorToken } from "../classes/ErrorToken.js"
|
|
7
|
-
import type { GroupNode } from "../classes/GroupNode.js"
|
|
8
|
-
import type { ValidToken } from "../classes/ValidToken.js"
|
|
9
|
-
import type { VariableNode } from "../classes/VariableNode.js"
|
|
3
|
+
import { type AnyToken, type ArrayNode, type ConditionNode, type ErrorToken, type FirstParam, type GroupNode, type Position, type TOKEN_TYPE, type ValidToken, type VariableNode } from "../../types/ast.js"
|
|
4
|
+
import { createConditionNode } from "../createConditionNode.js"
|
|
10
5
|
|
|
11
6
|
/**
|
|
12
|
-
* Creates a @
|
|
7
|
+
* Creates a {@link ConditionNode}
|
|
13
8
|
*
|
|
14
|
-
* @param variable An existing @
|
|
9
|
+
* @param variable An existing {@link VariableNode}
|
|
15
10
|
*
|
|
16
|
-
* @param not Defaults to plain true condition. To negate it you must pass an existing "not" operator @
|
|
11
|
+
* @param not Defaults to plain true condition. To negate it you must pass an existing "not" operator {@link ValidToken} which will be set as the node's operator and set the node's value to false.
|
|
17
12
|
*
|
|
18
13
|
* @param property Set the property for a property operator. A property operator must be passed if this is passed.
|
|
19
14
|
* @param propertyOperator Set the operator for a property condition. A property must have been passed. The property operator must be a valid token. There is no case where it would not be. If using an operator that is the same as a separator, if used as an operator, should be set as an operator.
|
|
@@ -25,9 +20,9 @@ export function condition(
|
|
|
25
20
|
| VariableNode
|
|
26
21
|
| GroupNode
|
|
27
22
|
| ArrayNode
|
|
28
|
-
| ErrorToken
|
|
23
|
+
| ErrorToken,
|
|
29
24
|
not: true | ValidToken<TOKEN_TYPE.NOT> = true,
|
|
30
|
-
property?: VariableNode | ErrorToken
|
|
25
|
+
property?: VariableNode | ErrorToken,
|
|
31
26
|
propertyOperator?: AnyToken<TOKEN_TYPE.OP_CUSTOM | TOKEN_TYPE.VALUE>,
|
|
32
27
|
{ right, left }: Partial<Record<"right" | "left", ValidToken<TOKEN_TYPE.OP_EXPANDED_SEP>>> = { },
|
|
33
28
|
): ConditionNode {
|
|
@@ -35,7 +30,7 @@ export function condition(
|
|
|
35
30
|
const notStart = not === true ? undefined : not.start
|
|
36
31
|
position.start = notStart ?? property?.start ?? propertyOperator?.start ?? position.start
|
|
37
32
|
|
|
38
|
-
const node:
|
|
33
|
+
const node: FirstParam<typeof createConditionNode> = {
|
|
39
34
|
property,
|
|
40
35
|
value,
|
|
41
36
|
propertyOperator,
|
|
@@ -50,7 +45,7 @@ export function condition(
|
|
|
50
45
|
if (right) node.sep.right = right
|
|
51
46
|
if (left) node.sep.left = left
|
|
52
47
|
}
|
|
53
|
-
|
|
54
|
-
return
|
|
48
|
+
|
|
49
|
+
return createConditionNode(node)
|
|
55
50
|
}
|
|
56
51
|
|
|
@@ -3,7 +3,7 @@ import { type } from "./type.js"
|
|
|
3
3
|
import { type ExtractTokenType, TOKEN_TYPE } from "../../types/ast.js"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Faster way, more intuitive way to generate the options for matching delimiters (e.g. quotes and parens) for functions like @
|
|
6
|
+
* Faster way, more intuitive way to generate the options for matching delimiters (e.g. quotes and parens) for functions like {@link variable} and {@link group} .
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
export function delim<
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type } from "./type.js"
|
|
2
2
|
|
|
3
|
-
import { TOKEN_TYPE } from "../../types/ast.js"
|
|
4
|
-
import {
|
|
3
|
+
import { type ErrorToken,TOKEN_TYPE } from "../../types/ast.js"
|
|
4
|
+
import { createToken } from "../createToken.js"
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates an error token.
|
|
9
9
|
*
|
|
10
|
-
* @param expected Can be passed an array of @
|
|
10
|
+
* @param expected Can be passed an array of {@link ValidToken_TYPE} or strings, in which case it will use {@link type} internally. So instead of `[TOKEN_TYPE.VALUE]` we can do `[""]` and instead of `[TOKEN_TYPE.PARENR]` we can do `[")"]`.
|
|
11
11
|
*/
|
|
12
|
-
export function error<T extends TOKEN_TYPE>(pos: number, expected: T[]): ErrorToken
|
|
13
|
-
export function error<T extends TOKEN_TYPE>(pos: number, expected_: T[]): ErrorToken
|
|
12
|
+
export function error<T extends TOKEN_TYPE>(pos: number, expected: T[]): ErrorToken
|
|
13
|
+
export function error<T extends TOKEN_TYPE>(pos: number, expected_: T[]): ErrorToken {
|
|
14
14
|
const expected = expected_.map(item => {
|
|
15
15
|
if (TOKEN_TYPE[item as keyof typeof TOKEN_TYPE] === undefined) {
|
|
16
16
|
return type(item)
|
|
@@ -18,5 +18,9 @@ export function error<T extends TOKEN_TYPE>(pos: number, expected_: T[]): ErrorT
|
|
|
18
18
|
return item
|
|
19
19
|
}
|
|
20
20
|
}) as T []
|
|
21
|
-
return
|
|
21
|
+
return createToken({
|
|
22
|
+
expected,
|
|
23
|
+
start: pos,
|
|
24
|
+
end: pos
|
|
25
|
+
})
|
|
22
26
|
}
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import { pos } from "./pos.js"
|
|
2
2
|
import { token } from "./token.js"
|
|
3
3
|
|
|
4
|
-
import { type AnyToken, type Position, TOKEN_TYPE, type TokenBooleanTypes } from "../../types/ast.js"
|
|
5
|
-
import
|
|
6
|
-
import type { ErrorToken } from "../classes/ErrorToken.js"
|
|
7
|
-
import { ExpressionNode } from "../classes/ExpressionNode.js"
|
|
8
|
-
import type { GroupNode } from "../classes/GroupNode.js"
|
|
4
|
+
import { type AnyToken, type ConditionNode, type ErrorToken, type ExpressionNode,type GroupNode, type Position, TOKEN_TYPE, type TokenBooleanTypes } from "../../types/ast.js"
|
|
5
|
+
import { createExpressionNode } from "../createExpressionNode.js"
|
|
9
6
|
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
|
-
* Creates an @
|
|
9
|
+
* Creates an {@link ExpressionNode}, can be passed nothing for any of the tokens to automatically create error tokens.
|
|
13
10
|
*
|
|
14
11
|
* Also automatically sets the correct start/end positions from valid tokens (e.g. for start, searching left to right for a valid token and vice versa) assuming at least one is defined.
|
|
15
12
|
*/
|
|
16
13
|
export function expression(
|
|
17
14
|
left:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
ConditionNode |
|
|
16
|
+
ExpressionNode |
|
|
17
|
+
GroupNode |
|
|
18
|
+
ErrorToken |
|
|
19
|
+
undefined,
|
|
23
20
|
operator:
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
AnyToken<TokenBooleanTypes> |
|
|
22
|
+
undefined,
|
|
26
23
|
right:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
ConditionNode |
|
|
25
|
+
ExpressionNode |
|
|
26
|
+
GroupNode |
|
|
27
|
+
ErrorToken |
|
|
28
|
+
undefined,
|
|
32
29
|
): ExpressionNode {
|
|
33
30
|
const start =
|
|
34
31
|
left?.start ??
|
|
@@ -54,13 +51,10 @@ export function expression(
|
|
|
54
51
|
right = token(TOKEN_TYPE.VALUE, undefined, { start: op.end })
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
|
|
54
|
+
return createExpressionNode({
|
|
58
55
|
left,
|
|
59
56
|
operator: op,
|
|
60
57
|
right,
|
|
61
58
|
...position,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const instance = new ExpressionNode(node)
|
|
65
|
-
return instance
|
|
59
|
+
})
|
|
66
60
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { token } from "./token.js"
|
|
2
2
|
|
|
3
|
-
import { type Position, TOKEN_TYPE } from "../../types/ast.js"
|
|
4
|
-
import
|
|
5
|
-
import type { ErrorToken } from "../classes/ErrorToken.js"
|
|
6
|
-
import type { ExpressionNode } from "../classes/ExpressionNode.js"
|
|
7
|
-
import { GroupNode } from "../classes/GroupNode.js"
|
|
8
|
-
import type { ValidToken } from "../classes/ValidToken.js"
|
|
3
|
+
import { type ConditionNode, type ErrorToken, type ExpressionNode, type FirstParam,type GroupNode, type Position, TOKEN_TYPE, type ValidToken } from "../../types/ast.js"
|
|
4
|
+
import { createGroupNode } from "../createGroupNode.js"
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* Creates a group.
|
|
12
8
|
*
|
|
13
9
|
* Automatically creates error tokens if missing condition or parens (not prefix because it is optional). Will look at the position of prefix if available.
|
|
14
10
|
*
|
|
15
|
-
* @param paren Use to add parens to group, usually by using @
|
|
11
|
+
* @param paren Use to add parens to group, usually by using {@link delim} . If either `right` or `left` are false or undefined, error tokens will be created. Unlike {@link variable}, if undefined is passed for parens, parens are created by default.
|
|
16
12
|
*
|
|
17
13
|
* The positions of the parens can be adjusted with the last two parameters by passing positions.
|
|
18
14
|
*/
|
|
@@ -27,7 +23,7 @@ export function group(
|
|
|
27
23
|
| ConditionNode
|
|
28
24
|
| ExpressionNode
|
|
29
25
|
| GroupNode
|
|
30
|
-
| ErrorToken
|
|
26
|
+
| ErrorToken
|
|
31
27
|
| undefined,
|
|
32
28
|
|
|
33
29
|
paren: { left?: boolean, right?: boolean } = { right: true, left: true },
|
|
@@ -38,7 +34,8 @@ export function group(
|
|
|
38
34
|
expression = token(TOKEN_TYPE.VALUE, undefined, prefix?.end !== undefined ? { start: prefix.end } : undefined)
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
const node: Partial<
|
|
37
|
+
const node: Partial<FirstParam<typeof createGroupNode>> = {
|
|
38
|
+
prefix: undefined,
|
|
42
39
|
expression,
|
|
43
40
|
}
|
|
44
41
|
if (prefix) {
|
|
@@ -74,6 +71,5 @@ export function group(
|
|
|
74
71
|
node.start = node.prefix?.start ?? node.paren?.left?.start ?? node.expression?.start ?? node.paren?.right.start
|
|
75
72
|
node.end = node.paren?.right?.end ?? node.expression?.end ?? node.paren?.left.end ?? node.prefix?.end
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
return instance
|
|
74
|
+
return createGroupNode(node as any)
|
|
79
75
|
}
|
package/src/ast/builders/pos.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isFullPos } from "./isFullPos.js"
|
|
2
2
|
|
|
3
|
-
import type { AnyToken, AST_TYPE, EmptyObj, Position, TOKEN_TYPE } from "../../types/ast.js"
|
|
4
|
-
import type { Node } from "../classes/Node.js"
|
|
3
|
+
import type { AnyToken, AST_TYPE, EmptyObj, Node, Position, TOKEN_TYPE } from "../../types/ast.js"
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Can either:
|
|
@@ -20,7 +19,7 @@ export function pos<TItem extends Position | Partial<Position> | EmptyObj>(
|
|
|
20
19
|
item: TItem,
|
|
21
20
|
opts?: undefined | { fill: false }
|
|
22
21
|
):
|
|
23
|
-
// not sure why this needs the AnyToken check
|
|
22
|
+
// not sure why this needs the AnyToken check
|
|
24
23
|
TItem extends Position
|
|
25
24
|
? Position
|
|
26
25
|
: TItem extends AnyToken<TOKEN_TYPE> | Position | EmptyObj
|
|
@@ -2,13 +2,12 @@ import { isArray } from "@alanscodelog/utils/isArray.js"
|
|
|
2
2
|
|
|
3
3
|
import { pos } from "./pos.js"
|
|
4
4
|
|
|
5
|
-
import type { AnyToken, EmptyObj, Position, TOKEN_TYPE } from "../../types/ast.js"
|
|
6
|
-
import {
|
|
7
|
-
import { ValidToken } from "../classes/ValidToken.js"
|
|
5
|
+
import type { AnyToken, EmptyObj, ErrorToken, Position, TOKEN_TYPE, ValidToken } from "../../types/ast.js"
|
|
6
|
+
import { createToken } from "../createToken.js"
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
|
-
* Creates a @
|
|
10
|
+
* Creates a {@link ValidToken} or of the given type with the given value. If no value is given, creates an {@link ErrorToken} instead.
|
|
12
11
|
*
|
|
13
12
|
* Can be passed multiple types when creating an error token to set the expected field.
|
|
14
13
|
*
|
|
@@ -23,20 +22,20 @@ export function token<
|
|
|
23
22
|
value: TValue,
|
|
24
23
|
position: Position | Partial<Position> | EmptyObj = {},
|
|
25
24
|
): TValue extends undefined
|
|
26
|
-
? ErrorToken
|
|
25
|
+
? ErrorToken
|
|
27
26
|
: ValidToken<TType> {
|
|
28
27
|
position = pos(position, { fill: true })
|
|
29
28
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
30
29
|
let token: AnyToken<TType>
|
|
31
30
|
if (value !== undefined) {
|
|
32
|
-
token =
|
|
31
|
+
token = createToken({
|
|
33
32
|
type: type as TType,
|
|
34
33
|
value,
|
|
35
34
|
start: position.start!,
|
|
36
35
|
end: position.end!,
|
|
37
36
|
})
|
|
38
37
|
} else {
|
|
39
|
-
token =
|
|
38
|
+
token = createToken({
|
|
40
39
|
expected: (isArray(type) ? type : [type]) as TType[],
|
|
41
40
|
start: position.start!,
|
|
42
41
|
end: position.end!,
|
package/src/ast/builders/type.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ExtractTokenType, TOKEN_TYPE } from "../../types/ast.js"
|
|
2
2
|
/**
|
|
3
|
-
* Given a the string value of an operator or single delimiter token, returns the corresponding @
|
|
3
|
+
* Given a the string value of an operator or single delimiter token, returns the corresponding {@link ValidToken_TYPE} .
|
|
4
4
|
*/
|
|
5
5
|
export function type<T extends string>(
|
|
6
6
|
operatorSymbol: T,
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { pos } from "./pos.js"
|
|
2
2
|
import { token } from "./token.js"
|
|
3
3
|
|
|
4
|
-
import { type AnyToken, type EmptyObj, type Position, TOKEN_TYPE, type TokenQuoteTypes } from "../../types/ast.js"
|
|
5
|
-
import
|
|
6
|
-
import { VariableNode } from "../classes/VariableNode.js"
|
|
4
|
+
import { type AnyToken, type EmptyObj,type FirstParam, type Position, TOKEN_TYPE, type TokenQuoteTypes, type ValidToken, type VariableNode } from "../../types/ast.js"
|
|
5
|
+
import { createVariableNode } from "../createVariableNode.js"
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
* Creates an @
|
|
9
|
+
* Creates an {@link VariableNode} .
|
|
11
10
|
*
|
|
12
|
-
* @param quote Use to add quotes to the variable, usually by using @
|
|
11
|
+
* @param quote Use to add quotes to the variable, usually by using {@link delim} . If false or undefined, no quotes are added. Otherwise at least `type` must be passed. If one side is defined but not the other, error tokens will be created with the given type.
|
|
13
12
|
*
|
|
14
13
|
* @param position Refers to position of the value (in case it needs to be created) not the node. Quote positions are automatically calculated from this if used. If value is already a token, there's no need to pass a position, it can be extracted from the token.
|
|
15
14
|
*/
|
|
@@ -26,7 +25,7 @@ export function variable(
|
|
|
26
25
|
|
|
27
26
|
position = pos(value)
|
|
28
27
|
|
|
29
|
-
const node: Partial<
|
|
28
|
+
const node: Partial<FirstParam<typeof createVariableNode>> = {
|
|
30
29
|
value,
|
|
31
30
|
prefix,
|
|
32
31
|
}
|
|
@@ -74,8 +73,7 @@ export function variable(
|
|
|
74
73
|
node.value?.end ??
|
|
75
74
|
node.quote?.left.end
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
return instance
|
|
76
|
+
return createVariableNode(node as any)
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
function quoteFromType(type: TokenQuoteTypes | undefined): string {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ArrayNode, AST_TYPE, type RawNode } from "../types/ast.js"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function createArrayNode<TValid extends boolean = boolean>(
|
|
5
|
+
raw: RawNode<ArrayNode<TValid>>
|
|
6
|
+
): ArrayNode<TValid> {
|
|
7
|
+
return {
|
|
8
|
+
type: AST_TYPE.ARRAY,
|
|
9
|
+
isNode: true,
|
|
10
|
+
valid: (
|
|
11
|
+
raw.values.every(val => val.valid) &&
|
|
12
|
+
raw.bracket.left.valid &&
|
|
13
|
+
raw.bracket.right.valid
|
|
14
|
+
) as TValid,
|
|
15
|
+
...raw
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AST_TYPE, type ConditionNode, type TOKEN_TYPE, type ValidToken } from "../types/ast.js"
|
|
2
|
+
import { isNode } from "../utils/isNode.js"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function createConditionNode<
|
|
6
|
+
TValid extends boolean = boolean,
|
|
7
|
+
TOperator extends
|
|
8
|
+
ValidToken<TOKEN_TYPE.NOT> | undefined =
|
|
9
|
+
ValidToken<TOKEN_TYPE.NOT> | undefined,
|
|
10
|
+
>(raw: {
|
|
11
|
+
operator?: TOperator
|
|
12
|
+
property?: ConditionNode<TValid>["property"]
|
|
13
|
+
propertyOperator?: ConditionNode<TValid>["propertyOperator"]
|
|
14
|
+
sep?: ConditionNode<TValid>["sep"]
|
|
15
|
+
value: ConditionNode<TValid>["value"]
|
|
16
|
+
start: number
|
|
17
|
+
end: number
|
|
18
|
+
}
|
|
19
|
+
): ConditionNode<TValid> {
|
|
20
|
+
const valid = (
|
|
21
|
+
(
|
|
22
|
+
raw.operator === undefined
|
|
23
|
+
|| raw.operator?.valid
|
|
24
|
+
)
|
|
25
|
+
&& isNode(raw.value)
|
|
26
|
+
&& raw.value.valid
|
|
27
|
+
)
|
|
28
|
+
&& (
|
|
29
|
+
(
|
|
30
|
+
raw.property === undefined &&
|
|
31
|
+
raw.propertyOperator === undefined &&
|
|
32
|
+
raw.sep === undefined
|
|
33
|
+
) || (
|
|
34
|
+
raw.property !== undefined
|
|
35
|
+
&& "type" in raw.property
|
|
36
|
+
&& raw.property.type === AST_TYPE.VARIABLE
|
|
37
|
+
&& (
|
|
38
|
+
raw.propertyOperator?.valid === true
|
|
39
|
+
|| (
|
|
40
|
+
raw.sep?.left?.valid === true
|
|
41
|
+
&& (
|
|
42
|
+
raw.sep.right === undefined
|
|
43
|
+
|| raw.sep?.right.valid
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
return {
|
|
50
|
+
property: undefined,
|
|
51
|
+
propertyOperator: undefined,
|
|
52
|
+
sep: undefined,
|
|
53
|
+
...raw,
|
|
54
|
+
isNode: true,
|
|
55
|
+
type: AST_TYPE.CONDITION,
|
|
56
|
+
valid
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AST_TYPE, type ExpressionNode,type RawNode } from "../types/ast.js"
|
|
2
|
+
import { isNode } from "../utils/isNode.js"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function createExpressionNode<TValid extends boolean = boolean>(
|
|
6
|
+
raw: RawNode< ExpressionNode<TValid>>
|
|
7
|
+
): ExpressionNode<TValid> {
|
|
8
|
+
const valid = (
|
|
9
|
+
raw.operator.valid &&
|
|
10
|
+
isNode(raw.left) &&
|
|
11
|
+
raw.left.valid &&
|
|
12
|
+
isNode(raw.right) &&
|
|
13
|
+
raw.right.valid
|
|
14
|
+
)
|
|
15
|
+
return {
|
|
16
|
+
...raw,
|
|
17
|
+
isNode: true,
|
|
18
|
+
valid,
|
|
19
|
+
type: AST_TYPE.EXPRESSION,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AST_TYPE, type ConditionNode, type GroupNode, type RawNode, type TOKEN_TYPE, type ValidToken } from "../types/ast.js"
|
|
2
|
+
import { isNode } from "../utils/isNode.js"
|
|
3
|
+
import { isToken } from "../utils/isToken.js"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function createGroupNode<
|
|
7
|
+
TValid extends boolean = boolean,
|
|
8
|
+
TPrefixable extends boolean = true,
|
|
9
|
+
TPrefix extends
|
|
10
|
+
TPrefixable extends true
|
|
11
|
+
? ConditionNode<TValid> |
|
|
12
|
+
ValidToken<TOKEN_TYPE.NOT> |
|
|
13
|
+
undefined
|
|
14
|
+
: ValidToken<TOKEN_TYPE.NOT> |
|
|
15
|
+
undefined =
|
|
16
|
+
TPrefixable extends true
|
|
17
|
+
? ConditionNode<TValid> |
|
|
18
|
+
ValidToken<TOKEN_TYPE.NOT> |
|
|
19
|
+
undefined
|
|
20
|
+
: ValidToken<TOKEN_TYPE.NOT>,
|
|
21
|
+
>(raw: {
|
|
22
|
+
prefix: TPrefix
|
|
23
|
+
} & RawNode<GroupNode<TValid>>): GroupNode<TValid, TPrefixable, TPrefix> {
|
|
24
|
+
return {
|
|
25
|
+
...raw,
|
|
26
|
+
isNode: true,
|
|
27
|
+
valid: (
|
|
28
|
+
(
|
|
29
|
+
raw.prefix === undefined
|
|
30
|
+
|| (isToken(raw.prefix) && raw.prefix.valid)
|
|
31
|
+
|| (isNode(raw.prefix) && raw.prefix.valid)
|
|
32
|
+
)
|
|
33
|
+
&& isNode(raw.expression)
|
|
34
|
+
&& raw.expression.valid
|
|
35
|
+
&& (
|
|
36
|
+
raw.paren === undefined
|
|
37
|
+
|| (
|
|
38
|
+
raw.paren.left.valid
|
|
39
|
+
&& raw.paren.right.valid
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
),
|
|
43
|
+
type: AST_TYPE.GROUP,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AST_TYPE, type NormalizedCondition } from "../types/ast.js"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function createCondition<
|
|
5
|
+
TOp extends string = string,
|
|
6
|
+
TValue = any,
|
|
7
|
+
>(raw: Omit<NormalizedCondition<TOp, TValue>, "type">): NormalizedCondition<TOp, TValue> {
|
|
8
|
+
return {
|
|
9
|
+
...raw,
|
|
10
|
+
type: AST_TYPE.NORMALIZED_CONDITION,
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AST_TYPE, type NormalizedExpression } from "../types/ast.js"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function createExpression<TType extends string = string, TValue = any>(raw: Omit<NormalizedExpression<TType, TValue>, "type">): NormalizedExpression<TType, TValue> {
|
|
5
|
+
return {
|
|
6
|
+
...raw,
|
|
7
|
+
type: AST_TYPE.NORMALIZED_EXPRESSION
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ExpressitError } from "../internal/ExpressitError.js"
|
|
2
|
+
import type { ErrorToken, RawToken, TOKEN_TYPE, ValidToken } from "../types/ast.js"
|
|
3
|
+
import { ERROR_CODES } from "../types/errors.js"
|
|
4
|
+
|
|
5
|
+
export function createToken<
|
|
6
|
+
TType extends TOKEN_TYPE,
|
|
7
|
+
>(raw: { type: TType } & RawToken<ValidToken>): ValidToken<TType>
|
|
8
|
+
export function createToken(raw: RawToken<ErrorToken>): ErrorToken
|
|
9
|
+
export function createToken<
|
|
10
|
+
TValid extends boolean = boolean,
|
|
11
|
+
TType extends
|
|
12
|
+
TValid extends true ? TOKEN_TYPE : never =
|
|
13
|
+
TValid extends true ? TOKEN_TYPE : never,
|
|
14
|
+
>(raw: RawToken<ValidToken> | RawToken<ErrorToken>): TValid extends true
|
|
15
|
+
? ValidToken<TType>
|
|
16
|
+
: ErrorToken {
|
|
17
|
+
if (raw.start === undefined || raw.end === undefined) {
|
|
18
|
+
throw new ExpressitError(ERROR_CODES.PARSER_POSITION_ERROR, raw)
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
...raw,
|
|
22
|
+
valid: typeof (raw as any).expected === "undefined",
|
|
23
|
+
isToken: true,
|
|
24
|
+
} as any
|
|
25
|
+
}
|
|
26
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AST_TYPE, type RawNode, type VariableNode } from "../types/ast.js"
|
|
2
|
+
|
|
3
|
+
export function createVariableNode<
|
|
4
|
+
TValid extends boolean = boolean,
|
|
5
|
+
>(raw: RawNode<VariableNode<TValid>>): VariableNode<TValid> {
|
|
6
|
+
return {
|
|
7
|
+
...raw,
|
|
8
|
+
isNode: true,
|
|
9
|
+
valid: (raw.value.valid && (
|
|
10
|
+
raw.quote === undefined ||
|
|
11
|
+
(
|
|
12
|
+
raw.quote.left.valid &&
|
|
13
|
+
raw.quote.right.valid
|
|
14
|
+
)
|
|
15
|
+
)) as TValid,
|
|
16
|
+
type: AST_TYPE.VARIABLE,
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/ast/error.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createToken } from "./createToken.js"
|
|
2
|
+
|
|
3
|
+
import { type ErrorToken,type TOKEN_TYPE } from "../types/ast.js"
|
|
4
|
+
|
|
5
|
+
export function error<T extends TOKEN_TYPE>(pos: number, expected: T[]): ErrorToken {
|
|
6
|
+
if (pos === undefined) throw new Error("should never happen, passed undefined position for error token")
|
|
7
|
+
return createToken({ expected, start: pos, end: pos })
|
|
8
|
+
}
|
|
9
|
+
|