arktype 1.1.0-dev-2 → 2.0.0-dev.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/__tests__/array.test.ts +272 -0
- package/__tests__/astUtils.test.ts +17 -0
- package/__tests__/badDefinitionType.test.ts +51 -0
- package/__tests__/basis.test.ts +46 -0
- package/__tests__/bounds.test.ts +388 -0
- package/__tests__/cast.test.ts +32 -0
- package/__tests__/completions.test.ts +46 -0
- package/__tests__/config.test.ts +168 -0
- package/__tests__/cyclic.test.ts +144 -0
- package/__tests__/dateLiteral.test.ts +32 -0
- package/__tests__/declared.test.ts +123 -0
- package/__tests__/discrimination.test.ts +74 -0
- package/__tests__/divisor.test.ts +90 -0
- package/__tests__/enclosed.test.ts +93 -0
- package/__tests__/examples.test.ts +56 -0
- package/__tests__/expressions.test.ts +138 -0
- package/__tests__/generateBenchData.ts +89 -0
- package/__tests__/generated/cyclic.ts +3058 -0
- package/__tests__/generic.test.ts +294 -0
- package/__tests__/group.test.ts +72 -0
- package/__tests__/hkt.test.ts +22 -0
- package/__tests__/imports.test.ts +113 -0
- package/__tests__/instanceof.test.ts +102 -0
- package/__tests__/intersection.test.ts +104 -0
- package/__tests__/jsdoc.test.ts +64 -0
- package/__tests__/keyTraversal.test.ts +73 -0
- package/__tests__/keyof.test.ts +134 -0
- package/__tests__/keywords.test.ts +188 -0
- package/__tests__/literal.test.ts +51 -0
- package/__tests__/match.test.ts +34 -0
- package/__tests__/methods.bench.ts +22 -0
- package/__tests__/morph.test.ts +409 -0
- package/__tests__/narrow.test.ts +102 -0
- package/__tests__/nodeDefinitions.test.ts +190 -0
- package/__tests__/object.bench.ts +28 -0
- package/__tests__/objectLiteral.test.ts +300 -0
- package/__tests__/operand.bench.ts +45 -0
- package/__tests__/operator.bench.ts +130 -0
- package/__tests__/regex.test.ts +58 -0
- package/__tests__/scope.bench.ts +39 -0
- package/__tests__/scope.test.ts +140 -0
- package/__tests__/string.test.ts +48 -0
- package/__tests__/submodule.test.ts +99 -0
- package/__tests__/this.test.ts +57 -0
- package/__tests__/thunk.test.ts +80 -0
- package/__tests__/traverse.test.ts +119 -0
- package/__tests__/tsGenerics.test.ts +12 -0
- package/__tests__/typeMethods.test.ts +69 -0
- package/__tests__/typeReference.test.ts +39 -0
- package/__tests__/unenclosed.test.ts +120 -0
- package/__tests__/union.test.ts +147 -0
- package/ark.ts +91 -0
- package/main.ts +7 -9
- package/match.ts +47 -68
- package/out/ark.d.ts +52 -0
- package/out/ark.d.ts.map +1 -0
- package/out/ark.js +19 -0
- package/out/ark.js.map +1 -0
- package/out/arkConfig.d.ts +2 -0
- package/out/arkConfig.d.ts.map +1 -0
- package/out/arkConfig.js +10 -0
- package/out/arkConfig.js.map +1 -0
- package/out/main.d.ts +7 -0
- package/out/main.d.ts.map +1 -0
- package/out/main.js +4 -0
- package/out/main.js.map +1 -0
- package/out/match.d.ts +48 -0
- package/out/match.d.ts.map +1 -0
- package/{dist → out}/match.js +0 -5
- package/out/match.js.map +1 -0
- package/{dist → out}/parser/definition.d.ts +3 -3
- package/out/parser/definition.d.ts.map +1 -0
- package/{dist → out}/parser/definition.js +8 -5
- package/out/parser/definition.js.map +1 -0
- package/out/parser/generic.d.ts +18 -0
- package/out/parser/generic.d.ts.map +1 -0
- package/out/parser/generic.js +19 -0
- package/out/parser/generic.js.map +1 -0
- package/{dist → out}/parser/objectLiteral.d.ts +14 -5
- package/out/parser/objectLiteral.d.ts.map +1 -0
- package/out/parser/objectLiteral.js +66 -0
- package/out/parser/objectLiteral.js.map +1 -0
- package/out/parser/semantic/bounds.d.ts +13 -0
- package/out/parser/semantic/bounds.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/bounds.js.map +1 -1
- package/{dist → out}/parser/semantic/divisor.d.ts +2 -2
- package/{dist → out}/parser/semantic/divisor.d.ts.map +1 -1
- package/{dist → out}/parser/semantic/intersections.d.ts +1 -2
- package/out/parser/semantic/intersections.d.ts.map +1 -0
- package/out/parser/semantic/semantic.d.ts +33 -0
- package/out/parser/semantic/semantic.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/utils.d.ts +1 -1
- package/{dist → out}/parser/semantic/utils.d.ts.map +1 -1
- package/{dist → out}/parser/semantic/validate.d.ts +3 -3
- package/out/parser/semantic/validate.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/validate.js.map +1 -1
- package/{dist → out}/parser/shared.d.ts +7 -1
- package/out/parser/shared.d.ts.map +1 -0
- package/{dist → out}/parser/shared.js +7 -1
- package/out/parser/shared.js.map +1 -0
- package/{dist → out}/parser/string/reduce/dynamic.d.ts +11 -9
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -0
- package/{dist → out}/parser/string/reduce/dynamic.js +13 -2
- package/out/parser/string/reduce/dynamic.js.map +1 -0
- package/{dist → out}/parser/string/reduce/shared.d.ts +29 -2
- package/{dist → out}/parser/string/reduce/shared.d.ts.map +1 -1
- package/{dist → out}/parser/string/reduce/shared.js +20 -1
- package/out/parser/string/reduce/shared.js.map +1 -0
- package/{dist → out}/parser/string/reduce/static.d.ts +1 -2
- package/out/parser/string/reduce/static.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/date.d.ts +3 -3
- package/out/parser/string/shift/operand/date.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/date.js.map +1 -1
- package/{dist → out}/parser/string/shift/operand/enclosed.d.ts +2 -2
- package/{dist → out}/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/{dist → out}/parser/string/shift/operand/enclosed.js +4 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts +29 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.js +25 -0
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -0
- package/{dist → out}/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/{dist → out}/parser/string/shift/operand/operand.js.map +1 -1
- package/{dist → out}/parser/string/shift/operand/unenclosed.d.ts +7 -9
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/unenclosed.js +10 -10
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -0
- package/{dist → out}/parser/string/shift/operator/bounds.d.ts +11 -33
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -0
- package/out/parser/string/shift/operator/bounds.js +106 -0
- package/out/parser/string/shift/operator/bounds.js.map +1 -0
- package/{dist → out}/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operator/operator.js.map +1 -1
- package/{dist → out}/parser/string/shift/scanner.d.ts +1 -1
- package/{dist → out}/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js.map +1 -0
- package/{dist → out}/parser/string/string.d.ts +9 -11
- package/out/parser/string/string.d.ts.map +1 -0
- package/out/parser/string/string.js +23 -0
- package/out/parser/string/string.js.map +1 -0
- package/{dist → out}/parser/tuple.d.ts +9 -11
- package/out/parser/tuple.d.ts.map +1 -0
- package/{dist → out}/parser/tuple.js +17 -14
- package/out/parser/tuple.js.map +1 -0
- package/{dist → out}/scope.d.ts +16 -16
- package/out/scope.d.ts.map +1 -0
- package/{dist → out}/scope.js +27 -22
- package/out/scope.js.map +1 -0
- package/out/test.d.ts +2 -0
- package/out/test.d.ts.map +1 -0
- package/out/test.js +7 -0
- package/out/test.js.map +1 -0
- package/out/tsconfig.build.tsbuildinfo +1 -0
- package/{dist → out}/type.d.ts +23 -47
- package/out/type.d.ts.map +1 -0
- package/{dist → out}/type.js +27 -31
- package/out/type.js.map +1 -0
- package/out/util.d.ts +19 -0
- package/out/util.d.ts.map +1 -0
- package/out/util.js +7 -0
- package/out/util.js.map +1 -0
- package/package.json +13 -15
- package/parser/definition.ts +58 -55
- package/parser/generic.ts +17 -157
- package/parser/objectLiteral.ts +107 -30
- package/parser/semantic/bounds.ts +22 -24
- package/parser/semantic/divisor.ts +2 -2
- package/parser/semantic/intersections.ts +17 -18
- package/parser/semantic/semantic.ts +80 -43
- package/parser/semantic/utils.ts +7 -7
- package/parser/semantic/validate.ts +40 -36
- package/parser/shared.ts +28 -17
- package/parser/string/reduce/dynamic.ts +26 -11
- package/parser/string/reduce/shared.ts +35 -7
- package/parser/string/reduce/static.ts +20 -22
- package/parser/string/shift/operand/date.ts +1 -4
- package/parser/string/shift/operand/enclosed.ts +5 -6
- package/parser/string/shift/operand/genericArgs.ts +127 -0
- package/parser/string/shift/operand/operand.ts +21 -21
- package/parser/string/shift/operand/unenclosed.ts +54 -68
- package/parser/string/shift/operator/bounds.ts +99 -64
- package/parser/string/shift/operator/operator.ts +31 -31
- package/parser/string/shift/scanner.ts +7 -7
- package/parser/string/string.ts +29 -32
- package/parser/tuple.ts +87 -88
- package/scope.ts +81 -80
- package/type.ts +76 -132
- package/util.ts +36 -0
- package/dist/main.d.ts +0 -11
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js +0 -8
- package/dist/main.js.map +0 -1
- package/dist/match.d.ts +0 -46
- package/dist/match.d.ts.map +0 -1
- package/dist/match.js.map +0 -1
- package/dist/parser/definition.d.ts.map +0 -1
- package/dist/parser/definition.js.map +0 -1
- package/dist/parser/generic.d.ts +0 -44
- package/dist/parser/generic.d.ts.map +0 -1
- package/dist/parser/generic.js +0 -46
- package/dist/parser/generic.js.map +0 -1
- package/dist/parser/objectLiteral.d.ts.map +0 -1
- package/dist/parser/objectLiteral.js +0 -38
- package/dist/parser/objectLiteral.js.map +0 -1
- package/dist/parser/semantic/bounds.d.ts +0 -13
- package/dist/parser/semantic/bounds.d.ts.map +0 -1
- package/dist/parser/semantic/intersections.d.ts.map +0 -1
- package/dist/parser/semantic/semantic.d.ts +0 -22
- package/dist/parser/semantic/semantic.d.ts.map +0 -1
- package/dist/parser/semantic/validate.d.ts.map +0 -1
- package/dist/parser/shared.d.ts.map +0 -1
- package/dist/parser/shared.js.map +0 -1
- package/dist/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/dist/parser/string/reduce/dynamic.js.map +0 -1
- package/dist/parser/string/reduce/shared.js.map +0 -1
- package/dist/parser/string/reduce/static.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/date.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/enclosed.js.map +0 -1
- package/dist/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/dist/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/dist/parser/string/shift/operator/bounds.js +0 -95
- package/dist/parser/string/shift/operator/bounds.js.map +0 -1
- package/dist/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/dist/parser/string/shift/scanner.js.map +0 -1
- package/dist/parser/string/string.d.ts.map +0 -1
- package/dist/parser/string/string.js +0 -31
- package/dist/parser/string/string.js.map +0 -1
- package/dist/parser/tuple.d.ts.map +0 -1
- package/dist/parser/tuple.js.map +0 -1
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js.map +0 -1
- package/dist/scopes/ark.d.ts +0 -38
- package/dist/scopes/ark.d.ts.map +0 -1
- package/dist/scopes/ark.js +0 -24
- package/dist/scopes/ark.js.map +0 -1
- package/dist/scopes/jsObjects.d.ts +0 -19
- package/dist/scopes/jsObjects.d.ts.map +0 -1
- package/dist/scopes/jsObjects.js +0 -15
- package/dist/scopes/jsObjects.js.map +0 -1
- package/dist/scopes/parsing.d.ts +0 -18
- package/dist/scopes/parsing.d.ts.map +0 -1
- package/dist/scopes/parsing.js +0 -61
- package/dist/scopes/parsing.js.map +0 -1
- package/dist/scopes/tsGenerics.d.ts +0 -17
- package/dist/scopes/tsGenerics.d.ts.map +0 -1
- package/dist/scopes/tsGenerics.js +0 -13
- package/dist/scopes/tsGenerics.js.map +0 -1
- package/dist/scopes/tsKeywords.d.ts +0 -24
- package/dist/scopes/tsKeywords.d.ts.map +0 -1
- package/dist/scopes/tsKeywords.js +0 -20
- package/dist/scopes/tsKeywords.js.map +0 -1
- package/dist/scopes/utils/creditCard.d.ts +0 -3
- package/dist/scopes/utils/creditCard.d.ts.map +0 -1
- package/dist/scopes/utils/creditCard.js +0 -36
- package/dist/scopes/utils/creditCard.js.map +0 -1
- package/dist/scopes/utils/date.d.ts +0 -24
- package/dist/scopes/utils/date.d.ts.map +0 -1
- package/dist/scopes/utils/date.js +0 -53
- package/dist/scopes/utils/date.js.map +0 -1
- package/dist/scopes/validation.d.ts +0 -20
- package/dist/scopes/validation.d.ts.map +0 -1
- package/dist/scopes/validation.js +0 -57
- package/dist/scopes/validation.js.map +0 -1
- package/dist/type.d.ts.map +0 -1
- package/dist/type.js.map +0 -1
- package/scopes/ark.ts +0 -64
- package/scopes/jsObjects.ts +0 -29
- package/scopes/parsing.ts +0 -81
- package/scopes/tsGenerics.ts +0 -28
- package/scopes/tsKeywords.ts +0 -39
- package/scopes/utils/creditCard.ts +0 -37
- package/scopes/utils/date.ts +0 -108
- package/scopes/validation.ts +0 -81
- /package/{dist → out}/parser/semantic/bounds.js +0 -0
- /package/{dist → out}/parser/semantic/divisor.js +0 -0
- /package/{dist → out}/parser/semantic/divisor.js.map +0 -0
- /package/{dist → out}/parser/semantic/intersections.js +0 -0
- /package/{dist → out}/parser/semantic/intersections.js.map +0 -0
- /package/{dist → out}/parser/semantic/semantic.js +0 -0
- /package/{dist → out}/parser/semantic/semantic.js.map +0 -0
- /package/{dist → out}/parser/semantic/utils.js +0 -0
- /package/{dist → out}/parser/semantic/utils.js.map +0 -0
- /package/{dist → out}/parser/semantic/validate.js +0 -0
- /package/{dist → out}/parser/string/reduce/static.js +0 -0
- /package/{dist → out}/parser/string/reduce/static.js.map +0 -0
- /package/{dist → out}/parser/string/shift/operand/date.js +0 -0
- /package/{dist → out}/parser/string/shift/operand/operand.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operand/operand.js +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.d.ts.map +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.js +0 -0
- /package/{dist → out}/parser/string/shift/operator/operator.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operator/operator.js +0 -0
- /package/{dist → out}/parser/string/shift/scanner.js +0 -0
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { Completion, defined, ErrorMessage } from "@arktype/util"
|
|
2
|
+
import type { Scanner } from "../shift/scanner.js"
|
|
2
3
|
import type {
|
|
3
4
|
Comparator,
|
|
4
5
|
InvertedComparators,
|
|
5
6
|
LimitLiteral,
|
|
6
7
|
MaxComparator,
|
|
7
|
-
MinComparator
|
|
8
|
-
} from "../shift/operator/bounds.js"
|
|
9
|
-
import type { Scanner } from "../shift/scanner.js"
|
|
10
|
-
import type {
|
|
8
|
+
MinComparator,
|
|
11
9
|
OpenLeftBound,
|
|
12
10
|
StringifiablePrefixOperator,
|
|
13
11
|
writeMultipleLeftBoundsMessage,
|
|
@@ -230,15 +228,15 @@ export namespace state {
|
|
|
230
228
|
> = s["branches"]["leftBound"] extends {}
|
|
231
229
|
? openRangeError<s["branches"]["leftBound"]>
|
|
232
230
|
: s["groups"] extends popGroup<infer stack, infer top>
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
231
|
+
? from<{
|
|
232
|
+
groups: stack
|
|
233
|
+
branches: top
|
|
234
|
+
root: mergeToUnion<s>
|
|
235
|
+
finalizer: s["finalizer"]
|
|
236
|
+
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
|
|
237
|
+
unscanned: unscanned
|
|
238
|
+
}>
|
|
239
|
+
: state.error<writeUnmatchedGroupCloseMessage<unscanned>>
|
|
242
240
|
|
|
243
241
|
export type reduceGroupOpen<
|
|
244
242
|
s extends StaticState,
|
|
@@ -275,15 +273,15 @@ export namespace state {
|
|
|
275
273
|
s["branches"]["leftBound"] extends {}
|
|
276
274
|
? s["branches"]["leftBound"]["comparator"]
|
|
277
275
|
: s["branches"]["prefixes"] extends [
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
276
|
+
...unknown[],
|
|
277
|
+
infer tail extends string
|
|
278
|
+
]
|
|
279
|
+
? tail
|
|
280
|
+
: s["branches"]["&"] extends {}
|
|
281
|
+
? "&"
|
|
282
|
+
: s["branches"]["|"] extends {}
|
|
283
|
+
? "|"
|
|
284
|
+
: undefined
|
|
287
285
|
|
|
288
286
|
export type scanTo<s extends StaticState, unscanned extends string> = from<{
|
|
289
287
|
root: s["root"]
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import type { DateLiteral } from "@arktype/schema"
|
|
1
2
|
import { throwParseError, tryParseNumber } from "@arktype/util"
|
|
2
3
|
|
|
3
|
-
export type DateLiteral<source extends string = string> =
|
|
4
|
-
| `d"${source}"`
|
|
5
|
-
| `d'${source}'`
|
|
6
|
-
|
|
7
4
|
export const isDateLiteral = (value: unknown): value is DateLiteral =>
|
|
8
5
|
typeof value === "string" &&
|
|
9
6
|
value[0] === "d" &&
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { schema, type RegexLiteral } from "@arktype/schema"
|
|
2
2
|
import { isKeyOf } from "@arktype/util"
|
|
3
|
-
import type { RegexLiteral } from "../../../semantic/semantic.js"
|
|
4
3
|
import type { DynamicState } from "../../reduce/dynamic.js"
|
|
5
|
-
import type {
|
|
4
|
+
import type { StaticState, state } from "../../reduce/static.js"
|
|
6
5
|
import type { Scanner } from "../scanner.js"
|
|
7
6
|
import { tryParseDate, writeInvalidDateMessage } from "./date.js"
|
|
8
7
|
|
|
@@ -31,12 +30,12 @@ export const parseEnclosed = (
|
|
|
31
30
|
if (enclosing === "/") {
|
|
32
31
|
// fail parsing if the regex is invalid
|
|
33
32
|
new RegExp(enclosed)
|
|
34
|
-
s.root =
|
|
33
|
+
s.root = schema({ basis: "string", pattern: token as RegexLiteral })
|
|
35
34
|
} else if (isKeyOf(enclosing, enclosingQuote)) {
|
|
36
|
-
s.root =
|
|
35
|
+
s.root = schema({ unit: enclosed })
|
|
37
36
|
} else {
|
|
38
37
|
const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed))
|
|
39
|
-
s.root =
|
|
38
|
+
s.root = schema({ unit: date, description: token })
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { TypeNode } from "@arktype/schema"
|
|
2
|
+
import type { ErrorMessage, join } from "@arktype/util"
|
|
3
|
+
import type { DynamicState } from "../../reduce/dynamic.js"
|
|
4
|
+
import { writeUnclosedGroupMessage } from "../../reduce/shared.js"
|
|
5
|
+
import type { StaticState, state } from "../../reduce/static.js"
|
|
6
|
+
import type { parseUntilFinalizer } from "../../string.js"
|
|
7
|
+
|
|
8
|
+
export type ParsedArgs<
|
|
9
|
+
result extends unknown[] = unknown[],
|
|
10
|
+
unscanned extends string = string
|
|
11
|
+
> = {
|
|
12
|
+
result: result
|
|
13
|
+
unscanned: unscanned
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const parseGenericArgs = (
|
|
17
|
+
name: string,
|
|
18
|
+
params: string[],
|
|
19
|
+
s: DynamicState
|
|
20
|
+
) => parseGenericArgsRecurse(name, params, s, [], [])
|
|
21
|
+
|
|
22
|
+
export type parseGenericArgs<
|
|
23
|
+
name extends string,
|
|
24
|
+
params extends string[],
|
|
25
|
+
unscanned extends string,
|
|
26
|
+
$,
|
|
27
|
+
args
|
|
28
|
+
> = parseGenericArgsRecurse<name, params, unscanned, $, args, [], []>
|
|
29
|
+
|
|
30
|
+
const parseGenericArgsRecurse = (
|
|
31
|
+
name: string,
|
|
32
|
+
params: string[],
|
|
33
|
+
s: DynamicState,
|
|
34
|
+
argDefs: string[],
|
|
35
|
+
argNodes: TypeNode[]
|
|
36
|
+
): ParsedArgs<TypeNode[]> => {
|
|
37
|
+
const argState = s.parseUntilFinalizer()
|
|
38
|
+
// remove the finalizing token from the argDef
|
|
39
|
+
argDefs.push(argState.scanner.scanned.slice(0, -1))
|
|
40
|
+
argNodes.push(argState.root)
|
|
41
|
+
if (argState.finalizer === ">") {
|
|
42
|
+
if (argNodes.length === params.length) {
|
|
43
|
+
return {
|
|
44
|
+
result: argNodes,
|
|
45
|
+
unscanned: argState.scanner.unscanned
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
return argState.error(
|
|
49
|
+
writeInvalidGenericArgsMessage(name, params, argDefs)
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
} else if (argState.finalizer === ",") {
|
|
53
|
+
return parseGenericArgsRecurse(name, params, s, argDefs, argNodes)
|
|
54
|
+
}
|
|
55
|
+
return argState.error(writeUnclosedGroupMessage(">"))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type parseGenericArgsRecurse<
|
|
59
|
+
name extends string,
|
|
60
|
+
params extends string[],
|
|
61
|
+
unscanned extends string,
|
|
62
|
+
$,
|
|
63
|
+
args,
|
|
64
|
+
argDefs extends string[],
|
|
65
|
+
argAsts extends unknown[]
|
|
66
|
+
> = parseUntilFinalizer<
|
|
67
|
+
state.initialize<unscanned>,
|
|
68
|
+
$,
|
|
69
|
+
args
|
|
70
|
+
> extends infer finalArgState extends StaticState
|
|
71
|
+
? {
|
|
72
|
+
defs: [
|
|
73
|
+
...argDefs,
|
|
74
|
+
finalArgState["scanned"] extends `${infer def}${"," | ">"}`
|
|
75
|
+
? def
|
|
76
|
+
: finalArgState["scanned"]
|
|
77
|
+
]
|
|
78
|
+
asts: [...argAsts, finalArgState["root"]]
|
|
79
|
+
unscanned: finalArgState["unscanned"]
|
|
80
|
+
} extends {
|
|
81
|
+
defs: infer nextDefs extends string[]
|
|
82
|
+
asts: infer nextAsts extends unknown[]
|
|
83
|
+
unscanned: infer nextUnscanned extends string
|
|
84
|
+
}
|
|
85
|
+
? finalArgState["finalizer"] extends ">"
|
|
86
|
+
? nextAsts["length"] extends params["length"]
|
|
87
|
+
? ParsedArgs<nextAsts, nextUnscanned>
|
|
88
|
+
: state.error<writeInvalidGenericArgsMessage<name, params, nextDefs>>
|
|
89
|
+
: finalArgState["finalizer"] extends ","
|
|
90
|
+
? parseGenericArgsRecurse<
|
|
91
|
+
name,
|
|
92
|
+
params,
|
|
93
|
+
nextUnscanned,
|
|
94
|
+
$,
|
|
95
|
+
args,
|
|
96
|
+
nextDefs,
|
|
97
|
+
nextAsts
|
|
98
|
+
>
|
|
99
|
+
: finalArgState["finalizer"] extends ErrorMessage
|
|
100
|
+
? finalArgState
|
|
101
|
+
: state.error<writeUnclosedGroupMessage<">">>
|
|
102
|
+
: never
|
|
103
|
+
: never
|
|
104
|
+
|
|
105
|
+
export const writeInvalidGenericArgsMessage = <
|
|
106
|
+
name extends string,
|
|
107
|
+
params extends string[],
|
|
108
|
+
argDefs extends string[]
|
|
109
|
+
>(
|
|
110
|
+
name: name,
|
|
111
|
+
params: params,
|
|
112
|
+
argDefs: argDefs
|
|
113
|
+
) =>
|
|
114
|
+
`${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${
|
|
115
|
+
argDefs.length
|
|
116
|
+
}${argDefs.length === 0 ? "" : ": " + argDefs.join(", ")})`
|
|
117
|
+
|
|
118
|
+
export type writeInvalidGenericArgsMessage<
|
|
119
|
+
name extends string,
|
|
120
|
+
params extends string[],
|
|
121
|
+
argDefs extends string[]
|
|
122
|
+
> = `${name}<${join<
|
|
123
|
+
params,
|
|
124
|
+
", "
|
|
125
|
+
>}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends 0
|
|
126
|
+
? ""
|
|
127
|
+
: `: ${join<argDefs, ",">}`})`
|
|
@@ -15,16 +15,16 @@ export const parseOperand = (s: DynamicState): void =>
|
|
|
15
15
|
s.scanner.lookahead === ""
|
|
16
16
|
? s.error(writeMissingOperandMessage(s))
|
|
17
17
|
: s.scanner.lookahead === "("
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
? s.shiftedByOne().reduceGroupOpen()
|
|
19
|
+
: s.scanner.lookaheadIsIn(enclosingChar)
|
|
20
|
+
? parseEnclosed(s, s.scanner.shift())
|
|
21
|
+
: s.scanner.lookaheadIsIn(Scanner.whiteSpaceTokens)
|
|
22
|
+
? parseOperand(s.shiftedByOne())
|
|
23
|
+
: s.scanner.lookahead === "d"
|
|
24
|
+
? s.shiftedByOne().scanner.lookaheadIsIn(enclosingChar)
|
|
25
|
+
? parseEnclosed(s, `d${s.scanner.shift()}` as EnclosingStartToken)
|
|
26
|
+
: parseUnenclosed(s)
|
|
27
|
+
: parseUnenclosed(s)
|
|
28
28
|
|
|
29
29
|
export type parseOperand<
|
|
30
30
|
s extends StaticState,
|
|
@@ -34,15 +34,15 @@ export type parseOperand<
|
|
|
34
34
|
? lookahead extends "("
|
|
35
35
|
? state.reduceGroupOpen<s, unscanned>
|
|
36
36
|
: lookahead extends EnclosingEndToken
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
? parseEnclosed<s, lookahead, unscanned>
|
|
38
|
+
: lookahead extends Scanner.WhiteSpaceToken
|
|
39
|
+
? parseOperand<state.scanTo<s, unscanned>, $, args>
|
|
40
|
+
: lookahead extends "d"
|
|
41
|
+
? unscanned extends Scanner.shift<
|
|
42
|
+
infer enclosing extends EnclosingQuote,
|
|
43
|
+
infer nextUnscanned
|
|
44
|
+
>
|
|
45
|
+
? parseEnclosed<s, `d${enclosing}`, nextUnscanned>
|
|
46
|
+
: parseUnenclosed<s, $, args>
|
|
47
|
+
: parseUnenclosed<s, $, args>
|
|
48
48
|
: state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseType, schema, type TypeNode } from "@arktype/schema"
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
printable,
|
|
4
4
|
throwParseError,
|
|
5
5
|
tryParseNumber,
|
|
6
6
|
tryParseWellFormedBigint,
|
|
@@ -11,21 +11,18 @@ import {
|
|
|
11
11
|
type NumberLiteral
|
|
12
12
|
} from "@arktype/util"
|
|
13
13
|
import type { Module } from "../../../../scope.js"
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
type Generic,
|
|
17
|
-
type GenericProps
|
|
18
|
-
} from "../../../../type.js"
|
|
19
|
-
import {
|
|
20
|
-
parseGenericArgs,
|
|
21
|
-
writeInvalidGenericArgsMessage,
|
|
22
|
-
type ParsedArgs
|
|
23
|
-
} from "../../../generic.js"
|
|
14
|
+
import type { Generic, GenericProps } from "../../../../type.js"
|
|
15
|
+
import { hasArkKind } from "../../../../util.js"
|
|
24
16
|
import type { GenericInstantiationAst } from "../../../semantic/semantic.js"
|
|
25
17
|
import type { DynamicState } from "../../reduce/dynamic.js"
|
|
26
18
|
import type { state, StaticState } from "../../reduce/static.js"
|
|
27
19
|
import type { BaseCompletions } from "../../string.js"
|
|
28
20
|
import type { Scanner } from "../scanner.js"
|
|
21
|
+
import {
|
|
22
|
+
parseGenericArgs,
|
|
23
|
+
writeInvalidGenericArgsMessage,
|
|
24
|
+
type ParsedArgs
|
|
25
|
+
} from "./genericArgs.js"
|
|
29
26
|
|
|
30
27
|
export const parseUnenclosed = (s: DynamicState) => {
|
|
31
28
|
const token = s.scanner.shiftUntilNextTerminator()
|
|
@@ -46,44 +43,39 @@ export type parseUnenclosed<
|
|
|
46
43
|
? token extends "keyof"
|
|
47
44
|
? state.addPrefix<s, "keyof", unscanned>
|
|
48
45
|
: tryResolve<s, token, $, args> extends infer result
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
? result extends ErrorMessage<infer message>
|
|
47
|
+
? state.error<message>
|
|
48
|
+
: result extends keyof $
|
|
49
|
+
? $[result] extends GenericProps
|
|
50
|
+
? parseGenericInstantiation<
|
|
51
|
+
token,
|
|
52
|
+
$[result],
|
|
53
|
+
state.scanTo<s, unscanned>,
|
|
54
|
+
$,
|
|
55
|
+
args
|
|
56
|
+
>
|
|
57
|
+
: state.setRoot<s, result, unscanned>
|
|
58
|
+
: state.setRoot<s, result, unscanned>
|
|
59
|
+
: never
|
|
63
60
|
: never
|
|
64
61
|
|
|
65
62
|
export const parseGenericInstantiation = (
|
|
66
63
|
name: string,
|
|
67
64
|
g: Generic,
|
|
68
65
|
s: DynamicState
|
|
69
|
-
) => {
|
|
66
|
+
): TypeNode => {
|
|
70
67
|
s.scanner.shiftUntilNonWhitespace()
|
|
71
68
|
const lookahead = s.scanner.shift()
|
|
72
69
|
if (lookahead !== "<") {
|
|
73
70
|
return s.error(writeInvalidGenericArgsMessage(name, g.parameters, []))
|
|
74
71
|
}
|
|
75
|
-
const parsedArgs = parseGenericArgs(
|
|
76
|
-
name,
|
|
77
|
-
g.parameters,
|
|
78
|
-
s.scanner.unscanned,
|
|
79
|
-
s.ctx
|
|
80
|
-
)
|
|
72
|
+
const parsedArgs = parseGenericArgs(name, g.parameters, s)
|
|
81
73
|
const remainingChars = parsedArgs.unscanned.length
|
|
82
74
|
// set the scanner position to where the args scanner left off
|
|
83
75
|
s.scanner.jumpToIndex(
|
|
84
76
|
remainingChars === 0 ? s.scanner.length : -remainingChars
|
|
85
77
|
)
|
|
86
|
-
return g(...parsedArgs.result).root
|
|
78
|
+
return g(...parsedArgs.result).root as never
|
|
87
79
|
}
|
|
88
80
|
|
|
89
81
|
export type parseGenericInstantiation<
|
|
@@ -108,7 +100,7 @@ export type parseGenericInstantiation<
|
|
|
108
100
|
: never
|
|
109
101
|
: state.error<writeInvalidGenericArgsMessage<name, g["parameters"], []>>
|
|
110
102
|
|
|
111
|
-
const unenclosedToNode = (s: DynamicState, token: string):
|
|
103
|
+
const unenclosedToNode = (s: DynamicState, token: string): TypeNode =>
|
|
112
104
|
maybeParseReference(s, token) ??
|
|
113
105
|
maybeParseUnenclosedLiteral(s, token) ??
|
|
114
106
|
s.error(
|
|
@@ -120,12 +112,12 @@ const unenclosedToNode = (s: DynamicState, token: string): Root =>
|
|
|
120
112
|
const maybeParseReference = (
|
|
121
113
|
s: DynamicState,
|
|
122
114
|
token: string
|
|
123
|
-
):
|
|
115
|
+
): TypeNode | undefined => {
|
|
124
116
|
if (s.ctx.args?.[token]) {
|
|
125
117
|
return s.ctx.args[token]
|
|
126
118
|
}
|
|
127
119
|
const resolution = s.ctx.scope.maybeResolve(token)
|
|
128
|
-
if (
|
|
120
|
+
if (resolution instanceof BaseType) {
|
|
129
121
|
return resolution
|
|
130
122
|
}
|
|
131
123
|
if (resolution === undefined) {
|
|
@@ -134,20 +126,20 @@ const maybeParseReference = (
|
|
|
134
126
|
if (hasArkKind(resolution, "generic")) {
|
|
135
127
|
return parseGenericInstantiation(token, resolution, s)
|
|
136
128
|
}
|
|
137
|
-
return throwParseError(`Unexpected resolution ${
|
|
129
|
+
return throwParseError(`Unexpected resolution ${printable(resolution)}`)
|
|
138
130
|
}
|
|
139
131
|
|
|
140
132
|
const maybeParseUnenclosedLiteral = (
|
|
141
133
|
s: DynamicState,
|
|
142
134
|
token: string
|
|
143
|
-
):
|
|
135
|
+
): TypeNode | undefined => {
|
|
144
136
|
const maybeNumber = tryParseNumber(token, { strict: true })
|
|
145
137
|
if (maybeNumber !== undefined) {
|
|
146
|
-
return
|
|
138
|
+
return schema({ unit: maybeNumber })
|
|
147
139
|
}
|
|
148
140
|
const maybeBigint = tryParseWellFormedBigint(token)
|
|
149
141
|
if (maybeBigint !== undefined) {
|
|
150
|
-
return
|
|
142
|
+
return schema({ unit: maybeBigint })
|
|
151
143
|
}
|
|
152
144
|
}
|
|
153
145
|
|
|
@@ -159,39 +151,33 @@ type tryResolve<
|
|
|
159
151
|
> = token extends keyof $
|
|
160
152
|
? token
|
|
161
153
|
: token extends keyof args
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
$[submodule],
|
|
182
|
-
args,
|
|
183
|
-
[submodule]
|
|
184
|
-
>
|
|
185
|
-
: ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
186
|
-
: unresolvableError<s, token, $, args, []>
|
|
154
|
+
? token
|
|
155
|
+
: token extends NumberLiteral
|
|
156
|
+
? token
|
|
157
|
+
: token extends BigintLiteral
|
|
158
|
+
? token
|
|
159
|
+
: token extends `${infer submodule extends keyof $ &
|
|
160
|
+
string}.${infer reference}`
|
|
161
|
+
? $[submodule] extends Module<infer r>
|
|
162
|
+
? reference extends keyof r["exports"]
|
|
163
|
+
? token
|
|
164
|
+
: unknown extends r["exports"]
|
|
165
|
+
? // not sure why I need the additional check here, but for now TS seems to
|
|
166
|
+
// hit this branch for a non-scope dot access rather than failing
|
|
167
|
+
// initially when we try to infer r. if this can be removed without breaking
|
|
168
|
+
// any submodule test cases, do it!
|
|
169
|
+
ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
170
|
+
: unresolvableError<s, reference, $[submodule], args, [submodule]>
|
|
171
|
+
: ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
172
|
+
: unresolvableError<s, token, $, args, []>
|
|
187
173
|
|
|
188
174
|
export const writeNonSubmoduleDotMessage = <name extends string>(
|
|
189
175
|
name: name
|
|
190
176
|
): writeNonSubmoduleDotMessage<name> =>
|
|
191
|
-
`'${name}' must reference a
|
|
177
|
+
`'${name}' must reference a module to be accessed using dot syntax`
|
|
192
178
|
|
|
193
179
|
type writeNonSubmoduleDotMessage<name extends string> =
|
|
194
|
-
`'${name}' must reference a
|
|
180
|
+
`'${name}' must reference a module to be accessed using dot syntax`
|
|
195
181
|
|
|
196
182
|
export const writeMissingSubmoduleAccessMessage = <name extends string>(
|
|
197
183
|
name: name
|