arktype 2.1.21 → 2.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -29
- package/out/attributes.d.ts +22 -25
- package/out/declare.d.ts +30 -0
- package/out/fn.d.ts +61 -0
- package/out/fn.js +53 -0
- package/out/generic.d.ts +9 -10
- package/out/generic.js +4 -3
- package/out/index.d.ts +2 -1
- package/out/index.js +1 -0
- package/out/keywords/keywords.d.ts +6 -3
- package/out/keywords/keywords.js +1 -0
- package/out/keywords/string.js +1 -12
- package/out/match.d.ts +3 -8
- package/out/nary.d.ts +21 -20
- package/out/parser/ast/infer.d.ts +3 -3
- package/out/parser/ast/utils.d.ts +2 -2
- package/out/parser/definition.d.ts +2 -15
- package/out/parser/objectLiteral.d.ts +4 -4
- package/out/parser/objectLiteral.js +3 -3
- package/out/parser/reduce/dynamic.d.ts +12 -12
- package/out/parser/reduce/dynamic.js +7 -7
- package/out/parser/reduce/shared.d.ts +0 -4
- package/out/parser/reduce/shared.js +0 -2
- package/out/parser/reduce/static.d.ts +13 -13
- package/out/parser/shift/operand/enclosed.d.ts +17 -9
- package/out/parser/shift/operand/enclosed.js +6 -3
- package/out/parser/shift/operand/genericArgs.d.ts +7 -8
- package/out/parser/shift/operand/genericArgs.js +1 -1
- package/out/parser/shift/operand/operand.d.ts +5 -6
- package/out/parser/shift/operand/unenclosed.d.ts +14 -17
- package/out/parser/shift/operand/unenclosed.js +3 -2
- package/out/parser/shift/operator/bounds.d.ts +8 -9
- package/out/parser/shift/operator/brand.d.ts +6 -5
- package/out/parser/shift/operator/brand.js +2 -1
- package/out/parser/shift/operator/default.d.ts +16 -9
- package/out/parser/shift/operator/default.js +1 -1
- package/out/parser/shift/operator/divisor.d.ts +6 -5
- package/out/parser/shift/operator/divisor.js +3 -1
- package/out/parser/shift/operator/operator.d.ts +6 -6
- package/out/parser/shift/operator/operator.js +2 -2
- package/out/parser/shift/tokens.d.ts +33 -0
- package/out/parser/shift/tokens.js +37 -0
- package/out/parser/string.d.ts +6 -6
- package/out/parser/string.js +3 -4
- package/out/parser/tupleExpressions.d.ts +5 -8
- package/out/parser/tupleExpressions.js +2 -2
- package/out/scope.d.ts +5 -1
- package/out/scope.js +4 -3
- package/out/type.d.ts +18 -10
- package/out/type.js +3 -2
- package/out/{methods → variants}/base.d.ts +1 -1
- package/out/{methods → variants}/object.d.ts +1 -1
- package/out/{methods → variants}/string.d.ts +4 -1
- package/out/variants/string.js +1 -0
- package/package.json +4 -3
- package/out/parser/shift/scanner.d.ts +0 -47
- package/out/parser/shift/scanner.js +0 -43
- /package/out/{methods/array.js → declare.js} +0 -0
- /package/out/{methods → variants}/array.d.ts +0 -0
- /package/out/{methods/base.js → variants/array.js} +0 -0
- /package/out/{methods/date.js → variants/base.js} +0 -0
- /package/out/{methods → variants}/date.d.ts +0 -0
- /package/out/{methods/instantiate.js → variants/date.js} +0 -0
- /package/out/{methods → variants}/instantiate.d.ts +0 -0
- /package/out/{methods/number.js → variants/instantiate.js} +0 -0
- /package/out/{methods → variants}/number.d.ts +0 -0
- /package/out/{methods/object.js → variants/number.js} +0 -0
- /package/out/{methods/string.js → variants/object.js} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import type { regex } from "@ark/regex";
|
|
1
2
|
import { type Scanner } from "@ark/util";
|
|
2
3
|
import type { InferredAst } from "../../ast/infer.ts";
|
|
3
|
-
import type {
|
|
4
|
-
import type { StaticState,
|
|
5
|
-
|
|
6
|
-
export type
|
|
7
|
-
export type
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
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 : Date, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends ArkTypeScanner.shift<string, infer unscanned> ? unscanned : ""> : never;
|
|
4
|
+
import type { RuntimeState } from "../../reduce/dynamic.ts";
|
|
5
|
+
import type { StaticState, s } from "../../reduce/static.ts";
|
|
6
|
+
export type StringLiteral<contents extends string = string> = DoubleQuotedStringLiteral<contents> | SingleQuotedStringLiteral<contents>;
|
|
7
|
+
export type DoubleQuotedStringLiteral<contents extends string = string> = `"${contents}"`;
|
|
8
|
+
export type SingleQuotedStringLiteral<contents extends string = string> = `'${contents}'`;
|
|
9
|
+
export declare const parseEnclosed: (s: RuntimeState, enclosing: EnclosingStartToken) => void;
|
|
10
|
+
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntilEscapable<unscanned, EnclosingTokens[enclosingStart], ""> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? nextUnscanned extends "" ? s.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : s.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? regex.infer<scanned> : Date, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
|
|
11
11
|
export declare const enclosingQuote: {
|
|
12
12
|
readonly "'": 1;
|
|
13
13
|
readonly '"': 1;
|
|
@@ -18,12 +18,20 @@ export declare const enclosingChar: {
|
|
|
18
18
|
readonly "'": 1;
|
|
19
19
|
readonly '"': 1;
|
|
20
20
|
};
|
|
21
|
-
export declare const
|
|
21
|
+
export declare const enclosingLiteralTokens: {
|
|
22
22
|
readonly "d'": "'";
|
|
23
23
|
readonly 'd"': "\"";
|
|
24
24
|
readonly "'": "'";
|
|
25
25
|
readonly '"': "\"";
|
|
26
|
+
};
|
|
27
|
+
export type EnclosingLiteralTokens = typeof enclosingLiteralTokens;
|
|
28
|
+
export type EnclosingLiteralStartToken = keyof EnclosingLiteralTokens;
|
|
29
|
+
export declare const enclosingTokens: {
|
|
26
30
|
readonly "/": "/";
|
|
31
|
+
readonly "d'": "'";
|
|
32
|
+
readonly 'd"': "\"";
|
|
33
|
+
readonly "'": "'";
|
|
34
|
+
readonly '"': "\"";
|
|
27
35
|
};
|
|
28
36
|
export type EnclosingTokens = typeof enclosingTokens;
|
|
29
37
|
export type EnclosingStartToken = keyof EnclosingTokens;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isKeyOf, throwParseError } from "@ark/util";
|
|
2
2
|
import { tryParseDate, writeInvalidDateMessage } from "./date.js";
|
|
3
3
|
export const parseEnclosed = (s, enclosing) => {
|
|
4
|
-
const enclosed = s.scanner.
|
|
4
|
+
const enclosed = s.scanner.shiftUntilEscapable(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
|
|
5
5
|
if (s.scanner.lookahead === "")
|
|
6
6
|
return s.error(writeUnterminatedEnclosedMessage(enclosed, enclosing));
|
|
7
7
|
// Shift the scanner one additional time for the second enclosing token
|
|
@@ -34,11 +34,14 @@ export const enclosingChar = {
|
|
|
34
34
|
"'": 1,
|
|
35
35
|
'"': 1
|
|
36
36
|
};
|
|
37
|
-
export const
|
|
37
|
+
export const enclosingLiteralTokens = {
|
|
38
38
|
"d'": "'",
|
|
39
39
|
'd"': '"',
|
|
40
40
|
"'": "'",
|
|
41
|
-
'"': '"'
|
|
41
|
+
'"': '"'
|
|
42
|
+
};
|
|
43
|
+
export const enclosingTokens = {
|
|
44
|
+
...enclosingLiteralTokens,
|
|
42
45
|
"/": "/"
|
|
43
46
|
};
|
|
44
47
|
export const untilLookaheadIsClosing = {
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { BaseRoot, GenericAst, genericParamNames, GenericRoot } from "@ark/schema";
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import type { state, StaticState } from "../../reduce/static.ts";
|
|
2
|
+
import { writeUnclosedGroupMessage, type array, type ErrorMessage, type join } from "@ark/util";
|
|
3
|
+
import type { RuntimeState } from "../../reduce/dynamic.ts";
|
|
4
|
+
import type { s, StaticState } from "../../reduce/static.ts";
|
|
6
5
|
import type { parseUntilFinalizer } from "../../string.ts";
|
|
7
|
-
export declare const parseGenericArgs: (name: string, g: GenericRoot, s:
|
|
6
|
+
export declare const parseGenericArgs: (name: string, g: GenericRoot, s: RuntimeState) => BaseRoot[];
|
|
8
7
|
export type parseGenericArgs<name extends string, g extends GenericAst, unscanned extends string, $, args> = _parseGenericArgs<name, g, unscanned, $, args, [], []>;
|
|
9
|
-
declare const _parseGenericArgs: (name: string, g: GenericRoot, s:
|
|
8
|
+
declare const _parseGenericArgs: (name: string, g: GenericRoot, s: RuntimeState, argNodes: BaseRoot[]) => BaseRoot[];
|
|
10
9
|
export type ParsedArgs<result extends unknown[] = unknown[], unscanned extends string = string> = {
|
|
11
10
|
result: result;
|
|
12
11
|
unscanned: unscanned;
|
|
13
12
|
};
|
|
14
|
-
type _parseGenericArgs<name extends string, g extends GenericAst, unscanned extends string, $, args, argDefs extends string[], argAsts extends unknown[]> = parseUntilFinalizer<
|
|
13
|
+
type _parseGenericArgs<name extends string, g extends GenericAst, unscanned extends string, $, args, argDefs extends string[], argAsts extends unknown[]> = parseUntilFinalizer<s.initialize<unscanned>, $, args> extends (infer finalArgState extends StaticState) ? {
|
|
15
14
|
defs: [
|
|
16
15
|
...argDefs,
|
|
17
16
|
finalArgState["scanned"] extends `${infer def}${"," | ">"}` ? def : finalArgState["scanned"]
|
|
@@ -22,7 +21,7 @@ type _parseGenericArgs<name extends string, g extends GenericAst, unscanned exte
|
|
|
22
21
|
defs: infer nextDefs extends string[];
|
|
23
22
|
asts: infer nextAsts extends unknown[];
|
|
24
23
|
unscanned: infer nextUnscanned extends string;
|
|
25
|
-
}) ? finalArgState["finalizer"] extends ">" ? nextAsts["length"] extends g["paramsAst"]["length"] ? ParsedArgs<nextAsts, nextUnscanned> :
|
|
24
|
+
}) ? finalArgState["finalizer"] extends ">" ? nextAsts["length"] extends g["paramsAst"]["length"] ? ParsedArgs<nextAsts, nextUnscanned> : s.error<writeInvalidGenericArgCountMessage<name, genericParamNames<g["paramsAst"]>, nextDefs>> : finalArgState["finalizer"] extends "," ? _parseGenericArgs<name, g, nextUnscanned, $, args, nextDefs, nextAsts> : finalArgState["finalizer"] extends ErrorMessage ? finalArgState : s.error<writeUnclosedGroupMessage<">">> : never : never;
|
|
26
25
|
export declare const writeInvalidGenericArgCountMessage: <name extends string, params extends array<string>, argDefs extends array<string>>(name: name, params: params, argDefs: argDefs) => writeInvalidGenericArgCountMessage<name, params, argDefs>;
|
|
27
26
|
export type writeInvalidGenericArgCountMessage<name extends string, params extends array<string>, argDefs extends array<string>> = `${name}<${join<params, ", ">}> requires exactly ${params["length"]} args (got ${argDefs["length"]}${argDefs["length"] extends (0) ? "" : `: ${join<argDefs, ",">}`})`;
|
|
28
27
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeUnclosedGroupMessage } from "
|
|
1
|
+
import { writeUnclosedGroupMessage } from "@ark/util";
|
|
2
2
|
export const parseGenericArgs = (name, g, s) => _parseGenericArgs(name, g, s, []);
|
|
3
3
|
const _parseGenericArgs = (name, g, s, argNodes) => {
|
|
4
4
|
const argState = s.parseUntilFinalizer();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { type WhitespaceChar } from "@ark/util";
|
|
2
|
-
import type {
|
|
3
|
-
import type { StaticState,
|
|
1
|
+
import { type Scanner, type WhitespaceChar } from "@ark/util";
|
|
2
|
+
import type { RuntimeState } from "../../reduce/dynamic.ts";
|
|
3
|
+
import type { StaticState, s } from "../../reduce/static.ts";
|
|
4
4
|
import type { BaseCompletions } from "../../string.ts";
|
|
5
|
-
import type { ArkTypeScanner } from "../scanner.ts";
|
|
6
5
|
import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
|
|
7
6
|
import { parseUnenclosed } from "./unenclosed.ts";
|
|
8
|
-
export declare const parseOperand: (s:
|
|
9
|
-
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends
|
|
7
|
+
export declare const parseOperand: (s: RuntimeState) => void;
|
|
8
|
+
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? s.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhitespaceChar ? parseOperand<s.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> : s.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
|
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type writeNonSubmoduleDotMessage } from "@ark/schema";
|
|
2
|
-
import { type BigintLiteral, type NumberLiteral, type join, type lastOf } from "@ark/util";
|
|
2
|
+
import { type BigintLiteral, type NumberLiteral, type Scanner, type join, type lastOf } from "@ark/util";
|
|
3
3
|
import type { ArkAmbient } from "../../../config.ts";
|
|
4
4
|
import type { resolutionToAst } from "../../../scope.ts";
|
|
5
5
|
import type { GenericInstantiationAst } from "../../ast/generic.ts";
|
|
6
6
|
import type { InferredAst } from "../../ast/infer.ts";
|
|
7
7
|
import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
|
|
8
|
-
import type {
|
|
9
|
-
import type { StaticState,
|
|
8
|
+
import type { RuntimeState } from "../../reduce/dynamic.ts";
|
|
9
|
+
import type { StaticState, s } from "../../reduce/static.ts";
|
|
10
10
|
import type { BaseCompletions } from "../../string.ts";
|
|
11
|
-
import type
|
|
11
|
+
import { type TerminatingChar } from "../tokens.ts";
|
|
12
12
|
import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.ts";
|
|
13
|
-
export declare const parseUnenclosed: (s:
|
|
14
|
-
export type parseUnenclosed<s extends StaticState, $, args> =
|
|
15
|
-
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,
|
|
16
|
-
export declare const parseGenericInstantiation: (name: string, g: GenericRoot, s:
|
|
17
|
-
export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> =
|
|
13
|
+
export declare const parseUnenclosed: (s: RuntimeState) => void;
|
|
14
|
+
export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntil<s["unscanned"], TerminatingChar> extends (Scanner.shiftResult<infer token, infer unscanned>) ? tryResolve<s, unscanned, token, $, args> extends s.from<infer s> ? s : never : never;
|
|
15
|
+
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, s.scanTo<s, unscanned>, $, args> : s.setRoot<s, ast, unscanned> : never;
|
|
16
|
+
export declare const parseGenericInstantiation: (name: string, g: GenericRoot, s: RuntimeState) => BaseRoot;
|
|
17
|
+
export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ? parseGenericArgs<name, g, unscanned, $, args> extends infer result ? result extends ParsedArgs<infer argAsts, infer nextUnscanned> ? s.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : s.error<writeInvalidGenericArgCountMessage<name, genericParamNames<g["paramsAst"]>, [
|
|
18
18
|
]>>;
|
|
19
|
-
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> :
|
|
19
|
+
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 ArkAmbient.$ ? parseResolution<s, unscanned, token, ArkAmbient.$[token], $, args> : `#${token}` extends keyof $ ? parseResolution<s, unscanned, token, $[`#${token}`], $, args> : token extends NumberLiteral<infer n> ? s.setRoot<s, InferredAst<n, token>, unscanned> : token extends (`${infer submodule extends keyof $ & string}.${infer reference}`) ? tryResolveSubmodule<token, $[submodule], reference, s, unscanned, $, args, [
|
|
20
20
|
submodule
|
|
21
21
|
]> : token extends (`${infer submodule extends keyof ArkAmbient.$ & string}.${infer reference}`) ? tryResolveSubmodule<token, ArkAmbient.$[submodule], reference, s, unscanned, $, args, [
|
|
22
22
|
submodule
|
|
23
|
-
]> : token extends BigintLiteral<infer b> ?
|
|
23
|
+
]> : token extends BigintLiteral<infer b> ? s.setRoot<s, InferredAst<b, token>, unscanned> : token extends "keyof" ? s.addPrefix<s, "keyof", unscanned> : unresolvableState<s, token, $, args, []>;
|
|
24
24
|
type tryResolveSubmodule<token extends string, resolution, reference extends string, s extends StaticState, unscanned extends string, $, args, submodulePath extends string[]> = resolution extends {
|
|
25
25
|
[arkKind]: "module";
|
|
26
26
|
} ? reference extends keyof resolution ? parseResolution<s, unscanned, token, resolution[reference], $, args> : reference extends (`${infer nestedSubmodule extends keyof resolution & string}.${infer nestedReference}`) ? tryResolveSubmodule<token, resolution[nestedSubmodule], nestedReference, s, unscanned, $, args, [
|
|
27
27
|
...submodulePath,
|
|
28
28
|
nestedSubmodule
|
|
29
|
-
]> : unresolvableState<s, reference, resolution, {}, submodulePath> :
|
|
29
|
+
]> : unresolvableState<s, reference, resolution, {}, submodulePath> : s.error<writeNonSubmoduleDotMessage<lastOf<submodulePath>>>;
|
|
30
30
|
/** Provide valid completions for the current token, or fallback to an
|
|
31
31
|
* unresolvable error if there are none */
|
|
32
32
|
export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
|
|
33
33
|
token,
|
|
34
34
|
s["unscanned"]
|
|
35
|
-
] extends ([
|
|
36
|
-
"",
|
|
37
|
-
ArkTypeScanner.shift<"#", infer unscanned>
|
|
38
|
-
]) ? 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
|
+
] extends ["", Scanner.shift<"#", infer unscanned>] ? Scanner.shiftUntil<unscanned, TerminatingChar> extends (Scanner.shiftResult<infer name, string>) ? s.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? s.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : s.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
|
|
39
36
|
type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
|
|
40
37
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
|
|
41
|
-
export declare const writeMissingOperandMessage: (s:
|
|
38
|
+
export declare const writeMissingOperandMessage: (s: RuntimeState) => string;
|
|
42
39
|
export type writeMissingRightOperandMessage<token extends string, unscanned extends string = ""> = `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
43
40
|
export declare const writeMissingRightOperandMessage: <token extends string, unscanned extends string>(token: token, unscanned?: unscanned) => writeMissingRightOperandMessage<token, unscanned>;
|
|
44
41
|
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => writeExpressionExpectedMessage<unscanned>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";
|
|
2
2
|
import { printable, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber } from "@ark/util";
|
|
3
3
|
import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.js";
|
|
4
|
+
import { terminatingChars } from "../tokens.js";
|
|
4
5
|
import { parseGenericArgs, writeInvalidGenericArgCountMessage } from "./genericArgs.js";
|
|
5
6
|
export const parseUnenclosed = (s) => {
|
|
6
|
-
const token = s.scanner.
|
|
7
|
+
const token = s.scanner.shiftUntilLookahead(terminatingChars);
|
|
7
8
|
if (token === "keyof")
|
|
8
9
|
s.addPrefix("keyof");
|
|
9
10
|
else
|
|
@@ -21,7 +22,7 @@ const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
|
|
|
21
22
|
maybeParseUnenclosedLiteral(s, token) ??
|
|
22
23
|
s.error(token === "" ?
|
|
23
24
|
s.scanner.lookahead === "#" ?
|
|
24
|
-
writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.
|
|
25
|
+
writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.shiftUntilLookahead(terminatingChars))
|
|
25
26
|
: writeMissingOperandMessage(s)
|
|
26
27
|
: writeUnresolvableMessage(token));
|
|
27
28
|
const maybeParseReference = (s, token) => {
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { type BaseRoot, type BoundKind } from "@ark/schema";
|
|
2
|
-
import { type KeySet } from "@ark/util";
|
|
2
|
+
import { type KeySet, type Scanner } 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";
|
|
6
|
-
import type {
|
|
6
|
+
import type { RootedRuntimeState, RuntimeState } from "../../reduce/dynamic.ts";
|
|
7
7
|
import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.ts";
|
|
8
|
-
import type {
|
|
8
|
+
import type { s, StaticState } from "../../reduce/static.ts";
|
|
9
9
|
import type { parseOperand } from "../operand/operand.ts";
|
|
10
|
-
|
|
11
|
-
export
|
|
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;
|
|
10
|
+
export declare const parseBound: (s: RootedRuntimeState, start: ComparatorStartChar) => void;
|
|
11
|
+
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 (InferredAst<Date | number, `${infer limit extends number | DateLiteral}`>) ? s.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<s.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
|
|
13
12
|
type OneCharComparator = ">" | "<";
|
|
14
13
|
export type ComparatorStartChar = Comparator extends `${infer char}${string}` ? char : never;
|
|
15
14
|
export declare const comparatorStartChars: KeySet<ComparatorStartChar>;
|
|
16
|
-
declare const shiftComparator: (s:
|
|
15
|
+
declare const shiftComparator: (s: RuntimeState, start: ComparatorStartChar) => Comparator;
|
|
17
16
|
type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : [start & OneCharComparator, unscanned];
|
|
18
17
|
export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
|
|
19
18
|
export declare const getBoundKinds: (comparator: Comparator, limit: number | DateLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
|
|
20
|
-
export declare const parseRightBound: (s:
|
|
21
|
-
export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends (InferredAst<unknown, `${infer limit extends number | DateLiteral}`>) ? s["branches"]["leftBound"] extends {} ? comparator extends MaxComparator ?
|
|
19
|
+
export declare const parseRightBound: (s: RootedRuntimeState, comparator: Comparator) => void;
|
|
20
|
+
export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends (InferredAst<unknown, `${infer limit extends number | DateLiteral}`>) ? s["branches"]["leftBound"] extends {} ? comparator extends MaxComparator ? s.reduceRange<s, s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], comparator, limit, nextState["unscanned"]> : s.error<writeUnpairableComparatorMessage<comparator>> : s.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : s.error<writeInvalidLimitMessage<comparator, astToString<nextState["root"]>, "right">> : never;
|
|
22
21
|
export declare const writeInvalidLimitMessage: <comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => writeInvalidLimitMessage<comparator, limit, boundKind>;
|
|
23
22
|
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})`;
|
|
24
23
|
export type BoundExpressionKind = "left" | "right";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { emptyBrandNameMessage } from "@ark/schema";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export
|
|
2
|
+
import type { Scanner } from "@ark/util";
|
|
3
|
+
import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
|
|
4
|
+
import type { StaticState, s } from "../../reduce/static.ts";
|
|
5
|
+
import { type TerminatingChar } from "../tokens.ts";
|
|
6
|
+
export declare const parseBrand: (s: RootedRuntimeState) => void;
|
|
7
|
+
export type parseBrand<s extends StaticState, unscanned extends string> = Scanner.shiftUntil<Scanner.skipWhitespace<unscanned>, TerminatingChar> extends Scanner.shiftResult<`${infer brandName}`, infer nextUnscanned> ? brandName extends "" ? s.error<emptyBrandNameMessage> : s.setRoot<s, [s["root"], "#", brandName], nextUnscanned> : never;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { terminatingChars } from "../tokens.js";
|
|
1
2
|
export const parseBrand = (s) => {
|
|
2
3
|
s.scanner.shiftUntilNonWhitespace();
|
|
3
|
-
const brandName = s.scanner.
|
|
4
|
+
const brandName = s.scanner.shiftUntilLookahead(terminatingChars);
|
|
4
5
|
s.root = s.root.brand(brandName);
|
|
5
6
|
};
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import type { BaseRoot } from "@ark/schema";
|
|
2
|
-
import type { BigintLiteral, ErrorMessage, NumberLiteral, trim } from "@ark/util";
|
|
2
|
+
import type { BigintLiteral, ErrorMessage, NumberLiteral, Scanner, trim } from "@ark/util";
|
|
3
3
|
import type { DateLiteral } from "../../../attributes.ts";
|
|
4
|
-
import type {
|
|
5
|
-
import type { StringLiteral } from "../operand/enclosed.ts";
|
|
4
|
+
import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
|
|
5
|
+
import type { EnclosingLiteralStartToken, EnclosingLiteralTokens, StringLiteral } from "../operand/enclosed.ts";
|
|
6
6
|
type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
|
|
7
|
-
export type UnitLiteral =
|
|
7
|
+
export type UnitLiteral = UnenclosedUnitLiteral | EnclosedUnitLiteral;
|
|
8
|
+
export type UnenclosedUnitLiteral = BigintLiteral | NumberLiteral | UnitLiteralKeyword;
|
|
9
|
+
export type EnclosedUnitLiteral = StringLiteral | DateLiteral;
|
|
8
10
|
export type ParsedDefaultableProperty = readonly [BaseRoot, "=", unknown];
|
|
9
|
-
export declare const parseDefault: (s:
|
|
10
|
-
export type parseDefault<root, unscanned extends string> = trim<unscanned> extends infer
|
|
11
|
+
export declare const parseDefault: (s: RootedRuntimeState) => ParsedDefaultableProperty;
|
|
12
|
+
export type parseDefault<root, unscanned extends string> = trim<unscanned> extends infer defaultExpression extends string ? defaultExpression extends UnenclosedUnitLiteral ? [
|
|
11
13
|
root,
|
|
12
14
|
"=",
|
|
13
|
-
|
|
14
|
-
] :
|
|
15
|
+
defaultExpression
|
|
16
|
+
] : defaultExpression extends (`${infer start extends EnclosingLiteralStartToken}${string}`) ? defaultExpression extends `${start}${infer nextUnscanned}` ? isValidEnclosedLiteral<start, nextUnscanned> extends true ? [
|
|
17
|
+
root,
|
|
18
|
+
"=",
|
|
19
|
+
defaultExpression
|
|
20
|
+
] : ErrorMessage<writeNonLiteralDefaultMessage<defaultExpression>> : never : ErrorMessage<writeNonLiteralDefaultMessage<defaultExpression>> : never;
|
|
21
|
+
export type isValidEnclosedLiteral<start extends EnclosingLiteralStartToken, unscanned extends string> = Scanner.shiftUntilEscapable<unscanned, EnclosingLiteralTokens[start], ""> extends Scanner.shiftResult<string, infer nextUnscanned> ? nextUnscanned extends EnclosingLiteralTokens[start] ? true : false : false;
|
|
15
22
|
export declare const writeNonLiteralDefaultMessage: <defaultDef extends string>(defaultDef: defaultDef) => writeNonLiteralDefaultMessage<defaultDef>;
|
|
16
|
-
export type writeNonLiteralDefaultMessage<defaultDef extends string> = `Default value '${defaultDef}' must a literal value`;
|
|
23
|
+
export type writeNonLiteralDefaultMessage<defaultDef extends string> = `Default value '${defaultDef}' must be a literal value`;
|
|
17
24
|
export {};
|
|
@@ -12,4 +12,4 @@ export const parseDefault = (s) => {
|
|
|
12
12
|
: defaultNode.unit;
|
|
13
13
|
return [baseNode, "=", defaultValue];
|
|
14
14
|
};
|
|
15
|
-
export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must a literal value`;
|
|
15
|
+
export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must be a literal value`;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
export
|
|
1
|
+
import { type Scanner } from "@ark/util";
|
|
2
|
+
import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
|
|
3
|
+
import type { StaticState, s } from "../../reduce/static.ts";
|
|
4
|
+
import { type TerminatingChar } from "../tokens.ts";
|
|
5
|
+
export declare const parseDivisor: (s: RootedRuntimeState) => void;
|
|
6
|
+
export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntil<Scanner.skipWhitespace<unscanned>, TerminatingChar> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? s.error<writeInvalidDivisorMessage<0>> : s.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : s.error<writeInvalidDivisorMessage<scanned>> : never;
|
|
6
7
|
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => writeInvalidDivisorMessage<divisor>;
|
|
7
8
|
export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { tryParseInteger } from "@ark/util";
|
|
2
|
+
import { terminatingChars } from "../tokens.js";
|
|
2
3
|
export const parseDivisor = (s) => {
|
|
3
|
-
|
|
4
|
+
s.scanner.shiftUntilNonWhitespace();
|
|
5
|
+
const divisorToken = s.scanner.shiftUntilLookahead(terminatingChars);
|
|
4
6
|
const divisor = tryParseInteger(divisorToken, {
|
|
5
7
|
errorOnFail: writeInvalidDivisorMessage(divisorToken)
|
|
6
8
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { type WhitespaceChar } from "@ark/util";
|
|
2
|
-
import type {
|
|
3
|
-
import type { StaticState,
|
|
4
|
-
import {
|
|
1
|
+
import { type Scanner, type WhitespaceChar } from "@ark/util";
|
|
2
|
+
import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
|
|
3
|
+
import type { StaticState, s } from "../../reduce/static.ts";
|
|
4
|
+
import { lookaheadIsFinalizing, type FinalizingLookahead } from "../tokens.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
|
-
export declare const parseOperator: (s:
|
|
9
|
-
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends
|
|
8
|
+
export declare const parseOperator: (s: RootedRuntimeState) => void;
|
|
9
|
+
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? s.setRoot<s, [s["root"], "[]"], nextUnscanned> : s.error<incompleteArrayTokenMessage> : lookahead extends "|" ? unscanned extends Scanner.shift<">", infer nextUnscanned> ? s.reduceBranch<s, "|>", nextUnscanned> : s.reduceBranch<s, lookahead, unscanned> : lookahead extends "&" ? s.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? s.finalizeGroup<s, unscanned> : lookaheadIsFinalizing<lookahead, unscanned> extends true ? s.finalize<s.scanTo<s, unscanned>, lookahead & FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhitespaceChar ? parseOperator<s.scanTo<s, unscanned>, $, args> : s.error<writeUnexpectedCharacterMessage<lookahead>> : s.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
1
|
import { isKeyOf, whitespaceChars } from "@ark/util";
|
|
2
|
-
import {
|
|
2
|
+
import { lookaheadIsFinalizing } from "../tokens.js";
|
|
3
3
|
import { comparatorStartChars, parseBound } from "./bounds.js";
|
|
4
4
|
import { parseBrand } from "./brand.js";
|
|
5
5
|
import { parseDivisor } from "./divisor.js";
|
|
@@ -16,7 +16,7 @@ export const parseOperator = (s) => {
|
|
|
16
16
|
: s.pushRootToBranch(lookahead)
|
|
17
17
|
: lookahead === "&" ? s.pushRootToBranch(lookahead)
|
|
18
18
|
: lookahead === ")" ? s.finalizeGroup()
|
|
19
|
-
:
|
|
19
|
+
: lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
|
|
20
20
|
s.finalize(lookahead)
|
|
21
21
|
: isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
|
|
22
22
|
: lookahead === "%" ? parseDivisor(s)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Scanner } from "@ark/util";
|
|
2
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
3
|
+
export declare const terminatingChars: {
|
|
4
|
+
readonly " ": 1;
|
|
5
|
+
readonly "\n": 1;
|
|
6
|
+
readonly "\t": 1;
|
|
7
|
+
readonly "<": 1;
|
|
8
|
+
readonly ">": 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
|
+
};
|
|
20
|
+
export type TerminatingChar = keyof typeof terminatingChars;
|
|
21
|
+
export declare const finalizingLookaheads: {
|
|
22
|
+
readonly ">": 1;
|
|
23
|
+
readonly ",": 1;
|
|
24
|
+
readonly "": 1;
|
|
25
|
+
readonly "=": 1;
|
|
26
|
+
readonly "?": 1;
|
|
27
|
+
};
|
|
28
|
+
export type FinalizingLookahead = keyof typeof finalizingLookaheads;
|
|
29
|
+
export declare const lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=" | "?";
|
|
30
|
+
export type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," | "?" ? true : false;
|
|
31
|
+
export type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "|>" | "#" | "@" | "=";
|
|
32
|
+
export type PostfixToken = "[]" | "?";
|
|
33
|
+
export type OperatorToken = InfixToken | PostfixToken;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isKeyOf, whitespaceChars } from "@ark/util";
|
|
2
|
+
export const terminatingChars = {
|
|
3
|
+
"<": 1,
|
|
4
|
+
">": 1,
|
|
5
|
+
"=": 1,
|
|
6
|
+
"|": 1,
|
|
7
|
+
"&": 1,
|
|
8
|
+
")": 1,
|
|
9
|
+
"[": 1,
|
|
10
|
+
"%": 1,
|
|
11
|
+
",": 1,
|
|
12
|
+
":": 1,
|
|
13
|
+
"?": 1,
|
|
14
|
+
"#": 1,
|
|
15
|
+
...whitespaceChars
|
|
16
|
+
};
|
|
17
|
+
export const finalizingLookaheads = {
|
|
18
|
+
">": 1,
|
|
19
|
+
",": 1,
|
|
20
|
+
"": 1,
|
|
21
|
+
"=": 1,
|
|
22
|
+
"?": 1
|
|
23
|
+
};
|
|
24
|
+
export const lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
|
|
25
|
+
unscanned[0] === "=" ?
|
|
26
|
+
// >== would only occur in an expression like Array<number>==5
|
|
27
|
+
// otherwise, >= would only occur as part of a bound like number>=5
|
|
28
|
+
unscanned[1] === "="
|
|
29
|
+
// if > is the end of a generic instantiation, the next token will be
|
|
30
|
+
// an operator or the end of the string
|
|
31
|
+
: unscanned.trimStart() === "" ||
|
|
32
|
+
isKeyOf(unscanned.trimStart()[0], terminatingChars)
|
|
33
|
+
// "=" is a finalizer on its own (representing a default value),
|
|
34
|
+
// but not with a second "=" (an equality comparator)
|
|
35
|
+
: lookahead === "=" ? unscanned[0] !== "="
|
|
36
|
+
// "," and "?" are unambiguously finalizers
|
|
37
|
+
: lookahead === "," || lookahead === "?";
|
package/out/parser/string.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { type ErrorMessage } from "@ark/util";
|
|
|
3
3
|
import type { ArkAmbient } from "../config.ts";
|
|
4
4
|
import type { InnerParseResult, resolutionToAst } from "../scope.ts";
|
|
5
5
|
import type { inferAstRoot } from "./ast/infer.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { RuntimeState, type RootedRuntimeState } from "./reduce/dynamic.ts";
|
|
7
7
|
import type { StringifiablePrefixOperator } from "./reduce/shared.ts";
|
|
8
|
-
import type {
|
|
8
|
+
import type { s, StaticState } from "./reduce/static.ts";
|
|
9
9
|
import type { parseOperand } from "./shift/operand/operand.ts";
|
|
10
10
|
import { parseDefault } from "./shift/operator/default.ts";
|
|
11
11
|
import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.ts";
|
|
@@ -17,14 +17,14 @@ export declare const parseString: (def: string, ctx: BaseParseContext) => InnerP
|
|
|
17
17
|
export type parseString<def extends string, $, args> = def extends keyof $ ? resolutionToAst<def, $[def]> : def extends `${infer child}[]` ? child extends keyof $ ? [
|
|
18
18
|
resolutionToAst<child, $[child]>,
|
|
19
19
|
"[]"
|
|
20
|
-
] : fullStringParse<
|
|
20
|
+
] : fullStringParse<s.initialize<def>, $, args> : fullStringParse<s.initialize<def>, $, args>;
|
|
21
21
|
export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
|
|
22
22
|
export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ArkAmbient.$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
|
|
23
|
-
export declare const fullStringParse: (s:
|
|
23
|
+
export declare const fullStringParse: (s: RuntimeState) => InnerParseResult;
|
|
24
24
|
type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
|
|
25
|
-
export declare const parseUntilFinalizer: (s:
|
|
25
|
+
export declare const parseUntilFinalizer: (s: RuntimeState) => RootedRuntimeState;
|
|
26
26
|
export type parseUntilFinalizer<s extends StaticState, $, args> = s["finalizer"] extends undefined ? parseUntilFinalizer<next<s, $, args>, $, args> : s;
|
|
27
|
-
declare const next: (s:
|
|
27
|
+
declare const next: (s: RuntimeState) => void;
|
|
28
28
|
type next<s extends StaticState, $, args> = s["root"] extends undefined ? parseOperand<s, $, args> : parseOperator<s, $, args>;
|
|
29
29
|
export type extractFinalizedResult<s extends StaticState> = s["finalizer"] extends "" ? s["root"] : s["finalizer"] extends ErrorMessage ? s["finalizer"] : s["finalizer"] extends "?" ? [s["root"], "?"] : s["finalizer"] extends "=" ? parseDefault<s["root"], s["unscanned"]> : ErrorMessage<writeUnexpectedCharacterMessage<s["finalizer"] & string>>;
|
|
30
30
|
export {};
|
package/out/parser/string.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { throwInternalError, throwParseError } from "@ark/util";
|
|
2
|
-
import {
|
|
1
|
+
import { Scanner, throwInternalError, throwParseError } from "@ark/util";
|
|
2
|
+
import { RuntimeState } from "./reduce/dynamic.js";
|
|
3
3
|
import { parseDefault } from "./shift/operator/default.js";
|
|
4
4
|
import { writeUnexpectedCharacterMessage } from "./shift/operator/operator.js";
|
|
5
|
-
import { ArkTypeScanner } from "./shift/scanner.js";
|
|
6
5
|
export const parseString = (def, ctx) => {
|
|
7
6
|
const aliasResolution = ctx.$.maybeResolveRoot(def);
|
|
8
7
|
if (aliasResolution)
|
|
@@ -12,7 +11,7 @@ export const parseString = (def, ctx) => {
|
|
|
12
11
|
if (possibleElementResolution)
|
|
13
12
|
return possibleElementResolution.array();
|
|
14
13
|
}
|
|
15
|
-
const s = new
|
|
14
|
+
const s = new RuntimeState(new Scanner(def), ctx);
|
|
16
15
|
const node = fullStringParse(s);
|
|
17
16
|
if (s.finalizer === ">")
|
|
18
17
|
throwParseError(writeUnexpectedCharacterMessage(">"));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type BaseParseContext, type BaseRoot, type Morph, type Predicate, type TypeMeta, type unwrapDefault } from "@ark/schema";
|
|
1
|
+
import { type BaseParseContext, type BaseRoot, type Morph, type NodeSelector, type Predicate, type TypeMeta, type unwrapDefault } from "@ark/schema";
|
|
2
2
|
import { type array, type BuiltinObjectKind, type Constructor, type Domain, type show } from "@ark/util";
|
|
3
3
|
import type { defaultFor, distill, inferIntersection, inferMorphOut, inferPipe, inferPredicate, Out, withDefault } from "../attributes.ts";
|
|
4
4
|
import type { type } from "../keywords/keywords.ts";
|
|
5
5
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
6
6
|
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
|
|
7
|
-
import type {
|
|
7
|
+
import type { InfixToken } from "./shift/tokens.ts";
|
|
8
8
|
import type { BaseCompletions } from "./string.ts";
|
|
9
9
|
export declare const maybeParseTupleExpression: (def: array, ctx: BaseParseContext) => BaseRoot | null;
|
|
10
10
|
export type maybeValidateTupleExpression<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends IndexOneExpression ? validateIndexOneExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
|
|
@@ -16,7 +16,8 @@ export type validatePrefixExpression<def extends IndexZeroExpression, $, args> =
|
|
|
16
16
|
export type validateIndexOneExpression<def extends IndexOneExpression, $, args> = def[1] extends TuplePostfixOperator ? readonly [validateDefinition<def[0], $, args>, def[1]] : readonly [
|
|
17
17
|
validateDefinition<def[0], $, args>,
|
|
18
18
|
def["length"] extends 2 ? writeMissingRightOperandMessage<def[1]> : def[1],
|
|
19
|
-
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "|>" ? validateDefinition<def[2], $, args> : def[1] extends "=" ? defaultFor<type.infer.In<def[0], $, args>> : def[1] extends "@" ? TypeMeta.MappableInput : validateDefinition<def[2], $, args
|
|
19
|
+
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "|>" ? validateDefinition<def[2], $, args> : def[1] extends "=" ? defaultFor<type.infer.In<def[0], $, args>> : def[1] extends "@" ? TypeMeta.MappableInput : validateDefinition<def[2], $, args>,
|
|
20
|
+
...(def[1] extends "@" ? [NodeSelector?] : [])
|
|
20
21
|
];
|
|
21
22
|
export type UnparsedTupleExpressionInput = {
|
|
22
23
|
instanceof: Constructor;
|
|
@@ -62,11 +63,7 @@ declare const indexOneParsers: {
|
|
|
62
63
|
"[]": IndexOneParser<"[]">;
|
|
63
64
|
};
|
|
64
65
|
export type IndexOneOperator = keyof typeof indexOneParsers;
|
|
65
|
-
export type InfixExpression = readonly [
|
|
66
|
-
unknown,
|
|
67
|
-
ArkTypeScanner.InfixToken,
|
|
68
|
-
...unknown[]
|
|
69
|
-
];
|
|
66
|
+
export type InfixExpression = readonly [unknown, InfixToken, ...unknown[]];
|
|
70
67
|
type IndexZeroParser<token extends string> = (def: IndexZeroExpression<token>, ctx: BaseParseContext) => BaseRoot;
|
|
71
68
|
type IndexZeroExpression<token extends string = IndexZeroOperator> = readonly [
|
|
72
69
|
token,
|
|
@@ -34,7 +34,7 @@ export const parseNarrowTuple = (def, ctx) => {
|
|
|
34
34
|
}
|
|
35
35
|
return ctx.$.parseOwnDefinitionFormat(def[0], ctx).constrain("predicate", def[2]);
|
|
36
36
|
};
|
|
37
|
-
const
|
|
37
|
+
const parseMetaTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).configure(def[2], def[3]);
|
|
38
38
|
const defineIndexOneParsers = (parsers) => parsers;
|
|
39
39
|
const postfixParsers = defineIndexOneParsers({
|
|
40
40
|
"[]": parseArrayTuple,
|
|
@@ -46,7 +46,7 @@ const infixParsers = defineIndexOneParsers({
|
|
|
46
46
|
":": parseNarrowTuple,
|
|
47
47
|
"=>": parseMorphTuple,
|
|
48
48
|
"|>": parseBranchTuple,
|
|
49
|
-
"@":
|
|
49
|
+
"@": parseMetaTuple,
|
|
50
50
|
// since object and tuple literals parse there via `parseProperty`,
|
|
51
51
|
// they must be shallow if parsed directly as a tuple expression
|
|
52
52
|
"=": () => throwParseError(shallowDefaultableMessage)
|