arktype 2.0.0-dev.1 → 2.0.0-dev.11
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/out/api.d.ts +6 -0
- package/out/api.js +5 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/main.d.ts +6 -7
- package/out/main.js +4 -3
- package/out/match.d.ts +57 -34
- package/out/match.js +51 -17
- package/out/module.d.ts +12 -0
- package/out/module.js +3 -0
- package/out/parser/definition.d.ts +14 -14
- package/out/parser/definition.js +10 -13
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/objectLiteral.d.ts +44 -18
- package/out/parser/objectLiteral.js +57 -51
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +16 -13
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/shared.d.ts +14 -28
- package/out/parser/string/reduce/shared.js +4 -3
- package/out/parser/string/reduce/static.d.ts +27 -24
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -2
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/string/shift/operand/enclosed.js +14 -14
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +8 -12
- package/out/parser/string/shift/operand/unenclosed.d.ts +16 -21
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +45 -56
- package/out/parser/string/shift/operator/divisor.d.ts +1 -3
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/operator.d.ts +1 -2
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/scanner.d.ts +2 -2
- package/out/parser/string/shift/scanner.js +14 -16
- package/out/parser/string/string.d.ts +8 -6
- package/out/parser/string/string.js +1 -3
- package/out/parser/tuple.d.ts +102 -43
- package/out/parser/tuple.js +119 -87
- package/out/scope.d.ts +44 -119
- package/out/scope.js +39 -209
- package/out/type.d.ts +43 -64
- package/out/type.js +30 -131
- package/package.json +12 -10
- package/__tests__/array.test.ts +0 -272
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/badDefinitionType.test.ts +0 -51
- package/__tests__/basis.test.ts +0 -46
- package/__tests__/bounds.test.ts +0 -388
- package/__tests__/cast.test.ts +0 -32
- package/__tests__/completions.test.ts +0 -46
- package/__tests__/config.test.ts +0 -168
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/dateLiteral.test.ts +0 -32
- package/__tests__/declared.test.ts +0 -123
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -90
- package/__tests__/enclosed.test.ts +0 -93
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -138
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -294
- package/__tests__/group.test.ts +0 -72
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -113
- package/__tests__/instanceof.test.ts +0 -102
- package/__tests__/intersection.test.ts +0 -104
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/keyTraversal.test.ts +0 -73
- package/__tests__/keyof.test.ts +0 -134
- package/__tests__/keywords.test.ts +0 -188
- package/__tests__/literal.test.ts +0 -51
- package/__tests__/match.test.ts +0 -34
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/narrow.test.ts +0 -102
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -300
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/regex.test.ts +0 -58
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -140
- package/__tests__/string.test.ts +0 -48
- package/__tests__/submodule.test.ts +0 -99
- package/__tests__/this.test.ts +0 -57
- package/__tests__/thunk.test.ts +0 -80
- package/__tests__/traverse.test.ts +0 -119
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/typeMethods.test.ts +0 -69
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -120
- package/__tests__/union.test.ts +0 -147
- package/ark.ts +0 -91
- package/main.ts +0 -18
- package/match.ts +0 -116
- package/out/ark.d.ts.map +0 -1
- package/out/ark.js.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts.map +0 -1
- package/out/main.js.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/match.js.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/shared.d.ts +0 -54
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -47
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/type.js.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/definition.ts +0 -159
- package/parser/generic.ts +0 -68
- package/parser/objectLiteral.ts +0 -197
- package/parser/semantic/bounds.ts +0 -61
- package/parser/semantic/divisor.ts +0 -13
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -144
- package/parser/semantic/utils.ts +0 -26
- package/parser/semantic/validate.ts +0 -109
- package/parser/shared.ts +0 -152
- package/parser/string/reduce/dynamic.ts +0 -196
- package/parser/string/reduce/shared.ts +0 -101
- package/parser/string/reduce/static.ts +0 -298
- package/parser/string/shift/operand/date.ts +0 -54
- package/parser/string/shift/operand/enclosed.ts +0 -118
- package/parser/string/shift/operand/genericArgs.ts +0 -127
- package/parser/string/shift/operand/operand.ts +0 -48
- package/parser/string/shift/operand/unenclosed.ts +0 -268
- package/parser/string/shift/operator/bounds.ts +0 -264
- package/parser/string/shift/operator/divisor.ts +0 -36
- package/parser/string/shift/operator/operator.ts +0 -82
- package/parser/string/shift/scanner.ts +0 -209
- package/parser/string/string.ts +0 -90
- package/parser/tuple.ts +0 -474
- package/scope.ts +0 -574
- package/type.ts +0 -347
- package/util.ts +0 -36
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LimitLiteral } from "@arktype/schema";
|
|
2
|
+
import type { Completion, ErrorMessage, defined } from "@arktype/util";
|
|
2
3
|
import type { Scanner } from "../shift/scanner.js";
|
|
3
|
-
import type { Comparator, InvertedComparators,
|
|
4
|
+
import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
|
|
4
5
|
export type StaticState = {
|
|
5
6
|
root: unknown;
|
|
6
7
|
branches: BranchState;
|
|
@@ -9,13 +10,13 @@ export type StaticState = {
|
|
|
9
10
|
scanned: string;
|
|
10
11
|
unscanned: string;
|
|
11
12
|
};
|
|
12
|
-
export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
|
|
13
13
|
type BranchState = {
|
|
14
14
|
prefixes: StringifiablePrefixOperator[];
|
|
15
15
|
leftBound: OpenLeftBound | undefined;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
intersection: unknown;
|
|
17
|
+
union: unknown;
|
|
18
18
|
};
|
|
19
|
+
export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
|
|
19
20
|
export declare namespace state {
|
|
20
21
|
export type initialize<def extends string> = from<{
|
|
21
22
|
root: undefined;
|
|
@@ -44,8 +45,8 @@ export declare namespace state {
|
|
|
44
45
|
type initialBranches = branchesFrom<{
|
|
45
46
|
prefixes: [];
|
|
46
47
|
leftBound: undefined;
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
intersection: undefined;
|
|
49
|
+
union: undefined;
|
|
49
50
|
}>;
|
|
50
51
|
type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
|
|
51
52
|
export type setRoot<s extends StaticState, root, unscanned extends string> = from<{
|
|
@@ -61,8 +62,8 @@ export declare namespace state {
|
|
|
61
62
|
branches: {
|
|
62
63
|
prefixes: [...s["branches"]["prefixes"], prefix];
|
|
63
64
|
leftBound: s["branches"]["leftBound"];
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
intersection: s["branches"]["intersection"];
|
|
66
|
+
union: s["branches"]["union"];
|
|
66
67
|
};
|
|
67
68
|
groups: s["groups"];
|
|
68
69
|
finalizer: s["finalizer"];
|
|
@@ -74,8 +75,8 @@ export declare namespace state {
|
|
|
74
75
|
branches: {
|
|
75
76
|
prefixes: [];
|
|
76
77
|
leftBound: undefined;
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
intersection: token extends "&" ? mergeToIntersection<s> : undefined;
|
|
79
|
+
union: token extends "|" ? mergeToUnion<s> : s["branches"]["union"];
|
|
79
80
|
};
|
|
80
81
|
groups: s["groups"];
|
|
81
82
|
finalizer: s["finalizer"];
|
|
@@ -90,8 +91,8 @@ export declare namespace state {
|
|
|
90
91
|
limit: limit;
|
|
91
92
|
comparator: InvertedComparators[comparator];
|
|
92
93
|
};
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
intersection: s["branches"]["intersection"];
|
|
95
|
+
union: s["branches"]["union"];
|
|
95
96
|
};
|
|
96
97
|
groups: s["groups"];
|
|
97
98
|
finalizer: s["finalizer"];
|
|
@@ -103,30 +104,33 @@ export declare namespace state {
|
|
|
103
104
|
branches: {
|
|
104
105
|
prefixes: s["branches"]["prefixes"];
|
|
105
106
|
leftBound: undefined;
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
intersection: s["branches"]["intersection"];
|
|
108
|
+
union: s["branches"]["union"];
|
|
108
109
|
};
|
|
109
110
|
groups: s["groups"];
|
|
110
111
|
finalizer: s["finalizer"];
|
|
111
112
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
112
113
|
unscanned: unscanned;
|
|
113
114
|
}>;
|
|
114
|
-
export type reduceSingleBound<s extends StaticState, comparator extends Comparator, limit extends
|
|
115
|
+
export type reduceSingleBound<s extends StaticState, comparator extends Comparator, limit extends number | string, unscanned extends string> = state.from<{
|
|
115
116
|
root: [s["root"], comparator, limit];
|
|
116
117
|
branches: {
|
|
117
118
|
prefixes: s["branches"]["prefixes"];
|
|
118
119
|
leftBound: undefined;
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
intersection: s["branches"]["intersection"];
|
|
121
|
+
union: s["branches"]["union"];
|
|
121
122
|
};
|
|
122
123
|
groups: s["groups"];
|
|
123
124
|
finalizer: s["finalizer"];
|
|
124
125
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
125
126
|
unscanned: unscanned;
|
|
126
127
|
}>;
|
|
127
|
-
type mergeToUnion<s extends StaticState> = s["branches"]["
|
|
128
|
-
type mergeToIntersection<s extends StaticState> = s["branches"]["
|
|
129
|
-
type mergePrefixes<s extends StaticState, remaining extends unknown[] = s["branches"]["prefixes"]> = remaining extends [infer head, ...infer tail] ? [
|
|
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"];
|
|
130
134
|
type popGroup<stack extends BranchState[], top extends BranchState> = [
|
|
131
135
|
...stack,
|
|
132
136
|
top
|
|
@@ -156,10 +160,10 @@ export declare namespace state {
|
|
|
156
160
|
unscanned: s["unscanned"];
|
|
157
161
|
}> : state.error<writeUnclosedGroupMessage<")">>;
|
|
158
162
|
type openRangeError<range extends defined<BranchState["leftBound"]>> = state.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
|
|
159
|
-
export type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends [
|
|
163
|
+
export type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends ([
|
|
160
164
|
...unknown[],
|
|
161
165
|
infer tail extends string
|
|
162
|
-
] ? tail : s["branches"]["
|
|
166
|
+
]) ? tail : s["branches"]["intersection"] extends {} ? "&" : s["branches"]["union"] extends {} ? "|" : undefined;
|
|
163
167
|
export type scanTo<s extends StaticState, unscanned extends string> = from<{
|
|
164
168
|
root: s["root"];
|
|
165
169
|
branches: s["branches"];
|
|
@@ -173,4 +177,3 @@ export declare namespace state {
|
|
|
173
177
|
export {};
|
|
174
178
|
}
|
|
175
179
|
export {};
|
|
176
|
-
//# sourceMappingURL=static.d.ts.map
|
|
@@ -6,6 +6,6 @@ type extractDateLiteralSource<literal extends DateLiteral> = literal extends Dat
|
|
|
6
6
|
export declare const writeInvalidDateMessage: <source extends string>(source: source) => `'${source}' could not be parsed by the Date constructor`;
|
|
7
7
|
export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
|
|
8
8
|
export type DateInput = ConstructorParameters<typeof Date>[0];
|
|
9
|
-
export
|
|
9
|
+
export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
|
|
10
|
+
export declare const tryParseDate: <errorOnFail extends string | boolean>(source: string, errorOnFail?: errorOnFail | undefined) => DateParseResult<errorOnFail>;
|
|
10
11
|
export {};
|
|
11
|
-
//# sourceMappingURL=date.d.ts.map
|
|
@@ -9,18 +9,15 @@ export const writeInvalidDateMessage = (source) => `'${source}' could not be par
|
|
|
9
9
|
export const tryParseDate = (source, errorOnFail) => maybeParseDate(source, errorOnFail);
|
|
10
10
|
const maybeParseDate = (source, errorOnFail) => {
|
|
11
11
|
const stringParsedDate = new Date(source);
|
|
12
|
-
if (isValidDate(stringParsedDate))
|
|
12
|
+
if (isValidDate(stringParsedDate))
|
|
13
13
|
return stringParsedDate;
|
|
14
|
-
}
|
|
15
14
|
const epochMillis = tryParseNumber(source);
|
|
16
15
|
if (epochMillis !== undefined) {
|
|
17
16
|
const numberParsedDate = new Date(epochMillis);
|
|
18
|
-
if (isValidDate(numberParsedDate))
|
|
17
|
+
if (isValidDate(numberParsedDate))
|
|
19
18
|
return numberParsedDate;
|
|
20
|
-
}
|
|
21
19
|
}
|
|
22
|
-
return errorOnFail
|
|
23
|
-
|
|
20
|
+
return errorOnFail ?
|
|
21
|
+
throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail)
|
|
24
22
|
: undefined;
|
|
25
23
|
};
|
|
26
|
-
//# sourceMappingURL=date.js.map
|
|
@@ -4,17 +4,17 @@ import type { Scanner } from "../scanner.js";
|
|
|
4
4
|
export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
|
|
5
5
|
export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
|
|
6
6
|
export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
|
|
7
|
-
export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) =>
|
|
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;
|
|
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
9
|
export declare const enclosingQuote: {
|
|
10
10
|
readonly "'": 1;
|
|
11
11
|
readonly '"': 1;
|
|
12
12
|
};
|
|
13
13
|
export type EnclosingQuote = keyof typeof enclosingQuote;
|
|
14
14
|
export declare const enclosingChar: {
|
|
15
|
+
readonly "/": 1;
|
|
15
16
|
readonly "'": 1;
|
|
16
17
|
readonly '"': 1;
|
|
17
|
-
readonly "/": 1;
|
|
18
18
|
};
|
|
19
19
|
export declare const enclosingTokens: {
|
|
20
20
|
readonly "d'": "'";
|
|
@@ -46,4 +46,3 @@ export declare const writeUnterminatedEnclosedMessage: <fragment extends string,
|
|
|
46
46
|
}[enclosingStart]]}`;
|
|
47
47
|
export type writeUnterminatedEnclosedMessage<fragment extends string, enclosingStart extends EnclosingStartToken> = `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[EnclosingTokens[enclosingStart]]}`;
|
|
48
48
|
export {};
|
|
49
|
-
//# sourceMappingURL=enclosed.d.ts.map
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { schema } from "@arktype/schema";
|
|
2
1
|
import { isKeyOf } from "@arktype/util";
|
|
3
2
|
import { tryParseDate, writeInvalidDateMessage } from "./date.js";
|
|
4
3
|
export const parseEnclosed = (s, enclosing) => {
|
|
5
4
|
const enclosed = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
|
|
6
|
-
if (s.scanner.lookahead === "")
|
|
5
|
+
if (s.scanner.lookahead === "")
|
|
7
6
|
return s.error(writeUnterminatedEnclosedMessage(enclosed, enclosing));
|
|
8
|
-
}
|
|
9
7
|
// Shift the scanner one additional time for the second enclosing token
|
|
10
|
-
|
|
8
|
+
s.scanner.shift();
|
|
11
9
|
if (enclosing === "/") {
|
|
12
10
|
// fail parsing if the regex is invalid
|
|
13
11
|
new RegExp(enclosed);
|
|
14
|
-
s.root =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
s.root = s.ctx.$.node("intersection", {
|
|
13
|
+
domain: "string",
|
|
14
|
+
regex: enclosed
|
|
15
|
+
}, { prereduced: true });
|
|
18
16
|
}
|
|
17
|
+
else if (isKeyOf(enclosing, enclosingQuote))
|
|
18
|
+
s.root = s.ctx.$.node("unit", { unit: enclosed });
|
|
19
19
|
else {
|
|
20
20
|
const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed));
|
|
21
|
-
s.root =
|
|
21
|
+
s.root = s.ctx.$.node("unit", { unit: date, description: enclosed });
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
export const enclosingQuote = {
|
|
@@ -27,7 +27,8 @@ export const enclosingQuote = {
|
|
|
27
27
|
};
|
|
28
28
|
export const enclosingChar = {
|
|
29
29
|
"/": 1,
|
|
30
|
-
|
|
30
|
+
"'": 1,
|
|
31
|
+
'"': 1
|
|
31
32
|
};
|
|
32
33
|
export const enclosingTokens = {
|
|
33
34
|
"d'": "'",
|
|
@@ -37,9 +38,9 @@ export const enclosingTokens = {
|
|
|
37
38
|
"/": "/"
|
|
38
39
|
};
|
|
39
40
|
export const untilLookaheadIsClosing = {
|
|
40
|
-
"'":
|
|
41
|
-
'"':
|
|
42
|
-
"/":
|
|
41
|
+
"'": scanner => scanner.lookahead === `'`,
|
|
42
|
+
'"': scanner => scanner.lookahead === `"`,
|
|
43
|
+
"/": scanner => scanner.lookahead === `/`
|
|
43
44
|
};
|
|
44
45
|
const enclosingCharDescriptions = {
|
|
45
46
|
'"': "double-quote",
|
|
@@ -47,4 +48,3 @@ const enclosingCharDescriptions = {
|
|
|
47
48
|
"/": "forward slash"
|
|
48
49
|
};
|
|
49
50
|
export const writeUnterminatedEnclosedMessage = (fragment, enclosingStart) => `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[enclosingTokens[enclosingStart]]}`;
|
|
50
|
-
//# sourceMappingURL=enclosed.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseRoot } from "@arktype/schema";
|
|
2
2
|
import type { ErrorMessage, join } from "@arktype/util";
|
|
3
3
|
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
4
4
|
import { writeUnclosedGroupMessage } from "../../reduce/shared.js";
|
|
@@ -8,22 +8,21 @@ export type ParsedArgs<result extends unknown[] = unknown[], unscanned extends s
|
|
|
8
8
|
result: result;
|
|
9
9
|
unscanned: unscanned;
|
|
10
10
|
};
|
|
11
|
-
export declare const parseGenericArgs: (name: string, params: string[], s: DynamicState) => ParsedArgs<
|
|
12
|
-
export type parseGenericArgs<name extends string, params extends string[], unscanned extends string, $, args> =
|
|
13
|
-
declare const
|
|
14
|
-
type
|
|
11
|
+
export declare const parseGenericArgs: (name: string, params: string[], s: DynamicState) => ParsedArgs<BaseRoot[]>;
|
|
12
|
+
export type parseGenericArgs<name extends string, params extends string[], unscanned extends string, $, args> = _parseGenericArgs<name, params, unscanned, $, args, [], []>;
|
|
13
|
+
declare const _parseGenericArgs: (name: string, params: string[], s: DynamicState, argDefs: string[], argNodes: BaseRoot[]) => ParsedArgs<BaseRoot[]>;
|
|
14
|
+
type _parseGenericArgs<name extends string, params extends string[], unscanned extends string, $, args, argDefs extends string[], argAsts extends unknown[]> = parseUntilFinalizer<state.initialize<unscanned>, $, args> extends (infer finalArgState extends StaticState) ? {
|
|
15
15
|
defs: [
|
|
16
16
|
...argDefs,
|
|
17
17
|
finalArgState["scanned"] extends `${infer def}${"," | ">"}` ? def : finalArgState["scanned"]
|
|
18
18
|
];
|
|
19
19
|
asts: [...argAsts, finalArgState["root"]];
|
|
20
20
|
unscanned: finalArgState["unscanned"];
|
|
21
|
-
} extends {
|
|
21
|
+
} extends ({
|
|
22
22
|
defs: infer nextDefs extends string[];
|
|
23
23
|
asts: infer nextAsts extends unknown[];
|
|
24
24
|
unscanned: infer nextUnscanned extends string;
|
|
25
|
-
} ? finalArgState["finalizer"] extends ">" ? nextAsts["length"] extends params["length"] ? ParsedArgs<nextAsts, nextUnscanned> : state.error<writeInvalidGenericArgsMessage<name, params, nextDefs>> : finalArgState["finalizer"] extends "," ?
|
|
26
|
-
export declare const writeInvalidGenericArgsMessage: <name extends string, params extends string[], argDefs extends string[]>(name: name, params: params, argDefs: argDefs) =>
|
|
27
|
-
export type writeInvalidGenericArgsMessage<name extends string, params extends string[], argDefs extends string[]> = `${name}<${join<params, ", ">}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends 0 ? "" : `: ${join<argDefs, ",">}`})`;
|
|
25
|
+
}) ? finalArgState["finalizer"] extends ">" ? nextAsts["length"] extends params["length"] ? ParsedArgs<nextAsts, nextUnscanned> : state.error<writeInvalidGenericArgsMessage<name, params, nextDefs>> : finalArgState["finalizer"] extends "," ? _parseGenericArgs<name, params, nextUnscanned, $, args, nextDefs, nextAsts> : finalArgState["finalizer"] extends ErrorMessage ? finalArgState : state.error<writeUnclosedGroupMessage<">">> : never : never;
|
|
26
|
+
export declare const writeInvalidGenericArgsMessage: <name extends string, params extends string[], argDefs extends string[]>(name: name, params: params, argDefs: argDefs) => `${name}<${join<params, ", ", "">}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends 0 ? "" : `: ${join<argDefs, ",", "">}`})`;
|
|
27
|
+
export type writeInvalidGenericArgsMessage<name extends string, params extends string[], argDefs extends string[]> = `${name}<${join<params, ", ">}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends (0) ? "" : `: ${join<argDefs, ",">}`})`;
|
|
28
28
|
export {};
|
|
29
|
-
//# sourceMappingURL=genericArgs.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeUnclosedGroupMessage } from "../../reduce/shared.js";
|
|
2
|
-
export const parseGenericArgs = (name, params, s) =>
|
|
3
|
-
const
|
|
2
|
+
export const parseGenericArgs = (name, params, s) => _parseGenericArgs(name, params, s, [], []);
|
|
3
|
+
const _parseGenericArgs = (name, params, s, argDefs, argNodes) => {
|
|
4
4
|
const argState = s.parseUntilFinalizer();
|
|
5
5
|
// remove the finalizing token from the argDef
|
|
6
6
|
argDefs.push(argState.scanner.scanned.slice(0, -1));
|
|
@@ -12,14 +12,10 @@ const parseGenericArgsRecurse = (name, params, s, argDefs, argNodes) => {
|
|
|
12
12
|
unscanned: argState.scanner.unscanned
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return argState.error(writeInvalidGenericArgsMessage(name, params, argDefs));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
else if (argState.finalizer === ",") {
|
|
20
|
-
return parseGenericArgsRecurse(name, params, s, argDefs, argNodes);
|
|
15
|
+
return argState.error(writeInvalidGenericArgsMessage(name, params, argDefs));
|
|
21
16
|
}
|
|
17
|
+
if (argState.finalizer === ",")
|
|
18
|
+
return _parseGenericArgs(name, params, s, argDefs, argNodes);
|
|
22
19
|
return argState.error(writeUnclosedGroupMessage(">"));
|
|
23
20
|
};
|
|
24
|
-
export const writeInvalidGenericArgsMessage = (name, params, argDefs) => `${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${argDefs.length}${argDefs.length === 0 ? "" :
|
|
25
|
-
//# sourceMappingURL=genericArgs.js.map
|
|
21
|
+
export const writeInvalidGenericArgsMessage = (name, params, argDefs) => `${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${argDefs.length}${argDefs.length === 0 ? "" : `: ${argDefs.join(", ")}`})`;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { StaticState, state } from "../../reduce/static.js";
|
|
3
3
|
import type { BaseCompletions } from "../../string.js";
|
|
4
4
|
import { Scanner } from "../scanner.js";
|
|
5
|
-
import {
|
|
5
|
+
import { type EnclosingQuote, type EnclosingStartToken, parseEnclosed } from "./enclosed.js";
|
|
6
6
|
import { parseUnenclosed } from "./unenclosed.js";
|
|
7
7
|
export declare const parseOperand: (s: DynamicState) => void;
|
|
8
|
-
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends
|
|
9
|
-
//# sourceMappingURL=operand.d.ts.map
|
|
8
|
+
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends Scanner.WhiteSpaceToken ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { Scanner } from "../scanner.js";
|
|
2
2
|
import { enclosingChar, parseEnclosed } from "./enclosed.js";
|
|
3
3
|
import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
|
|
4
|
-
export const parseOperand = (s) => s.scanner.lookahead === ""
|
|
5
|
-
? s.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
: s.scanner.lookahead === "d"
|
|
13
|
-
? s.shiftedByOne().scanner.lookaheadIsIn(enclosingChar)
|
|
14
|
-
? parseEnclosed(s, `d${s.scanner.shift()}`)
|
|
4
|
+
export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
|
|
5
|
+
: s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen()
|
|
6
|
+
: s.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s, s.scanner.shift())
|
|
7
|
+
: s.scanner.lookaheadIsIn(Scanner.whiteSpaceTokens) ?
|
|
8
|
+
parseOperand(s.shiftedByOne())
|
|
9
|
+
: s.scanner.lookahead === "d" ?
|
|
10
|
+
s.shiftedByOne().scanner.lookaheadIsIn(enclosingChar) ?
|
|
11
|
+
parseEnclosed(s, `d${s.scanner.shift()}`)
|
|
15
12
|
: parseUnenclosed(s)
|
|
16
13
|
: parseUnenclosed(s);
|
|
17
|
-
//# sourceMappingURL=operand.js.map
|
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type BigintLiteral, type Completion, type ErrorMessage, type
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { GenericInstantiationAst } from "../../../semantic/semantic.js";
|
|
1
|
+
import { BaseRoot, type GenericProps, type arkKind, type writeNonSubmoduleDotMessage, writeUnresolvableMessage } from "@arktype/schema";
|
|
2
|
+
import { type BigintLiteral, type Completion, type ErrorMessage, type anyOrNever, type join } from "@arktype/util";
|
|
3
|
+
import type { Generic } from "../../../../generic.js";
|
|
4
|
+
import type { GenericInstantiationAst } from "../../../semantic/infer.js";
|
|
6
5
|
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
7
|
-
import type {
|
|
6
|
+
import type { StaticState, state } from "../../reduce/static.js";
|
|
8
7
|
import type { BaseCompletions } from "../../string.js";
|
|
9
8
|
import type { Scanner } from "../scanner.js";
|
|
10
|
-
import { parseGenericArgs, writeInvalidGenericArgsMessage
|
|
9
|
+
import { type ParsedArgs, parseGenericArgs, writeInvalidGenericArgsMessage } from "./genericArgs.js";
|
|
11
10
|
export declare const parseUnenclosed: (s: DynamicState) => void;
|
|
12
|
-
export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends Scanner.shiftResult<infer token, infer unscanned> ? token extends "keyof" ? state.addPrefix<s, "keyof", unscanned> : tryResolve<s, token, $, args> extends infer result ? result extends ErrorMessage<infer message> ? state.error<message> : result extends keyof $ ?
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? token extends "keyof" ? state.addPrefix<s, "keyof", unscanned> : tryResolve<s, token, $, args> extends infer result ? result extends ErrorMessage<infer message> ? state.error<message> : result extends keyof $ ? [
|
|
12
|
+
$[result]
|
|
13
|
+
] extends [anyOrNever] ? state.setRoot<s, result, unscanned> : $[result] extends GenericProps ? parseGenericInstantiation<token, $[result], state.scanTo<s, unscanned>, $, args> : state.setRoot<s, result, unscanned> : state.setRoot<s, result, unscanned> : never : never;
|
|
14
|
+
export declare const parseGenericInstantiation: (name: string, g: Generic, s: DynamicState) => BaseRoot;
|
|
15
|
+
export type parseGenericInstantiation<name extends string, g extends GenericProps, s extends StaticState, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ? parseGenericArgs<name, g["params"], unscanned, $, args> extends (infer result) ? result extends ParsedArgs<infer argAsts, infer nextUnscanned> ? state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : state.error<writeInvalidGenericArgsMessage<name, g["params"], []>>;
|
|
16
|
+
type tryResolve<s extends StaticState, token extends string, $, args> = token extends keyof $ ? token : `#${token}` extends keyof $ ? token : token extends keyof args ? token : token extends `${number}` ? token : token extends BigintLiteral ? token : token extends (`${infer submodule extends keyof $ & string}.${infer reference}`) ? $[submodule] extends {
|
|
17
|
+
[arkKind]: "module";
|
|
18
|
+
} ? reference extends keyof $[submodule] ? token : unresolvableError<s, reference, $[submodule], args, [submodule]> : ErrorMessage<writeNonSubmoduleDotMessage<submodule>> : unresolvableError<s, token, $, args, []>;
|
|
20
19
|
/** Provide valid completions for the current token, or fallback to an
|
|
21
20
|
* unresolvable error if there are none */
|
|
22
21
|
export type unresolvableError<s extends StaticState, token extends string, $, args, submodulePath extends string[]> = validReferenceFromToken<token, $, args, submodulePath> extends never ? ErrorMessage<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : Completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, $, args, submodulePath>, submodulePath>}`>;
|
|
23
22
|
type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
|
|
24
23
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath extends [] ? BaseCompletions<$, args> : keyof $, `${token}${string}`>;
|
|
25
|
-
export declare const
|
|
26
|
-
type writeUnresolvableMessage<token extends string> = `'${token}' is unresolvable`;
|
|
27
|
-
export declare const writeMissingOperandMessage: <s extends DynamicState>(s: s) => string;
|
|
28
|
-
export type writeMissingOperandMessage<s extends StaticState, operator extends string | undefined = state.previousOperator<s>> = operator extends string ? writeMissingRightOperandMessage<operator, s["unscanned"]> : writeExpressionExpectedMessage<s["unscanned"]>;
|
|
24
|
+
export declare const writeMissingOperandMessage: (s: DynamicState) => string;
|
|
29
25
|
export type writeMissingRightOperandMessage<token extends string, unscanned extends string = ""> = `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
30
26
|
export declare const writeMissingRightOperandMessage: <token extends string, unscanned extends string>(token: token, unscanned?: unscanned) => `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
31
|
-
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) =>
|
|
27
|
+
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
32
28
|
export type writeExpressionExpectedMessage<unscanned extends string> = `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
33
29
|
export {};
|
|
34
|
-
//# sourceMappingURL=unenclosed.d.ts.map
|
|
@@ -1,68 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRoot, hasArkKind, writeUnresolvableMessage } from "@arktype/schema";
|
|
2
2
|
import { printable, throwParseError, tryParseNumber, tryParseWellFormedBigint } from "@arktype/util";
|
|
3
|
-
import {
|
|
3
|
+
import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js";
|
|
4
4
|
import { parseGenericArgs, writeInvalidGenericArgsMessage } from "./genericArgs.js";
|
|
5
5
|
export const parseUnenclosed = (s) => {
|
|
6
6
|
const token = s.scanner.shiftUntilNextTerminator();
|
|
7
|
-
if (token === "keyof")
|
|
7
|
+
if (token === "keyof")
|
|
8
8
|
s.addPrefix("keyof");
|
|
9
|
-
|
|
10
|
-
else {
|
|
9
|
+
else
|
|
11
10
|
s.root = unenclosedToNode(s, token);
|
|
12
|
-
}
|
|
13
11
|
};
|
|
14
12
|
export const parseGenericInstantiation = (name, g, s) => {
|
|
15
13
|
s.scanner.shiftUntilNonWhitespace();
|
|
16
14
|
const lookahead = s.scanner.shift();
|
|
17
|
-
if (lookahead !== "<")
|
|
18
|
-
return s.error(writeInvalidGenericArgsMessage(name, g.
|
|
19
|
-
|
|
20
|
-
const parsedArgs = parseGenericArgs(name, g.parameters, s);
|
|
15
|
+
if (lookahead !== "<")
|
|
16
|
+
return s.error(writeInvalidGenericArgsMessage(name, g.params, []));
|
|
17
|
+
const parsedArgs = parseGenericArgs(name, g.params, s);
|
|
21
18
|
const remainingChars = parsedArgs.unscanned.length;
|
|
22
19
|
// set the scanner position to where the args scanner left off
|
|
23
20
|
s.scanner.jumpToIndex(remainingChars === 0 ? s.scanner.length : -remainingChars);
|
|
24
|
-
return g(...parsedArgs.result)
|
|
21
|
+
return g(...parsedArgs.result);
|
|
25
22
|
};
|
|
26
23
|
const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
|
|
27
24
|
maybeParseUnenclosedLiteral(s, token) ??
|
|
28
|
-
s.error(token === ""
|
|
29
|
-
?
|
|
30
|
-
|
|
25
|
+
s.error(token === "" ? writeMissingOperandMessage(s)
|
|
26
|
+
: token[0] === "#" ?
|
|
27
|
+
writePrefixedPrivateReferenceMessage(token)
|
|
28
|
+
: writeUnresolvableMessage(token));
|
|
31
29
|
const maybeParseReference = (s, token) => {
|
|
32
|
-
if (s.ctx.args?.[token])
|
|
33
|
-
return s.ctx.args[token];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (resolution instanceof BaseType) {
|
|
30
|
+
if (s.ctx.args?.[token])
|
|
31
|
+
return s.ctx.args[token].raw;
|
|
32
|
+
const resolution = s.ctx.$.maybeResolve(token);
|
|
33
|
+
if (resolution instanceof BaseRoot)
|
|
37
34
|
return resolution;
|
|
38
|
-
|
|
39
|
-
if (resolution === undefined) {
|
|
35
|
+
if (resolution === undefined)
|
|
40
36
|
return;
|
|
41
|
-
|
|
42
|
-
if (hasArkKind(resolution, "generic")) {
|
|
37
|
+
if (hasArkKind(resolution, "generic"))
|
|
43
38
|
return parseGenericInstantiation(token, resolution, s);
|
|
44
|
-
}
|
|
45
39
|
return throwParseError(`Unexpected resolution ${printable(resolution)}`);
|
|
46
40
|
};
|
|
47
41
|
const maybeParseUnenclosedLiteral = (s, token) => {
|
|
48
42
|
const maybeNumber = tryParseNumber(token, { strict: true });
|
|
49
|
-
if (maybeNumber !== undefined)
|
|
50
|
-
return
|
|
51
|
-
}
|
|
43
|
+
if (maybeNumber !== undefined)
|
|
44
|
+
return s.ctx.$.node("unit", { unit: maybeNumber });
|
|
52
45
|
const maybeBigint = tryParseWellFormedBigint(token);
|
|
53
|
-
if (maybeBigint !== undefined)
|
|
54
|
-
return
|
|
55
|
-
}
|
|
46
|
+
if (maybeBigint !== undefined)
|
|
47
|
+
return s.ctx.$.node("unit", { unit: maybeBigint });
|
|
56
48
|
};
|
|
57
|
-
export const writeNonSubmoduleDotMessage = (name) => `'${name}' must reference a module to be accessed using dot syntax`;
|
|
58
|
-
export const writeMissingSubmoduleAccessMessage = (name) => `Reference to submodule '${name}' must specify an alias`;
|
|
59
|
-
export const writeUnresolvableMessage = (token) => `'${token}' is unresolvable`;
|
|
60
49
|
export const writeMissingOperandMessage = (s) => {
|
|
61
50
|
const operator = s.previousOperator();
|
|
62
|
-
return operator
|
|
63
|
-
|
|
51
|
+
return operator ?
|
|
52
|
+
writeMissingRightOperandMessage(operator, s.scanner.unscanned)
|
|
64
53
|
: writeExpressionExpectedMessage(s.scanner.unscanned);
|
|
65
54
|
};
|
|
66
55
|
export const writeMissingRightOperandMessage = (token, unscanned = "") => `Token '${token}' requires a right operand${unscanned ? ` before '${unscanned}'` : ""}`;
|
|
67
56
|
export const writeExpressionExpectedMessage = (unscanned) => `Expected an expression${unscanned ? ` before '${unscanned}'` : ""}`;
|
|
68
|
-
//# sourceMappingURL=unenclosed.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type BaseRoot, type BoundKind, type LimitLiteral } from "@arktype/schema";
|
|
2
2
|
import { type keySet } from "@arktype/util";
|
|
3
3
|
import type { astToString } from "../../../semantic/utils.js";
|
|
4
4
|
import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.js";
|
|
5
|
-
import {
|
|
5
|
+
import { type Comparator, type InvertedComparators, type MaxComparator, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
|
|
6
6
|
import type { StaticState, state } from "../../reduce/static.js";
|
|
7
7
|
import type { parseOperand } from "../operand/operand.js";
|
|
8
8
|
import type { Scanner } from "../scanner.js";
|
|
9
|
-
export declare const parseBound: (s: DynamicStateWithRoot, start: ComparatorStartChar) =>
|
|
10
|
-
export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends Scanner.shiftResult<infer comparator extends Comparator, infer nextUnscanned> ? s["root"] extends `${infer limit extends LimitLiteral}` ? state.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<state.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
|
|
9
|
+
export declare const parseBound: (s: DynamicStateWithRoot, start: ComparatorStartChar) => void;
|
|
10
|
+
export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends (Scanner.shiftResult<infer comparator extends Comparator, infer nextUnscanned>) ? s["root"] extends `${infer limit extends LimitLiteral}` ? state.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<state.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
|
|
11
11
|
declare const oneCharComparators: {
|
|
12
12
|
readonly "<": true;
|
|
13
13
|
readonly ">": true;
|
|
@@ -17,17 +17,13 @@ export type ComparatorStartChar = Comparator extends `${infer char}${string}` ?
|
|
|
17
17
|
export declare const comparatorStartChars: keySet<ComparatorStartChar>;
|
|
18
18
|
declare const shiftComparator: (s: DynamicState, start: ComparatorStartChar) => Comparator;
|
|
19
19
|
type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : start extends OneCharComparator ? [start, unscanned] : state.error<singleEqualsMessage>;
|
|
20
|
-
export declare const writeUnboundableMessage: <root extends string>(root: root) => `Bounded expression ${root} must be a number, string, Array, or Date`;
|
|
21
|
-
export type writeUnboundableMessage<root extends string> = `Bounded expression ${root} must be a number, string, Array, or Date`;
|
|
22
20
|
export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const getBoundKinds: (comparator: Comparator, limit: LimitSchemaValue, root: TypeNode) => BoundKind[];
|
|
21
|
+
export declare const getBoundKinds: (comparator: Comparator, limit: LimitLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
|
|
25
22
|
export declare const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
|
|
26
23
|
type singleEqualsMessage = typeof singleEqualsMessage;
|
|
27
|
-
export declare const parseRightBound: (s: DynamicStateWithRoot, comparator: Comparator) =>
|
|
24
|
+
export declare const parseRightBound: (s: DynamicStateWithRoot, comparator: Comparator) => void;
|
|
28
25
|
export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends `${infer limit extends LimitLiteral}` ? s["branches"]["leftBound"] extends {} ? comparator extends MaxComparator ? state.reduceRange<s, s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], comparator, limit, nextState["unscanned"]> : state.error<writeUnpairableComparatorMessage<comparator>> : state.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : state.error<writeInvalidLimitMessage<comparator, astToString<nextState["root"]>, "right">> : never;
|
|
29
|
-
export declare const writeInvalidLimitMessage: <comparator extends "
|
|
30
|
-
export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was
|
|
26
|
+
export declare const writeInvalidLimitMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==", limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
27
|
+
export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
31
28
|
export type BoundExpressionKind = "left" | "right";
|
|
32
29
|
export {};
|
|
33
|
-
//# sourceMappingURL=bounds.d.ts.map
|