arktype 2.0.0-rc.21 → 2.0.0-rc.22
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/generic.d.ts +10 -10
- package/out/parser/ast/infer.d.ts +3 -3
- package/out/parser/objectLiteral.d.ts +4 -4
- package/out/parser/objectLiteral.js +3 -3
- package/out/parser/reduce/dynamic.d.ts +6 -6
- package/out/parser/reduce/static.d.ts +3 -3
- package/out/parser/shift/operand/enclosed.d.ts +3 -2
- package/out/parser/shift/operand/operand.d.ts +3 -3
- package/out/parser/shift/operand/operand.js +2 -2
- package/out/parser/shift/operand/unenclosed.d.ts +7 -4
- package/out/parser/shift/operator/bounds.d.ts +4 -4
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +3 -3
- package/out/parser/shift/operator/operator.js +4 -4
- package/out/parser/shift/scanner.d.ts +28 -53
- package/out/parser/shift/scanner.js +22 -83
- package/out/parser/tuple.d.ts +6 -2
- package/out/scope.js +3 -3
- package/package.json +3 -3
package/out/generic.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { GenericRoot, type arkKind, type BaseParseContext, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
2
|
-
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type
|
|
2
|
+
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type WhitespaceChar } from "@ark/util";
|
|
3
3
|
import type { type } from "./keywords/keywords.ts";
|
|
4
4
|
import type { inferAstRoot } from "./parser/ast/infer.ts";
|
|
5
5
|
import type { validateAst } from "./parser/ast/validate.ts";
|
|
6
6
|
import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
|
|
7
7
|
import type { state, StaticState } from "./parser/reduce/static.ts";
|
|
8
|
-
import type {
|
|
8
|
+
import type { ArkTypeScanner } from "./parser/shift/scanner.ts";
|
|
9
9
|
import { parseUntilFinalizer } from "./parser/string.ts";
|
|
10
10
|
import type { Scope } from "./scope.ts";
|
|
11
11
|
import type { Type } from "./type.ts";
|
|
@@ -127,19 +127,19 @@ export type GenericDeclaration<name extends string = string, params extends Para
|
|
|
127
127
|
export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
|
|
128
128
|
export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
129
129
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
130
|
-
export type parseGenericParams<def extends string, $> = parseNextNameChar<
|
|
130
|
+
export type parseGenericParams<def extends string, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<def>, "", [
|
|
131
131
|
], $>;
|
|
132
|
-
type ParamsTerminator =
|
|
133
|
-
export declare const parseGenericParamName: (scanner:
|
|
134
|
-
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<
|
|
135
|
-
type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends
|
|
132
|
+
type ParamsTerminator = WhitespaceChar | ",";
|
|
133
|
+
export declare const parseGenericParamName: (scanner: ArkTypeScanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
134
|
+
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<unscanned>, "", result, $>;
|
|
135
|
+
type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends WhitespaceChar ? _parseOptionalConstraint<nextUnscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
|
|
136
136
|
declare const extendsToken = "extends ";
|
|
137
137
|
type extendsToken = typeof extendsToken;
|
|
138
|
-
declare const _parseOptionalConstraint: (scanner:
|
|
139
|
-
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> =
|
|
138
|
+
declare const _parseOptionalConstraint: (scanner: ArkTypeScanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
139
|
+
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = ArkTypeScanner.skipWhitespace<unscanned> extends (`${extendsToken}${infer nextUnscanned}`) ? parseUntilFinalizer<state.initialize<nextUnscanned>, $, {}> extends (infer finalArgState extends StaticState) ? validateAst<finalArgState["root"], $, {}> extends (infer e extends ErrorMessage) ? e : parseName<finalArgState["unscanned"], [
|
|
140
140
|
...result,
|
|
141
141
|
[name, inferAstRoot<finalArgState["root"], $, {}>]
|
|
142
|
-
], $> : never : parseName<
|
|
142
|
+
], $> : never : parseName<ArkTypeScanner.skipWhitespace<unscanned> extends (`,${infer nextUnscanned}`) ? nextUnscanned : unscanned, [
|
|
143
143
|
...result,
|
|
144
144
|
[name, unknown]
|
|
145
145
|
], $>;
|
|
@@ -6,7 +6,7 @@ import type { type } from "../../keywords/keywords.ts";
|
|
|
6
6
|
import type { UnparsedScope } from "../../scope.ts";
|
|
7
7
|
import type { inferDefinition } from "../definition.ts";
|
|
8
8
|
import type { Comparator } from "../reduce/shared.ts";
|
|
9
|
-
import type {
|
|
9
|
+
import type { ArkTypeScanner } from "../shift/scanner.ts";
|
|
10
10
|
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
|
|
11
11
|
export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
|
|
12
12
|
export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
|
|
@@ -34,6 +34,6 @@ type dateBoundToAttributes<comparator extends Comparator, limit extends string |
|
|
|
34
34
|
type numericBoundToAttributes<comparator extends Comparator, limit extends number> = comparator extends "<" ? LessThan<limit> : comparator extends "<=" ? AtMost<limit> : comparator extends ">" ? MoreThan<limit> : AtLeast<limit>;
|
|
35
35
|
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
36
36
|
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
37
|
-
export type PostfixExpression<operator extends
|
|
38
|
-
export type InfixExpression<operator extends
|
|
37
|
+
export type PostfixExpression<operator extends ArkTypeScanner.PostfixToken = ArkTypeScanner.PostfixToken, operand = unknown> = readonly [operand, operator];
|
|
38
|
+
export type InfixExpression<operator extends ArkTypeScanner.InfixToken = ArkTypeScanner.InfixToken, l = unknown, r = unknown> = [l, operator, r];
|
|
39
39
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type
|
|
2
|
+
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeChar, type Key, type listable, type merge, type show } from "@ark/util";
|
|
3
3
|
import type { of } from "../attributes.ts";
|
|
4
4
|
import type { astToString } from "./ast/utils.ts";
|
|
5
5
|
import type { validateString } from "./ast/validate.ts";
|
|
@@ -44,7 +44,7 @@ export type ParsedSpreadEntry = {
|
|
|
44
44
|
};
|
|
45
45
|
export declare const parseEntry: (key: Key, value: unknown, ctx: BaseParseContext) => listable<ParsedEntry>;
|
|
46
46
|
declare const parseKey: (key: Key) => PreparsedKey;
|
|
47
|
-
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${
|
|
47
|
+
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeChar}` ? PreparsedKey.from<{
|
|
48
48
|
kind: "required";
|
|
49
49
|
key: `${baseName}?`;
|
|
50
50
|
}> : PreparsedKey.from<{
|
|
@@ -53,7 +53,7 @@ type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName
|
|
|
53
53
|
}> : k extends MetaKey ? PreparsedKey.from<{
|
|
54
54
|
kind: k;
|
|
55
55
|
key: k;
|
|
56
|
-
}> : k extends `${
|
|
56
|
+
}> : k extends `${EscapeChar}${infer escapedMeta extends MetaKey}` ? PreparsedKey.from<{
|
|
57
57
|
kind: "required";
|
|
58
58
|
key: escapedMeta;
|
|
59
59
|
}> : k extends IndexKey<infer def> ? PreparsedKey.from<{
|
|
@@ -61,7 +61,7 @@ type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName
|
|
|
61
61
|
key: def;
|
|
62
62
|
}> : PreparsedKey.from<{
|
|
63
63
|
kind: "required";
|
|
64
|
-
key: k extends `${
|
|
64
|
+
key: k extends `${EscapeChar}${infer escapedIndexKey extends IndexKey}` ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
65
65
|
}>;
|
|
66
66
|
export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => writeInvalidSpreadTypeMessage<def>;
|
|
67
67
|
type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeIndex } from "@ark/schema";
|
|
2
|
-
import { append,
|
|
2
|
+
import { append, escapeChar, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
|
|
3
3
|
export const parseObjectLiteral = (def, ctx) => {
|
|
4
4
|
let spread;
|
|
5
5
|
const structure = {};
|
|
@@ -61,7 +61,7 @@ export const parseEntry = (key, value, ctx) => {
|
|
|
61
61
|
};
|
|
62
62
|
const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
|
|
63
63
|
: key.at(-1) === "?" ?
|
|
64
|
-
key.at(-2) ===
|
|
64
|
+
key.at(-2) === escapeChar ?
|
|
65
65
|
{ kind: "required", key: `${key.slice(0, -2)}?` }
|
|
66
66
|
: {
|
|
67
67
|
kind: "optional",
|
|
@@ -69,7 +69,7 @@ const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
|
|
|
69
69
|
}
|
|
70
70
|
: key[0] === "[" && key.at(-1) === "]" ?
|
|
71
71
|
{ kind: "index", key: key.slice(1, -1) }
|
|
72
|
-
: key[0] ===
|
|
72
|
+
: key[0] === escapeChar && key[1] === "[" && key.at(-1) === "]" ?
|
|
73
73
|
{ kind: "required", key: key.slice(1) }
|
|
74
74
|
: key === "..." ? { kind: key, key }
|
|
75
75
|
: key === "+" ? { kind: key, key }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BaseParseContext, BaseRoot } from "@ark/schema";
|
|
2
2
|
import { type requireKeys } from "@ark/util";
|
|
3
3
|
import type { LimitLiteral } from "../../attributes.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { ArkTypeScanner } from "../shift/scanner.ts";
|
|
5
5
|
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
|
|
6
6
|
type BranchState = {
|
|
7
7
|
prefixes: StringifiablePrefixOperator[];
|
|
@@ -13,17 +13,17 @@ export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
|
|
|
13
13
|
export declare class DynamicState {
|
|
14
14
|
root: BaseRoot<any> | undefined;
|
|
15
15
|
branches: BranchState;
|
|
16
|
-
finalizer:
|
|
16
|
+
finalizer: ArkTypeScanner.FinalizingLookahead | undefined;
|
|
17
17
|
groups: BranchState[];
|
|
18
|
-
scanner:
|
|
18
|
+
scanner: ArkTypeScanner;
|
|
19
19
|
ctx: BaseParseContext;
|
|
20
|
-
constructor(scanner:
|
|
20
|
+
constructor(scanner: ArkTypeScanner, ctx: BaseParseContext);
|
|
21
21
|
error(message: string): never;
|
|
22
22
|
hasRoot(): this is DynamicStateWithRoot;
|
|
23
23
|
setRoot(root: BaseRoot): void;
|
|
24
24
|
unsetRoot(): this["root"];
|
|
25
25
|
constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
|
|
26
|
-
finalize(finalizer:
|
|
26
|
+
finalize(finalizer: ArkTypeScanner.FinalizingLookahead): void;
|
|
27
27
|
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
|
|
28
28
|
finalizeBranches(): void;
|
|
29
29
|
finalizeGroup(): void;
|
|
@@ -35,7 +35,7 @@ export declare class DynamicState {
|
|
|
35
35
|
parseOperand(): void;
|
|
36
36
|
private assertRangeUnset;
|
|
37
37
|
reduceGroupOpen(): void;
|
|
38
|
-
previousOperator(): MinComparator | StringifiablePrefixOperator |
|
|
38
|
+
previousOperator(): MinComparator | StringifiablePrefixOperator | ArkTypeScanner.InfixToken | undefined;
|
|
39
39
|
shiftedByOne(): this;
|
|
40
40
|
}
|
|
41
41
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Completion, ErrorMessage, defined } from "@ark/util";
|
|
2
2
|
import type { LimitLiteral } from "../../attributes.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ArkTypeScanner } from "../shift/scanner.ts";
|
|
4
4
|
import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
|
|
5
5
|
export type StaticState = {
|
|
6
6
|
root: unknown;
|
|
7
7
|
branches: BranchState;
|
|
8
8
|
groups: BranchState[];
|
|
9
|
-
finalizer:
|
|
9
|
+
finalizer: ArkTypeScanner.FinalizingLookahead | ErrorMessage | undefined;
|
|
10
10
|
scanned: string;
|
|
11
11
|
unscanned: string;
|
|
12
12
|
};
|
|
@@ -151,7 +151,7 @@ export declare namespace state {
|
|
|
151
151
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
152
152
|
unscanned: unscanned;
|
|
153
153
|
}>;
|
|
154
|
-
type finalize<s extends StaticState, finalizer extends
|
|
154
|
+
type finalize<s extends StaticState, finalizer extends ArkTypeScanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
|
|
155
155
|
root: mergeToUnion<s>;
|
|
156
156
|
groups: s["groups"];
|
|
157
157
|
branches: initialBranches;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { type Scanner } from "@ark/util";
|
|
1
2
|
import type { string } from "../../../attributes.ts";
|
|
2
3
|
import type { Date } from "../../../keywords/constructors/Date.ts";
|
|
3
4
|
import type { InferredAst } from "../../ast/infer.ts";
|
|
4
5
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
5
6
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
6
|
-
import type {
|
|
7
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
7
8
|
export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
|
|
8
9
|
export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
|
|
9
10
|
export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
|
|
10
11
|
export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
|
|
11
|
-
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> =
|
|
12
|
+
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = ArkTypeScanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends ArkTypeScanner.shiftResult<infer scanned, infer nextUnscanned> ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? string.matching<scanned> : Date.nominal<scanned>, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends ArkTypeScanner.shift<string, infer unscanned> ? unscanned : ""> : never;
|
|
12
13
|
export declare const enclosingQuote: {
|
|
13
14
|
readonly "'": 1;
|
|
14
15
|
readonly '"': 1;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type WhitespaceChar } from "@ark/util";
|
|
2
2
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
3
3
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
4
|
import type { BaseCompletions } from "../../string.ts";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
6
6
|
import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
|
|
7
7
|
import { parseUnenclosed } from "./unenclosed.ts";
|
|
8
8
|
export declare const parseOperand: (s: DynamicState) => void;
|
|
9
|
-
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends
|
|
9
|
+
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhitespaceChar ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (ArkTypeScanner.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,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { whitespaceChars } from "@ark/util";
|
|
2
2
|
import { enclosingChar, enclosingQuote, parseEnclosed } from "./enclosed.js";
|
|
3
3
|
import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
|
|
4
4
|
export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
|
|
5
5
|
: s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen()
|
|
6
6
|
: s.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s, s.scanner.shift())
|
|
7
|
-
: s.scanner.lookaheadIsIn(
|
|
7
|
+
: s.scanner.lookaheadIsIn(whitespaceChars) ? parseOperand(s.shiftedByOne())
|
|
8
8
|
: s.scanner.lookahead === "d" ?
|
|
9
9
|
s.scanner.nextLookahead in enclosingQuote ?
|
|
10
10
|
parseEnclosed(s, `${s.scanner.shift()}${s.scanner.shift()}`)
|
|
@@ -7,13 +7,13 @@ import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
|
|
|
7
7
|
import type { DynamicState } from "../../reduce/dynamic.ts";
|
|
8
8
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
9
9
|
import type { BaseCompletions } from "../../string.ts";
|
|
10
|
-
import type {
|
|
10
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
11
11
|
import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.ts";
|
|
12
12
|
export declare const parseUnenclosed: (s: DynamicState) => void;
|
|
13
|
-
export type parseUnenclosed<s extends StaticState, $, args> =
|
|
13
|
+
export type parseUnenclosed<s extends StaticState, $, args> = ArkTypeScanner.shiftUntilNextTerminator<s["unscanned"]> extends (ArkTypeScanner.shiftResult<infer token, infer unscanned>) ? tryResolve<s, unscanned, token, $, args> extends state.from<infer s> ? s : never : never;
|
|
14
14
|
type parseResolution<s extends StaticState, unscanned extends string, alias extends string, resolution, $, args> = resolutionToAst<alias, resolution> extends infer ast ? ast extends GenericAst ? parseGenericInstantiation<alias, ast, state.scanTo<s, unscanned>, $, args> : state.setRoot<s, ast, unscanned> : never;
|
|
15
15
|
export declare const parseGenericInstantiation: (name: string, g: GenericRoot, s: DynamicState) => BaseRoot;
|
|
16
|
-
export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> =
|
|
16
|
+
export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> = ArkTypeScanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ? parseGenericArgs<name, g, unscanned, $, args> extends infer result ? result extends ParsedArgs<infer argAsts, infer nextUnscanned> ? state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : state.error<writeInvalidGenericArgCountMessage<name, genericParamNames<g["paramsAst"]>, [
|
|
17
17
|
]>>;
|
|
18
18
|
type tryResolve<s extends StaticState, unscanned extends string, token extends string, $, args> = token extends keyof args ? parseResolution<s, unscanned, token, args[token], $, args> : token extends keyof $ ? parseResolution<s, unscanned, token, $[token], $, args> : `#${token}` extends keyof $ ? parseResolution<s, unscanned, token, $[`#${token}`], $, args> : token extends keyof ArkAmbient.$ ? parseResolution<s, unscanned, token, ArkAmbient.$[token], $, args> : token extends NumberLiteral<infer n> ? state.setRoot<s, InferredAst<n, token>, unscanned> : token extends (`${infer submodule extends keyof $ & string}.${infer reference}`) ? tryResolveSubmodule<token, $[submodule], reference, s, unscanned, $, args, [
|
|
19
19
|
submodule
|
|
@@ -31,7 +31,10 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
|
|
|
31
31
|
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
|
|
32
32
|
token,
|
|
33
33
|
s["unscanned"]
|
|
34
|
-
] extends
|
|
34
|
+
] extends ([
|
|
35
|
+
"",
|
|
36
|
+
ArkTypeScanner.shift<"#", infer unscanned>
|
|
37
|
+
]) ? ArkTypeScanner.shiftUntilNextTerminator<unscanned> extends (ArkTypeScanner.shiftResult<infer name, string>) ? state.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
|
|
35
38
|
type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
|
|
36
39
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
|
|
37
40
|
export declare const writeMissingOperandMessage: (s: DynamicState) => string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BaseRoot, type BoundKind } from "@ark/schema";
|
|
2
|
-
import { type
|
|
2
|
+
import { type KeySet } from "@ark/util";
|
|
3
3
|
import type { DateLiteral } from "../../../attributes.ts";
|
|
4
4
|
import type { InferredAst } from "../../ast/infer.ts";
|
|
5
5
|
import type { astToString } from "../../ast/utils.ts";
|
|
@@ -7,12 +7,12 @@ import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.ts
|
|
|
7
7
|
import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.ts";
|
|
8
8
|
import type { state, StaticState } from "../../reduce/static.ts";
|
|
9
9
|
import type { parseOperand } from "../operand/operand.ts";
|
|
10
|
-
import type {
|
|
10
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
11
11
|
export declare const parseBound: (s: DynamicStateWithRoot, start: ComparatorStartChar) => void;
|
|
12
|
-
export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends (
|
|
12
|
+
export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends (ArkTypeScanner.shiftResult<infer comparator extends Comparator, infer nextUnscanned>) ? s["root"] extends (InferredAst<Date | number, `${infer limit extends number | DateLiteral}`>) ? state.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<state.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
|
|
13
13
|
type OneCharComparator = ">" | "<";
|
|
14
14
|
export type ComparatorStartChar = Comparator extends `${infer char}${string}` ? char : never;
|
|
15
|
-
export declare const comparatorStartChars:
|
|
15
|
+
export declare const comparatorStartChars: KeySet<ComparatorStartChar>;
|
|
16
16
|
declare const shiftComparator: (s: DynamicState, start: ComparatorStartChar) => Comparator;
|
|
17
17
|
type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : [start & OneCharComparator, unscanned];
|
|
18
18
|
export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { emptyBrandNameMessage } from "@ark/schema";
|
|
2
2
|
import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
3
3
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
5
5
|
export declare const parseBrand: (s: DynamicStateWithRoot) => void;
|
|
6
|
-
export type parseBrand<s extends StaticState, unscanned extends string> =
|
|
6
|
+
export type parseBrand<s extends StaticState, unscanned extends string> = ArkTypeScanner.shiftUntilNextTerminator<ArkTypeScanner.skipWhitespace<unscanned>> extends (ArkTypeScanner.shiftResult<`${infer brandName}`, infer nextUnscanned>) ? brandName extends "" ? state.error<emptyBrandNameMessage> : state.setRoot<s, [s["root"], "#", brandName], nextUnscanned> : never;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
2
2
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ArkTypeScanner } from "../scanner.ts";
|
|
4
4
|
export declare const parseDivisor: (s: DynamicStateWithRoot) => void;
|
|
5
|
-
export type parseDivisor<s extends StaticState, unscanned extends string> =
|
|
5
|
+
export type parseDivisor<s extends StaticState, unscanned extends string> = ArkTypeScanner.shiftUntilNextTerminator<ArkTypeScanner.skipWhitespace<unscanned>> extends ArkTypeScanner.shiftResult<infer scanned, infer nextUnscanned> ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? state.error<writeInvalidDivisorMessage<0>> : state.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : state.error<writeInvalidDivisorMessage<scanned>> : never;
|
|
6
6
|
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => writeInvalidDivisorMessage<divisor>;
|
|
7
7
|
export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type WhitespaceChar } from "@ark/util";
|
|
2
2
|
import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
|
|
3
3
|
import type { StaticState, state } from "../../reduce/static.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { ArkTypeScanner } from "../scanner.ts";
|
|
5
5
|
import { parseBound, type ComparatorStartChar } from "./bounds.ts";
|
|
6
6
|
import { parseBrand } from "./brand.ts";
|
|
7
7
|
import { parseDivisor } from "./divisor.ts";
|
|
8
8
|
export declare const parseOperator: (s: DynamicStateWithRoot) => void;
|
|
9
|
-
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends
|
|
9
|
+
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "[" ? unscanned extends ArkTypeScanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : ArkTypeScanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & ArkTypeScanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhitespaceChar ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
|
|
10
10
|
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
|
|
11
11
|
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
12
12
|
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isKeyOf,
|
|
2
|
-
import {
|
|
1
|
+
import { isKeyOf, whitespaceChars } from "@ark/util";
|
|
2
|
+
import { ArkTypeScanner } from "../scanner.js";
|
|
3
3
|
import { comparatorStartChars, parseBound } from "./bounds.js";
|
|
4
4
|
import { parseBrand } from "./brand.js";
|
|
5
5
|
import { parseDivisor } from "./divisor.js";
|
|
@@ -12,12 +12,12 @@ export const parseOperator = (s) => {
|
|
|
12
12
|
: s.error(incompleteArrayTokenMessage)
|
|
13
13
|
: lookahead === "|" || lookahead === "&" ? s.pushRootToBranch(lookahead)
|
|
14
14
|
: lookahead === ")" ? s.finalizeGroup()
|
|
15
|
-
:
|
|
15
|
+
: ArkTypeScanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
|
|
16
16
|
s.finalize(lookahead)
|
|
17
17
|
: isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
|
|
18
18
|
: lookahead === "%" ? parseDivisor(s)
|
|
19
19
|
: lookahead === "#" ? parseBrand(s)
|
|
20
|
-
: lookahead in
|
|
20
|
+
: lookahead in whitespaceChars ? parseOperator(s)
|
|
21
21
|
: s.error(writeUnexpectedCharacterMessage(lookahead)));
|
|
22
22
|
};
|
|
23
23
|
export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
|
|
@@ -1,70 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Scanner, type EscapeChar, type WhitespaceChar } from "@ark/util";
|
|
2
2
|
import type { Comparator } from "../reduce/shared.ts";
|
|
3
|
-
export declare class
|
|
4
|
-
private chars;
|
|
5
|
-
private i;
|
|
6
|
-
constructor(def: string);
|
|
7
|
-
/** Get lookahead and advance scanner by one */
|
|
8
|
-
shift(): lookahead;
|
|
9
|
-
get lookahead(): lookahead;
|
|
10
|
-
get nextLookahead(): string;
|
|
11
|
-
get length(): number;
|
|
12
|
-
shiftUntil(condition: Scanner.UntilCondition): string;
|
|
3
|
+
export declare class ArkTypeScanner<lookahead extends string = string> extends Scanner<lookahead> {
|
|
13
4
|
shiftUntilNextTerminator(): string;
|
|
14
|
-
shiftUntilNonWhitespace(): string;
|
|
15
|
-
jumpToIndex(i: number): void;
|
|
16
|
-
jumpForward(count: number): void;
|
|
17
|
-
get location(): number;
|
|
18
|
-
get unscanned(): string;
|
|
19
|
-
get scanned(): string;
|
|
20
|
-
sliceChars(start: number, end?: number): string;
|
|
21
|
-
lookaheadIs<char extends lookahead>(char: char): this is Scanner<char>;
|
|
22
|
-
lookaheadIsIn<tokens extends Dict>(tokens: tokens): this is Scanner<Extract<keyof tokens, string>>;
|
|
23
5
|
static terminatingChars: {
|
|
24
|
-
readonly " ":
|
|
25
|
-
readonly "\n":
|
|
26
|
-
readonly "\t":
|
|
27
|
-
readonly "<":
|
|
28
|
-
readonly ">":
|
|
29
|
-
readonly "=":
|
|
30
|
-
readonly "|":
|
|
31
|
-
readonly "&":
|
|
32
|
-
readonly ")":
|
|
33
|
-
readonly "[":
|
|
34
|
-
readonly "%":
|
|
35
|
-
readonly ",":
|
|
36
|
-
readonly ":":
|
|
37
|
-
readonly "?":
|
|
38
|
-
readonly "#":
|
|
6
|
+
readonly " ": 1;
|
|
7
|
+
readonly "\n": 1;
|
|
8
|
+
readonly "\t": 1;
|
|
9
|
+
readonly "<": 1;
|
|
10
|
+
readonly ">": 1;
|
|
11
|
+
readonly "=": 1;
|
|
12
|
+
readonly "|": 1;
|
|
13
|
+
readonly "&": 1;
|
|
14
|
+
readonly ")": 1;
|
|
15
|
+
readonly "[": 1;
|
|
16
|
+
readonly "%": 1;
|
|
17
|
+
readonly ",": 1;
|
|
18
|
+
readonly ":": 1;
|
|
19
|
+
readonly "?": 1;
|
|
20
|
+
readonly "#": 1;
|
|
39
21
|
};
|
|
40
22
|
static finalizingLookaheads: {
|
|
41
|
-
readonly ">":
|
|
42
|
-
readonly ",":
|
|
43
|
-
readonly "":
|
|
44
|
-
readonly "=":
|
|
45
|
-
readonly "?":
|
|
23
|
+
readonly ">": 1;
|
|
24
|
+
readonly ",": 1;
|
|
25
|
+
readonly "": 1;
|
|
26
|
+
readonly "=": 1;
|
|
27
|
+
readonly "?": 1;
|
|
46
28
|
};
|
|
47
|
-
static lookaheadIsTerminator: Scanner.UntilCondition;
|
|
48
|
-
static lookaheadIsNotWhitespace: Scanner.UntilCondition;
|
|
49
29
|
static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
|
|
50
30
|
}
|
|
51
|
-
export declare namespace
|
|
52
|
-
type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false :
|
|
53
|
-
type
|
|
54
|
-
type
|
|
55
|
-
type ShiftUntilOptions = {
|
|
56
|
-
onInputEnd?: OnInputEndFn;
|
|
57
|
-
};
|
|
58
|
-
type TerminatingChar = keyof typeof Scanner.terminatingChars;
|
|
59
|
-
type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads;
|
|
31
|
+
export declare namespace ArkTypeScanner {
|
|
32
|
+
type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : ArkTypeScanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," | "?" ? true : false;
|
|
33
|
+
type TerminatingChar = keyof typeof ArkTypeScanner.terminatingChars;
|
|
34
|
+
type FinalizingLookahead = keyof typeof ArkTypeScanner.finalizingLookaheads;
|
|
60
35
|
type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "#" | "@" | "=";
|
|
61
36
|
type PostfixToken = "[]" | "?";
|
|
62
37
|
type OperatorToken = InfixToken | PostfixToken;
|
|
63
38
|
type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
|
|
64
|
-
type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${
|
|
39
|
+
type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeChar}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
|
|
65
40
|
type shiftUntilNot<unscanned extends string, nonTerminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends nonTerminator ? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`> : [scanned, unscanned] : [scanned, ""];
|
|
66
41
|
type shiftUntilNextTerminator<unscanned extends string> = shiftUntil<unscanned, TerminatingChar>;
|
|
67
|
-
type skipWhitespace<unscanned extends string> = shiftUntilNot<unscanned,
|
|
42
|
+
type skipWhitespace<unscanned extends string> = shiftUntilNot<unscanned, WhitespaceChar>[1];
|
|
68
43
|
type shiftResult<scanned extends string, unscanned extends string> = [
|
|
69
44
|
scanned,
|
|
70
45
|
unscanned
|
|
@@ -1,92 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class Scanner {
|
|
3
|
-
chars;
|
|
4
|
-
i;
|
|
5
|
-
constructor(def) {
|
|
6
|
-
this.chars = [...def];
|
|
7
|
-
this.i = 0;
|
|
8
|
-
}
|
|
9
|
-
/** Get lookahead and advance scanner by one */
|
|
10
|
-
shift() {
|
|
11
|
-
return (this.chars[this.i++] ?? "");
|
|
12
|
-
}
|
|
13
|
-
get lookahead() {
|
|
14
|
-
return (this.chars[this.i] ?? "");
|
|
15
|
-
}
|
|
16
|
-
get nextLookahead() {
|
|
17
|
-
return this.chars[this.i + 1] ?? "";
|
|
18
|
-
}
|
|
19
|
-
get length() {
|
|
20
|
-
return this.chars.length;
|
|
21
|
-
}
|
|
22
|
-
shiftUntil(condition) {
|
|
23
|
-
let shifted = "";
|
|
24
|
-
while (this.lookahead) {
|
|
25
|
-
if (condition(this, shifted)) {
|
|
26
|
-
if (shifted[shifted.length - 1] === escapeToken)
|
|
27
|
-
shifted = shifted.slice(0, -1);
|
|
28
|
-
else
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
shifted += this.shift();
|
|
32
|
-
}
|
|
33
|
-
return shifted;
|
|
34
|
-
}
|
|
1
|
+
import { isKeyOf, Scanner, whitespaceChars } from "@ark/util";
|
|
2
|
+
export class ArkTypeScanner extends Scanner {
|
|
35
3
|
shiftUntilNextTerminator() {
|
|
36
4
|
this.shiftUntilNonWhitespace();
|
|
37
|
-
return this.shiftUntil(
|
|
38
|
-
}
|
|
39
|
-
shiftUntilNonWhitespace() {
|
|
40
|
-
return this.shiftUntil(Scanner.lookaheadIsNotWhitespace);
|
|
41
|
-
}
|
|
42
|
-
jumpToIndex(i) {
|
|
43
|
-
this.i = i < 0 ? this.length + i : i;
|
|
44
|
-
}
|
|
45
|
-
jumpForward(count) {
|
|
46
|
-
this.i += count;
|
|
47
|
-
}
|
|
48
|
-
get location() {
|
|
49
|
-
return this.i;
|
|
50
|
-
}
|
|
51
|
-
get unscanned() {
|
|
52
|
-
return this.chars.slice(this.i, this.length).join("");
|
|
53
|
-
}
|
|
54
|
-
get scanned() {
|
|
55
|
-
return this.chars.slice(0, this.i).join("");
|
|
56
|
-
}
|
|
57
|
-
sliceChars(start, end) {
|
|
58
|
-
return this.chars.slice(start, end).join("");
|
|
59
|
-
}
|
|
60
|
-
lookaheadIs(char) {
|
|
61
|
-
return this.lookahead === char;
|
|
62
|
-
}
|
|
63
|
-
lookaheadIsIn(tokens) {
|
|
64
|
-
return this.lookahead in tokens;
|
|
5
|
+
return this.shiftUntil(() => this.lookahead in ArkTypeScanner.terminatingChars);
|
|
65
6
|
}
|
|
66
7
|
static terminatingChars = {
|
|
67
|
-
"<":
|
|
68
|
-
">":
|
|
69
|
-
"=":
|
|
70
|
-
"|":
|
|
71
|
-
"&":
|
|
72
|
-
")":
|
|
73
|
-
"[":
|
|
74
|
-
"%":
|
|
75
|
-
",":
|
|
76
|
-
":":
|
|
77
|
-
"?":
|
|
78
|
-
"#":
|
|
79
|
-
...
|
|
8
|
+
"<": 1,
|
|
9
|
+
">": 1,
|
|
10
|
+
"=": 1,
|
|
11
|
+
"|": 1,
|
|
12
|
+
"&": 1,
|
|
13
|
+
")": 1,
|
|
14
|
+
"[": 1,
|
|
15
|
+
"%": 1,
|
|
16
|
+
",": 1,
|
|
17
|
+
":": 1,
|
|
18
|
+
"?": 1,
|
|
19
|
+
"#": 1,
|
|
20
|
+
...whitespaceChars
|
|
80
21
|
};
|
|
81
22
|
static finalizingLookaheads = {
|
|
82
|
-
">":
|
|
83
|
-
",":
|
|
84
|
-
"":
|
|
85
|
-
"=":
|
|
86
|
-
"?":
|
|
23
|
+
">": 1,
|
|
24
|
+
",": 1,
|
|
25
|
+
"": 1,
|
|
26
|
+
"=": 1,
|
|
27
|
+
"?": 1
|
|
87
28
|
};
|
|
88
|
-
static lookaheadIsTerminator = (scanner) => scanner.lookahead in this.terminatingChars;
|
|
89
|
-
static lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in whiteSpaceTokens);
|
|
90
29
|
static lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
|
|
91
30
|
unscanned[0] === "=" ?
|
|
92
31
|
// >== would only occur in an expression like Array<number>==5
|
|
@@ -94,7 +33,7 @@ export class Scanner {
|
|
|
94
33
|
unscanned[1] === "="
|
|
95
34
|
// if > is the end of a generic instantiation, the next token will be an operator or the end of the string
|
|
96
35
|
: unscanned.trimStart() === "" ||
|
|
97
|
-
isKeyOf(unscanned.trimStart()[0],
|
|
36
|
+
isKeyOf(unscanned.trimStart()[0], ArkTypeScanner.terminatingChars)
|
|
98
37
|
// "=" is a finalizer on its own (representing a default value),
|
|
99
38
|
// but not with a second "=" (an equality comparator)
|
|
100
39
|
: lookahead === "=" ? unscanned[0] !== "="
|
package/out/parser/tuple.d.ts
CHANGED
|
@@ -5,11 +5,15 @@ import type { type } from "../keywords/keywords.ts";
|
|
|
5
5
|
import type { PostfixExpression } from "./ast/infer.ts";
|
|
6
6
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
7
7
|
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
|
|
8
|
-
import type {
|
|
8
|
+
import type { ArkTypeScanner } from "./shift/scanner.ts";
|
|
9
9
|
import type { BaseCompletions } from "./string.ts";
|
|
10
10
|
export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
|
|
11
11
|
export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
|
|
12
|
-
type InfixExpression = readonly [
|
|
12
|
+
type InfixExpression = readonly [
|
|
13
|
+
unknown,
|
|
14
|
+
ArkTypeScanner.InfixToken,
|
|
15
|
+
...unknown[]
|
|
16
|
+
];
|
|
13
17
|
export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
|
|
14
18
|
def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
|
|
15
19
|
def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
|
package/out/scope.js
CHANGED
|
@@ -4,7 +4,7 @@ import { parseGenericParamName } from "./generic.js";
|
|
|
4
4
|
import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
|
|
5
5
|
import { DynamicState } from "./parser/reduce/dynamic.js";
|
|
6
6
|
import { writeUnexpectedCharacterMessage } from "./parser/shift/operator/operator.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ArkTypeScanner } from "./parser/shift/scanner.js";
|
|
8
8
|
import { fullStringParse } from "./parser/string.js";
|
|
9
9
|
import { InternalTypeParser } from "./type.js";
|
|
10
10
|
export const $arkTypeRegistry = $ark;
|
|
@@ -43,7 +43,7 @@ export class InternalScope extends BaseScope {
|
|
|
43
43
|
];
|
|
44
44
|
}
|
|
45
45
|
parseGenericParams(def, opts) {
|
|
46
|
-
return parseGenericParamName(new
|
|
46
|
+
return parseGenericParamName(new ArkTypeScanner(def), [], this.createParseContext({ ...opts, def, prefix: "generic" }));
|
|
47
47
|
}
|
|
48
48
|
normalizeRootScopeValue(resolution) {
|
|
49
49
|
if (isThunk(resolution) && !hasArkKind(resolution, "generic"))
|
|
@@ -84,7 +84,7 @@ export class InternalScope extends BaseScope {
|
|
|
84
84
|
: undefined;
|
|
85
85
|
if (aliasArrayResolution)
|
|
86
86
|
return aliasArrayResolution;
|
|
87
|
-
const s = new DynamicState(new
|
|
87
|
+
const s = new DynamicState(new ArkTypeScanner(def), ctx);
|
|
88
88
|
const node = fullStringParse(s);
|
|
89
89
|
if (s.finalizer === ">")
|
|
90
90
|
throwParseError(writeUnexpectedCharacterMessage(">"));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
3
|
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
4
|
+
"version": "2.0.0-rc.22",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"out"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@ark/
|
|
38
|
-
"@ark/
|
|
37
|
+
"@ark/util": "0.22.0",
|
|
38
|
+
"@ark/schema": "0.22.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|