arktype 1.1.0-dev-1 → 2.0.0-beta.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/LICENSE +7 -0
- package/out/ark.d.ts +24 -0
- package/out/ark.js +8 -0
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +54 -0
- package/out/generic.js +39 -0
- package/out/index.d.ts +6 -0
- package/out/index.js +5 -0
- package/out/match.d.ts +71 -0
- package/out/match.js +50 -0
- package/out/module.d.ts +11 -0
- package/out/module.js +2 -0
- package/out/parser/definition.d.ts +32 -0
- package/out/parser/definition.js +29 -0
- package/out/parser/objectLiteral.d.ts +79 -0
- package/out/parser/objectLiteral.js +100 -0
- package/out/parser/semantic/bounds.d.ts +15 -0
- package/out/parser/semantic/bounds.js +1 -0
- package/out/parser/semantic/default.d.ts +8 -0
- package/out/parser/semantic/default.js +1 -0
- package/out/parser/semantic/divisor.d.ts +7 -0
- package/out/parser/semantic/divisor.js +1 -0
- package/out/parser/semantic/infer.d.ts +25 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/utils.d.ts +4 -0
- package/out/parser/semantic/utils.js +1 -0
- package/out/parser/semantic/validate.d.ts +30 -0
- package/out/parser/semantic/validate.js +2 -0
- package/out/parser/string/reduce/dynamic.d.ts +43 -0
- package/out/parser/string/reduce/dynamic.js +139 -0
- package/out/parser/string/reduce/shared.d.ts +42 -0
- package/out/parser/string/reduce/shared.js +27 -0
- package/out/parser/string/reduce/static.d.ts +179 -0
- package/out/parser/string/reduce/static.js +1 -0
- package/out/parser/string/shift/operand/date.d.ts +9 -0
- package/out/parser/string/shift/operand/date.js +23 -0
- package/out/parser/string/shift/operand/enclosed.d.ts +38 -0
- package/out/parser/string/shift/operand/enclosed.js +50 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts +28 -0
- package/out/parser/string/shift/operand/genericArgs.js +16 -0
- package/out/parser/string/shift/operand/operand.d.ts +9 -0
- package/out/parser/string/shift/operand/operand.js +12 -0
- package/out/parser/string/shift/operand/unenclosed.d.ts +30 -0
- package/out/parser/string/shift/operand/unenclosed.js +53 -0
- package/out/parser/string/shift/operator/bounds.d.ts +27 -0
- package/out/parser/string/shift/operator/bounds.js +94 -0
- package/out/parser/string/shift/operator/default.d.ts +24 -0
- package/out/parser/string/shift/operator/default.js +23 -0
- package/out/parser/string/shift/operator/divisor.d.ts +7 -0
- package/out/parser/string/shift/operator/divisor.js +11 -0
- package/out/parser/string/shift/operator/operator.d.ts +13 -0
- package/out/parser/string/shift/operator/operator.js +22 -0
- package/out/parser/string/shift/scanner.d.ts +67 -0
- package/out/parser/string/shift/scanner.js +102 -0
- package/out/parser/string/string.d.ts +28 -0
- package/out/parser/string/string.js +24 -0
- package/out/parser/tuple.d.ts +130 -0
- package/out/parser/tuple.js +157 -0
- package/out/scope.d.ts +84 -0
- package/out/scope.js +131 -0
- package/out/type.d.ts +79 -0
- package/out/type.js +37 -0
- package/package.json +37 -36
- package/dist/main.d.ts +0 -1018
- package/dist/main.js +0 -1450
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Stringifiable } from "@ark/util";
|
|
2
|
+
import type { Comparator } from "../string/reduce/shared.js";
|
|
3
|
+
import type { InfixExpression, PostfixExpression } from "./infer.js";
|
|
4
|
+
export type astToString<ast> = ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${astToString<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${astToString<l>} ${operator} ${astToString<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { arkKind, GenericParamAst, GenericProps, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
|
|
2
|
+
import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
|
|
3
|
+
import type { Generic } from "../../generic.js";
|
|
4
|
+
import type { Comparator } from "../string/reduce/shared.js";
|
|
5
|
+
import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.js";
|
|
6
|
+
import type { UnitLiteral } from "../string/shift/operator/default.js";
|
|
7
|
+
import type { parseString } from "../string/string.js";
|
|
8
|
+
import type { validateRange } from "./bounds.js";
|
|
9
|
+
import type { validateDefault } from "./default.js";
|
|
10
|
+
import type { validateDivisor } from "./divisor.js";
|
|
11
|
+
import type { GenericInstantiationAst, inferAstRoot, InfixExpression, PostfixExpression } from "./infer.js";
|
|
12
|
+
import type { astToString } from "./utils.js";
|
|
13
|
+
export type validateAst<ast, $, args> = ast extends string ? validateStringAst<ast, $> : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : undefined : ast extends (readonly [infer baseAst, "=", infer unitLiteral extends UnitLiteral]) ? validateDefault<baseAst, unitLiteral, $, args> : ast extends readonly ["keyof", infer operand] ? validateAst<operand, $, args> : ast extends (GenericInstantiationAst<Generic<infer params, any, any> | GenericProps<infer params>, infer argAsts>) ? validateGenericArgs<params, argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
|
|
14
|
+
ast: ast;
|
|
15
|
+
};
|
|
16
|
+
type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
|
|
17
|
+
type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined;
|
|
18
|
+
export declare const writeUnsatisfiableExpressionError: <expression extends string>(expression: expression) => writeUnsatisfiableExpressionError<expression>;
|
|
19
|
+
export type writeUnsatisfiableExpressionError<expression extends string> = `${expression} results in an unsatisfiable type`;
|
|
20
|
+
export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>;
|
|
21
|
+
export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
|
|
22
|
+
type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ? [
|
|
23
|
+
$[alias]
|
|
24
|
+
] extends [anyOrNever] ? def : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : $[alias] extends GenericProps ? ErrorMessage<writeInvalidGenericArgCountMessage<def, $[alias]["names"], []>> : $[alias] extends {
|
|
25
|
+
[arkKind]: "module";
|
|
26
|
+
} ? ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
|
|
27
|
+
export type maybeExtractAlias<def extends string, $> = def extends keyof $ ? def : `#${def}` extends keyof $ ? `#${def}` : null;
|
|
28
|
+
export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
|
|
29
|
+
type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : validateAst<ast[2], $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : undefined;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BaseRoot, LimitLiteral } from "@ark/schema";
|
|
2
|
+
import { type requireKeys } from "@ark/util";
|
|
3
|
+
import type { ParseContext } from "../../../scope.js";
|
|
4
|
+
import type { InfixOperator } from "../../semantic/infer.js";
|
|
5
|
+
import type { Scanner } from "../shift/scanner.js";
|
|
6
|
+
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.js";
|
|
7
|
+
type BranchState = {
|
|
8
|
+
prefixes: StringifiablePrefixOperator[];
|
|
9
|
+
leftBound: OpenLeftBound | null;
|
|
10
|
+
intersection: BaseRoot | null;
|
|
11
|
+
union: BaseRoot | null;
|
|
12
|
+
};
|
|
13
|
+
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
|
|
14
|
+
export declare class DynamicState {
|
|
15
|
+
readonly scanner: Scanner;
|
|
16
|
+
readonly ctx: ParseContext;
|
|
17
|
+
readonly defaultable: boolean;
|
|
18
|
+
root: BaseRoot<any> | undefined;
|
|
19
|
+
branches: BranchState;
|
|
20
|
+
finalizer: Scanner.FinalizingLookahead | undefined;
|
|
21
|
+
groups: BranchState[];
|
|
22
|
+
constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
|
|
23
|
+
error(message: string): never;
|
|
24
|
+
hasRoot(): this is DynamicStateWithRoot;
|
|
25
|
+
setRoot(root: BaseRoot): void;
|
|
26
|
+
unsetRoot(): this["root"];
|
|
27
|
+
constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
|
|
28
|
+
finalize(finalizer: Scanner.FinalizingLookahead): void;
|
|
29
|
+
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
|
|
30
|
+
finalizeBranches(): void;
|
|
31
|
+
finalizeGroup(): void;
|
|
32
|
+
addPrefix(prefix: StringifiablePrefixOperator): void;
|
|
33
|
+
applyPrefixes(): void;
|
|
34
|
+
pushRootToBranch(token: "|" | "&"): void;
|
|
35
|
+
parseUntilFinalizer(): DynamicStateWithRoot;
|
|
36
|
+
parseOperator(this: DynamicStateWithRoot): void;
|
|
37
|
+
parseOperand(): void;
|
|
38
|
+
private assertRangeUnset;
|
|
39
|
+
reduceGroupOpen(): void;
|
|
40
|
+
previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined;
|
|
41
|
+
shiftedByOne(): this;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { isKeyOf, throwInternalError, throwParseError } from "@ark/util";
|
|
2
|
+
import { parseOperand } from "../shift/operand/operand.js";
|
|
3
|
+
import { parseOperator } from "../shift/operator/operator.js";
|
|
4
|
+
import { parseUntilFinalizer } from "../string.js";
|
|
5
|
+
import { invertedComparators, minComparators, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
|
|
6
|
+
export class DynamicState {
|
|
7
|
+
scanner;
|
|
8
|
+
ctx;
|
|
9
|
+
defaultable;
|
|
10
|
+
// set root type to `any` so that all constraints can be applied
|
|
11
|
+
root;
|
|
12
|
+
branches = {
|
|
13
|
+
prefixes: [],
|
|
14
|
+
leftBound: null,
|
|
15
|
+
intersection: null,
|
|
16
|
+
union: null
|
|
17
|
+
};
|
|
18
|
+
finalizer;
|
|
19
|
+
groups = [];
|
|
20
|
+
constructor(scanner, ctx, defaultable) {
|
|
21
|
+
this.scanner = scanner;
|
|
22
|
+
this.ctx = ctx;
|
|
23
|
+
this.defaultable = defaultable;
|
|
24
|
+
}
|
|
25
|
+
error(message) {
|
|
26
|
+
return throwParseError(message);
|
|
27
|
+
}
|
|
28
|
+
hasRoot() {
|
|
29
|
+
return this.root !== undefined;
|
|
30
|
+
}
|
|
31
|
+
setRoot(root) {
|
|
32
|
+
this.root = root;
|
|
33
|
+
}
|
|
34
|
+
unsetRoot() {
|
|
35
|
+
const value = this.root;
|
|
36
|
+
this.root = undefined;
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
constrainRoot(...args) {
|
|
40
|
+
this.root = this.root.constrain(args[0], args[1]);
|
|
41
|
+
}
|
|
42
|
+
finalize(finalizer) {
|
|
43
|
+
if (this.groups.length)
|
|
44
|
+
return this.error(writeUnclosedGroupMessage(")"));
|
|
45
|
+
this.finalizeBranches();
|
|
46
|
+
this.finalizer = finalizer;
|
|
47
|
+
}
|
|
48
|
+
reduceLeftBound(limit, comparator) {
|
|
49
|
+
const invertedComparator = invertedComparators[comparator];
|
|
50
|
+
if (!isKeyOf(invertedComparator, minComparators))
|
|
51
|
+
return this.error(writeUnpairableComparatorMessage(comparator));
|
|
52
|
+
if (this.branches.leftBound) {
|
|
53
|
+
return this.error(writeMultipleLeftBoundsMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
|
|
54
|
+
}
|
|
55
|
+
this.branches.leftBound = {
|
|
56
|
+
comparator: invertedComparator,
|
|
57
|
+
limit
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
finalizeBranches() {
|
|
61
|
+
this.assertRangeUnset();
|
|
62
|
+
if (this.branches.union) {
|
|
63
|
+
this.pushRootToBranch("|");
|
|
64
|
+
this.root = this.branches.union;
|
|
65
|
+
}
|
|
66
|
+
else if (this.branches.intersection) {
|
|
67
|
+
this.pushRootToBranch("&");
|
|
68
|
+
this.root = this.branches.intersection;
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
this.applyPrefixes();
|
|
72
|
+
}
|
|
73
|
+
finalizeGroup() {
|
|
74
|
+
this.finalizeBranches();
|
|
75
|
+
const topBranchState = this.groups.pop();
|
|
76
|
+
if (!topBranchState)
|
|
77
|
+
return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned));
|
|
78
|
+
this.branches = topBranchState;
|
|
79
|
+
}
|
|
80
|
+
addPrefix(prefix) {
|
|
81
|
+
this.branches.prefixes.push(prefix);
|
|
82
|
+
}
|
|
83
|
+
applyPrefixes() {
|
|
84
|
+
while (this.branches.prefixes.length) {
|
|
85
|
+
const lastPrefix = this.branches.prefixes.pop();
|
|
86
|
+
this.root =
|
|
87
|
+
lastPrefix === "keyof" ?
|
|
88
|
+
this.root.keyof()
|
|
89
|
+
: throwInternalError(`Unexpected prefix '${lastPrefix}'`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
pushRootToBranch(token) {
|
|
93
|
+
this.assertRangeUnset();
|
|
94
|
+
this.applyPrefixes();
|
|
95
|
+
const root = this.root;
|
|
96
|
+
this.branches.intersection = this.branches.intersection?.and(root) ?? root;
|
|
97
|
+
if (token === "|") {
|
|
98
|
+
this.branches.union =
|
|
99
|
+
this.branches.union?.or(this.branches.intersection) ??
|
|
100
|
+
this.branches.intersection;
|
|
101
|
+
this.branches.intersection = null;
|
|
102
|
+
}
|
|
103
|
+
this.root = undefined;
|
|
104
|
+
}
|
|
105
|
+
parseUntilFinalizer() {
|
|
106
|
+
return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx, false));
|
|
107
|
+
}
|
|
108
|
+
parseOperator() {
|
|
109
|
+
return parseOperator(this);
|
|
110
|
+
}
|
|
111
|
+
parseOperand() {
|
|
112
|
+
return parseOperand(this);
|
|
113
|
+
}
|
|
114
|
+
assertRangeUnset() {
|
|
115
|
+
if (this.branches.leftBound) {
|
|
116
|
+
return this.error(writeOpenRangeMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
reduceGroupOpen() {
|
|
120
|
+
this.groups.push(this.branches);
|
|
121
|
+
this.branches = {
|
|
122
|
+
prefixes: [],
|
|
123
|
+
leftBound: null,
|
|
124
|
+
union: null,
|
|
125
|
+
intersection: null
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
previousOperator() {
|
|
129
|
+
return (this.branches.leftBound?.comparator ??
|
|
130
|
+
this.branches.prefixes.at(-1) ??
|
|
131
|
+
(this.branches.intersection ? "&"
|
|
132
|
+
: this.branches.union ? "|"
|
|
133
|
+
: undefined));
|
|
134
|
+
}
|
|
135
|
+
shiftedByOne() {
|
|
136
|
+
this.scanner.shift();
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { LimitLiteral } from "@ark/schema";
|
|
2
|
+
export type StringifiablePrefixOperator = "keyof";
|
|
3
|
+
export declare const minComparators: {
|
|
4
|
+
readonly ">": true;
|
|
5
|
+
readonly ">=": true;
|
|
6
|
+
};
|
|
7
|
+
export type MinComparator = keyof typeof minComparators;
|
|
8
|
+
export declare const maxComparators: {
|
|
9
|
+
readonly "<": true;
|
|
10
|
+
readonly "<=": true;
|
|
11
|
+
};
|
|
12
|
+
export type MaxComparator = keyof typeof maxComparators;
|
|
13
|
+
export declare const comparators: {
|
|
14
|
+
">": boolean;
|
|
15
|
+
">=": boolean;
|
|
16
|
+
"<": boolean;
|
|
17
|
+
"<=": boolean;
|
|
18
|
+
"==": boolean;
|
|
19
|
+
};
|
|
20
|
+
export type Comparator = keyof typeof comparators;
|
|
21
|
+
export declare const invertedComparators: InvertedComparators;
|
|
22
|
+
export type InvertedComparators = {
|
|
23
|
+
"<": ">";
|
|
24
|
+
">": "<";
|
|
25
|
+
"<=": ">=";
|
|
26
|
+
">=": "<=";
|
|
27
|
+
"==": "==";
|
|
28
|
+
};
|
|
29
|
+
export type OpenLeftBound = {
|
|
30
|
+
limit: LimitLiteral;
|
|
31
|
+
comparator: MinComparator;
|
|
32
|
+
};
|
|
33
|
+
export declare const writeUnmatchedGroupCloseMessage: <unscanned extends string>(unscanned: unscanned) => writeUnmatchedGroupCloseMessage<unscanned>;
|
|
34
|
+
export type writeUnmatchedGroupCloseMessage<unscanned extends string> = `Unmatched )${unscanned extends "" ? "" : ` before ${unscanned}`}`;
|
|
35
|
+
export declare const writeUnclosedGroupMessage: <missingChar extends string>(missingChar: missingChar) => writeUnclosedGroupMessage<missingChar>;
|
|
36
|
+
export type writeUnclosedGroupMessage<missingChar extends string> = `Missing ${missingChar}`;
|
|
37
|
+
export declare const writeOpenRangeMessage: <min extends LimitLiteral, comparator extends MinComparator>(min: min, comparator: comparator) => writeOpenRangeMessage<min, comparator>;
|
|
38
|
+
export type writeOpenRangeMessage<min extends LimitLiteral, comparator extends MinComparator> = `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
39
|
+
export type writeUnpairableComparatorMessage<comparator extends Comparator> = `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
40
|
+
export declare const writeUnpairableComparatorMessage: <comparator extends Comparator>(comparator: comparator) => writeUnpairableComparatorMessage<comparator>;
|
|
41
|
+
export declare const writeMultipleLeftBoundsMessage: <openLimit extends LimitLiteral, openComparator extends MinComparator, limit extends LimitLiteral, comparator extends MinComparator>(openLimit: openLimit, openComparator: openComparator, limit: limit, comparator: comparator) => writeMultipleLeftBoundsMessage<openLimit, openComparator, limit, comparator>;
|
|
42
|
+
export type writeMultipleLeftBoundsMessage<openLimit extends LimitLiteral, openComparator extends MinComparator, limit extends LimitLiteral, comparator extends MinComparator> = `An expression may have at most one left bound (parsed ${openLimit}${InvertedComparators[openComparator]}, ${limit}${InvertedComparators[comparator]})`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const minComparators = {
|
|
2
|
+
">": true,
|
|
3
|
+
">=": true
|
|
4
|
+
};
|
|
5
|
+
export const maxComparators = {
|
|
6
|
+
"<": true,
|
|
7
|
+
"<=": true
|
|
8
|
+
};
|
|
9
|
+
export const comparators = {
|
|
10
|
+
">": true,
|
|
11
|
+
">=": true,
|
|
12
|
+
"<": true,
|
|
13
|
+
"<=": true,
|
|
14
|
+
"==": true
|
|
15
|
+
};
|
|
16
|
+
export const invertedComparators = {
|
|
17
|
+
"<": ">",
|
|
18
|
+
">": "<",
|
|
19
|
+
"<=": ">=",
|
|
20
|
+
">=": "<=",
|
|
21
|
+
"==": "=="
|
|
22
|
+
};
|
|
23
|
+
export const writeUnmatchedGroupCloseMessage = (unscanned) => `Unmatched )${(unscanned === "" ? "" : ` before ${unscanned}`)}`;
|
|
24
|
+
export const writeUnclosedGroupMessage = (missingChar) => `Missing ${missingChar}`;
|
|
25
|
+
export const writeOpenRangeMessage = (min, comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
26
|
+
export const writeUnpairableComparatorMessage = (comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
27
|
+
export const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator) => `An expression may have at most one left bound (parsed ${openLimit}${invertedComparators[openComparator]}, ${limit}${invertedComparators[comparator]})`;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { LimitLiteral } from "@ark/schema";
|
|
2
|
+
import type { Completion, ErrorMessage, defined } from "@ark/util";
|
|
3
|
+
import type { Scanner } from "../shift/scanner.js";
|
|
4
|
+
import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
|
|
5
|
+
export type StaticState = {
|
|
6
|
+
root: unknown;
|
|
7
|
+
branches: BranchState;
|
|
8
|
+
groups: BranchState[];
|
|
9
|
+
finalizer: Scanner.FinalizingLookahead | ErrorMessage | undefined;
|
|
10
|
+
scanned: string;
|
|
11
|
+
unscanned: string;
|
|
12
|
+
};
|
|
13
|
+
type BranchState = {
|
|
14
|
+
prefixes: StringifiablePrefixOperator[];
|
|
15
|
+
leftBound: OpenLeftBound | undefined;
|
|
16
|
+
intersection: unknown;
|
|
17
|
+
union: unknown;
|
|
18
|
+
};
|
|
19
|
+
export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
|
|
20
|
+
export declare namespace state {
|
|
21
|
+
export type initialize<def extends string> = from<{
|
|
22
|
+
root: undefined;
|
|
23
|
+
branches: initialBranches;
|
|
24
|
+
groups: [];
|
|
25
|
+
finalizer: undefined;
|
|
26
|
+
scanned: "";
|
|
27
|
+
unscanned: def;
|
|
28
|
+
}>;
|
|
29
|
+
export type error<message extends string> = from<{
|
|
30
|
+
root: ErrorMessage<message>;
|
|
31
|
+
branches: initialBranches;
|
|
32
|
+
groups: [];
|
|
33
|
+
finalizer: ErrorMessage<message>;
|
|
34
|
+
scanned: "";
|
|
35
|
+
unscanned: "";
|
|
36
|
+
}>;
|
|
37
|
+
export type completion<text extends string> = from<{
|
|
38
|
+
root: Completion<text>;
|
|
39
|
+
branches: initialBranches;
|
|
40
|
+
groups: [];
|
|
41
|
+
finalizer: Completion<text>;
|
|
42
|
+
scanned: "";
|
|
43
|
+
unscanned: "";
|
|
44
|
+
}>;
|
|
45
|
+
type initialBranches = branchesFrom<{
|
|
46
|
+
prefixes: [];
|
|
47
|
+
leftBound: undefined;
|
|
48
|
+
intersection: undefined;
|
|
49
|
+
union: undefined;
|
|
50
|
+
}>;
|
|
51
|
+
type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
|
|
52
|
+
export type setRoot<s extends StaticState, root, unscanned extends string> = from<{
|
|
53
|
+
root: root;
|
|
54
|
+
branches: s["branches"];
|
|
55
|
+
groups: s["groups"];
|
|
56
|
+
finalizer: s["finalizer"];
|
|
57
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
58
|
+
unscanned: unscanned;
|
|
59
|
+
}>;
|
|
60
|
+
export type addPrefix<s extends StaticState, prefix extends StringifiablePrefixOperator, unscanned extends string> = from<{
|
|
61
|
+
root: s["root"];
|
|
62
|
+
branches: {
|
|
63
|
+
prefixes: [...s["branches"]["prefixes"], prefix];
|
|
64
|
+
leftBound: s["branches"]["leftBound"];
|
|
65
|
+
intersection: s["branches"]["intersection"];
|
|
66
|
+
union: s["branches"]["union"];
|
|
67
|
+
};
|
|
68
|
+
groups: s["groups"];
|
|
69
|
+
finalizer: s["finalizer"];
|
|
70
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
71
|
+
unscanned: unscanned;
|
|
72
|
+
}>;
|
|
73
|
+
export type reduceBranch<s extends StaticState, token extends "|" | "&", unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
|
|
74
|
+
root: undefined;
|
|
75
|
+
branches: {
|
|
76
|
+
prefixes: [];
|
|
77
|
+
leftBound: undefined;
|
|
78
|
+
intersection: token extends "&" ? mergeToIntersection<s> : undefined;
|
|
79
|
+
union: token extends "|" ? mergeToUnion<s> : s["branches"]["union"];
|
|
80
|
+
};
|
|
81
|
+
groups: s["groups"];
|
|
82
|
+
finalizer: s["finalizer"];
|
|
83
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
84
|
+
unscanned: unscanned;
|
|
85
|
+
}>;
|
|
86
|
+
export type reduceLeftBound<s extends StaticState, limit extends LimitLiteral, comparator extends Comparator, unscanned extends string> = comparator extends "<" | "<=" ? s["branches"]["leftBound"] extends {} ? state.error<writeMultipleLeftBoundsMessage<s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], limit, InvertedComparators[comparator]>> : from<{
|
|
87
|
+
root: undefined;
|
|
88
|
+
branches: {
|
|
89
|
+
prefixes: s["branches"]["prefixes"];
|
|
90
|
+
leftBound: {
|
|
91
|
+
limit: limit;
|
|
92
|
+
comparator: InvertedComparators[comparator];
|
|
93
|
+
};
|
|
94
|
+
intersection: s["branches"]["intersection"];
|
|
95
|
+
union: s["branches"]["union"];
|
|
96
|
+
};
|
|
97
|
+
groups: s["groups"];
|
|
98
|
+
finalizer: s["finalizer"];
|
|
99
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
100
|
+
unscanned: unscanned;
|
|
101
|
+
}> : state.error<writeUnpairableComparatorMessage<comparator>>;
|
|
102
|
+
export type reduceRange<s extends StaticState, minLimit extends LimitLiteral, minComparator extends MinComparator, maxComparator extends MaxComparator, maxLimit extends LimitLiteral, unscanned extends string> = state.from<{
|
|
103
|
+
root: [minLimit, minComparator, [s["root"], maxComparator, maxLimit]];
|
|
104
|
+
branches: {
|
|
105
|
+
prefixes: s["branches"]["prefixes"];
|
|
106
|
+
leftBound: undefined;
|
|
107
|
+
intersection: s["branches"]["intersection"];
|
|
108
|
+
union: s["branches"]["union"];
|
|
109
|
+
};
|
|
110
|
+
groups: s["groups"];
|
|
111
|
+
finalizer: s["finalizer"];
|
|
112
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
113
|
+
unscanned: unscanned;
|
|
114
|
+
}>;
|
|
115
|
+
export type reduceSingleBound<s extends StaticState, comparator extends Comparator, limit extends number | string, unscanned extends string> = state.from<{
|
|
116
|
+
root: [s["root"], comparator, limit];
|
|
117
|
+
branches: {
|
|
118
|
+
prefixes: s["branches"]["prefixes"];
|
|
119
|
+
leftBound: undefined;
|
|
120
|
+
intersection: s["branches"]["intersection"];
|
|
121
|
+
union: s["branches"]["union"];
|
|
122
|
+
};
|
|
123
|
+
groups: s["groups"];
|
|
124
|
+
finalizer: s["finalizer"];
|
|
125
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
126
|
+
unscanned: unscanned;
|
|
127
|
+
}>;
|
|
128
|
+
type mergeToUnion<s extends StaticState> = s["branches"]["union"] extends undefined ? mergeToIntersection<s> : [s["branches"]["union"], "|", mergeToIntersection<s>];
|
|
129
|
+
type mergeToIntersection<s extends StaticState> = s["branches"]["intersection"] extends undefined ? mergePrefixes<s> : [s["branches"]["intersection"], "&", mergePrefixes<s>];
|
|
130
|
+
type mergePrefixes<s extends StaticState, remaining extends unknown[] = s["branches"]["prefixes"]> = remaining extends [infer head, ...infer tail] ? [
|
|
131
|
+
head,
|
|
132
|
+
mergePrefixes<s, tail>
|
|
133
|
+
] : s["root"];
|
|
134
|
+
type popGroup<stack extends BranchState[], top extends BranchState> = [
|
|
135
|
+
...stack,
|
|
136
|
+
top
|
|
137
|
+
];
|
|
138
|
+
export type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
|
|
139
|
+
groups: stack;
|
|
140
|
+
branches: top;
|
|
141
|
+
root: mergeToUnion<s>;
|
|
142
|
+
finalizer: s["finalizer"];
|
|
143
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
144
|
+
unscanned: unscanned;
|
|
145
|
+
}> : state.error<writeUnmatchedGroupCloseMessage<unscanned>>;
|
|
146
|
+
export type reduceGroupOpen<s extends StaticState, unscanned extends string> = from<{
|
|
147
|
+
groups: [...s["groups"], s["branches"]];
|
|
148
|
+
branches: initialBranches;
|
|
149
|
+
root: undefined;
|
|
150
|
+
finalizer: s["finalizer"];
|
|
151
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
152
|
+
unscanned: unscanned;
|
|
153
|
+
}>;
|
|
154
|
+
export type finalize<s extends StaticState, finalizer extends Scanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
|
|
155
|
+
root: mergeToUnion<s>;
|
|
156
|
+
groups: s["groups"];
|
|
157
|
+
branches: initialBranches;
|
|
158
|
+
finalizer: finalizer;
|
|
159
|
+
scanned: s["scanned"];
|
|
160
|
+
unscanned: s["unscanned"];
|
|
161
|
+
}> : state.error<writeUnclosedGroupMessage<")">>;
|
|
162
|
+
type openRangeError<range extends defined<BranchState["leftBound"]>> = state.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
|
|
163
|
+
export type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends ([
|
|
164
|
+
...unknown[],
|
|
165
|
+
infer tail extends string
|
|
166
|
+
]) ? tail : s["branches"]["intersection"] extends {} ? "&" : s["branches"]["union"] extends {} ? "|" : undefined;
|
|
167
|
+
export type scanTo<s extends StaticState, unscanned extends string> = from<{
|
|
168
|
+
root: s["root"];
|
|
169
|
+
branches: s["branches"];
|
|
170
|
+
groups: s["groups"];
|
|
171
|
+
finalizer: s["finalizer"];
|
|
172
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
173
|
+
unscanned: unscanned;
|
|
174
|
+
}>;
|
|
175
|
+
export type from<s extends StaticState> = s;
|
|
176
|
+
export type branchesFrom<b extends BranchState> = b;
|
|
177
|
+
export {};
|
|
178
|
+
}
|
|
179
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DateLiteral } from "@ark/schema";
|
|
2
|
+
export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
|
|
3
|
+
export declare const isValidDate: (d: Date) => boolean;
|
|
4
|
+
export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
|
|
5
|
+
export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
|
|
6
|
+
export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
|
|
7
|
+
export type DateInput = ConstructorParameters<typeof Date>[0];
|
|
8
|
+
export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
|
|
9
|
+
export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { throwParseError, tryParseNumber } from "@ark/util";
|
|
2
|
+
export const isDateLiteral = (value) => typeof value === "string" &&
|
|
3
|
+
value[0] === "d" &&
|
|
4
|
+
(value[1] === "'" || value[1] === '"') &&
|
|
5
|
+
value.at(-1) === value[1];
|
|
6
|
+
export const isValidDate = (d) => d.toString() !== "Invalid Date";
|
|
7
|
+
export const extractDateLiteralSource = (literal) => literal.slice(2, -1);
|
|
8
|
+
export const writeInvalidDateMessage = (source) => `'${source}' could not be parsed by the Date constructor`;
|
|
9
|
+
export const tryParseDate = (source, errorOnFail) => maybeParseDate(source, errorOnFail);
|
|
10
|
+
const maybeParseDate = (source, errorOnFail) => {
|
|
11
|
+
const stringParsedDate = new Date(source);
|
|
12
|
+
if (isValidDate(stringParsedDate))
|
|
13
|
+
return stringParsedDate;
|
|
14
|
+
const epochMillis = tryParseNumber(source);
|
|
15
|
+
if (epochMillis !== undefined) {
|
|
16
|
+
const numberParsedDate = new Date(epochMillis);
|
|
17
|
+
if (isValidDate(numberParsedDate))
|
|
18
|
+
return numberParsedDate;
|
|
19
|
+
}
|
|
20
|
+
return errorOnFail ?
|
|
21
|
+
throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail)
|
|
22
|
+
: undefined;
|
|
23
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
2
|
+
import type { StaticState, state } from "../../reduce/static.js";
|
|
3
|
+
import type { Scanner } from "../scanner.js";
|
|
4
|
+
export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
|
|
5
|
+
export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
|
|
6
|
+
export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
|
|
7
|
+
export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
|
|
8
|
+
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
|
|
9
|
+
export declare const enclosingQuote: {
|
|
10
|
+
readonly "'": 1;
|
|
11
|
+
readonly '"': 1;
|
|
12
|
+
};
|
|
13
|
+
export type EnclosingQuote = keyof typeof enclosingQuote;
|
|
14
|
+
export declare const enclosingChar: {
|
|
15
|
+
readonly "/": 1;
|
|
16
|
+
readonly "'": 1;
|
|
17
|
+
readonly '"': 1;
|
|
18
|
+
};
|
|
19
|
+
export declare const enclosingTokens: {
|
|
20
|
+
readonly "d'": "'";
|
|
21
|
+
readonly 'd"': "\"";
|
|
22
|
+
readonly "'": "'";
|
|
23
|
+
readonly '"': "\"";
|
|
24
|
+
readonly "/": "/";
|
|
25
|
+
};
|
|
26
|
+
export type EnclosingTokens = typeof enclosingTokens;
|
|
27
|
+
export type EnclosingStartToken = keyof EnclosingTokens;
|
|
28
|
+
export type EnclosingEndToken = EnclosingTokens[keyof EnclosingTokens];
|
|
29
|
+
export declare const untilLookaheadIsClosing: Record<EnclosingEndToken, Scanner.UntilCondition>;
|
|
30
|
+
declare const enclosingCharDescriptions: {
|
|
31
|
+
readonly '"': "double-quote";
|
|
32
|
+
readonly "'": "single-quote";
|
|
33
|
+
readonly "/": "forward slash";
|
|
34
|
+
};
|
|
35
|
+
type enclosingCharDescriptions = typeof enclosingCharDescriptions;
|
|
36
|
+
export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosingStart extends EnclosingStartToken>(fragment: fragment, enclosingStart: enclosingStart) => writeUnterminatedEnclosedMessage<fragment, enclosingStart>;
|
|
37
|
+
export type writeUnterminatedEnclosedMessage<fragment extends string, enclosingStart extends EnclosingStartToken> = `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[EnclosingTokens[enclosingStart]]}`;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isKeyOf } from "@ark/util";
|
|
2
|
+
import { tryParseDate, writeInvalidDateMessage } from "./date.js";
|
|
3
|
+
export const parseEnclosed = (s, enclosing) => {
|
|
4
|
+
const enclosed = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
|
|
5
|
+
if (s.scanner.lookahead === "")
|
|
6
|
+
return s.error(writeUnterminatedEnclosedMessage(enclosed, enclosing));
|
|
7
|
+
// Shift the scanner one additional time for the second enclosing token
|
|
8
|
+
s.scanner.shift();
|
|
9
|
+
if (enclosing === "/") {
|
|
10
|
+
// fail parsing if the regex is invalid
|
|
11
|
+
new RegExp(enclosed);
|
|
12
|
+
s.root = s.ctx.$.node("intersection", {
|
|
13
|
+
domain: "string",
|
|
14
|
+
pattern: enclosed
|
|
15
|
+
}, { prereduced: true });
|
|
16
|
+
}
|
|
17
|
+
else if (isKeyOf(enclosing, enclosingQuote))
|
|
18
|
+
s.root = s.ctx.$.node("unit", { unit: enclosed });
|
|
19
|
+
else {
|
|
20
|
+
const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed));
|
|
21
|
+
s.root = s.ctx.$.node("unit", { unit: date, description: enclosed });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const enclosingQuote = {
|
|
25
|
+
"'": 1,
|
|
26
|
+
'"': 1
|
|
27
|
+
};
|
|
28
|
+
export const enclosingChar = {
|
|
29
|
+
"/": 1,
|
|
30
|
+
"'": 1,
|
|
31
|
+
'"': 1
|
|
32
|
+
};
|
|
33
|
+
export const enclosingTokens = {
|
|
34
|
+
"d'": "'",
|
|
35
|
+
'd"': '"',
|
|
36
|
+
"'": "'",
|
|
37
|
+
'"': '"',
|
|
38
|
+
"/": "/"
|
|
39
|
+
};
|
|
40
|
+
export const untilLookaheadIsClosing = {
|
|
41
|
+
"'": scanner => scanner.lookahead === `'`,
|
|
42
|
+
'"': scanner => scanner.lookahead === `"`,
|
|
43
|
+
"/": scanner => scanner.lookahead === `/`
|
|
44
|
+
};
|
|
45
|
+
const enclosingCharDescriptions = {
|
|
46
|
+
'"': "double-quote",
|
|
47
|
+
"'": "single-quote",
|
|
48
|
+
"/": "forward slash"
|
|
49
|
+
};
|
|
50
|
+
export const writeUnterminatedEnclosedMessage = (fragment, enclosingStart) => `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[enclosingTokens[enclosingStart]]}`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { BaseRoot, GenericProps, GenericRoot } from "@ark/schema";
|
|
2
|
+
import type { array, ErrorMessage, join } from "@ark/util";
|
|
3
|
+
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
4
|
+
import { writeUnclosedGroupMessage } from "../../reduce/shared.js";
|
|
5
|
+
import type { state, StaticState } from "../../reduce/static.js";
|
|
6
|
+
import type { parseUntilFinalizer } from "../../string.js";
|
|
7
|
+
export declare const parseGenericArgs: (name: string, g: GenericRoot, s: DynamicState) => BaseRoot[];
|
|
8
|
+
export type parseGenericArgs<name extends string, g extends GenericProps, unscanned extends string, $, args> = _parseGenericArgs<name, g, unscanned, $, args, [], []>;
|
|
9
|
+
declare const _parseGenericArgs: (name: string, g: GenericRoot, s: DynamicState, argNodes: BaseRoot[]) => BaseRoot[];
|
|
10
|
+
export type ParsedArgs<result extends unknown[] = unknown[], unscanned extends string = string> = {
|
|
11
|
+
result: result;
|
|
12
|
+
unscanned: unscanned;
|
|
13
|
+
};
|
|
14
|
+
type _parseGenericArgs<name extends string, g extends GenericProps, unscanned extends string, $, args, argDefs extends string[], argAsts extends unknown[]> = parseUntilFinalizer<state.initialize<unscanned>, $, args> extends (infer finalArgState extends StaticState) ? {
|
|
15
|
+
defs: [
|
|
16
|
+
...argDefs,
|
|
17
|
+
finalArgState["scanned"] extends `${infer def}${"," | ">"}` ? def : finalArgState["scanned"]
|
|
18
|
+
];
|
|
19
|
+
asts: [...argAsts, finalArgState["root"]];
|
|
20
|
+
unscanned: finalArgState["unscanned"];
|
|
21
|
+
} extends ({
|
|
22
|
+
defs: infer nextDefs extends string[];
|
|
23
|
+
asts: infer nextAsts extends unknown[];
|
|
24
|
+
unscanned: infer nextUnscanned extends string;
|
|
25
|
+
}) ? finalArgState["finalizer"] extends ">" ? nextAsts["length"] extends g["params"]["length"] ? ParsedArgs<nextAsts, nextUnscanned> : state.error<writeInvalidGenericArgCountMessage<name, g["names"], nextDefs>> : finalArgState["finalizer"] extends "," ? _parseGenericArgs<name, g, nextUnscanned, $, args, nextDefs, nextAsts> : finalArgState["finalizer"] extends ErrorMessage ? finalArgState : state.error<writeUnclosedGroupMessage<">">> : never : never;
|
|
26
|
+
export declare const writeInvalidGenericArgCountMessage: <name extends string, params extends array<string>, argDefs extends array<string>>(name: name, params: params, argDefs: argDefs) => writeInvalidGenericArgCountMessage<name, params, argDefs>;
|
|
27
|
+
export type writeInvalidGenericArgCountMessage<name extends string, params extends array<string>, argDefs extends array<string>> = `${name}<${join<params, ", ">}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends (0) ? "" : `: ${join<argDefs, ",">}`})`;
|
|
28
|
+
export {};
|