arktype 2.0.0-rc.9 → 2.0.1

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.
Files changed (128) hide show
  1. package/out/attributes.d.ts +94 -0
  2. package/out/attributes.js +3 -0
  3. package/out/generic.d.ts +13 -13
  4. package/out/index.d.ts +3 -1
  5. package/out/index.js +2 -1
  6. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
  7. package/out/keywords/{constructors/Array.js → Array.js} +2 -2
  8. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
  9. package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
  10. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  11. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
  12. package/out/keywords/builtins.js +2 -2
  13. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
  14. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  15. package/out/keywords/keywords.d.ts +14 -13
  16. package/out/keywords/keywords.js +9 -5
  17. package/out/keywords/number.d.ts +23 -0
  18. package/out/keywords/{number/epoch.js → number.js} +22 -1
  19. package/out/keywords/string.d.ts +327 -0
  20. package/out/keywords/string.js +398 -0
  21. package/out/keywords/ts.d.ts +31 -4
  22. package/out/keywords/ts.js +21 -8
  23. package/out/methods/array.d.ts +6 -7
  24. package/out/methods/base.d.ts +461 -35
  25. package/out/methods/date.d.ts +5 -6
  26. package/out/methods/instantiate.d.ts +4 -4
  27. package/out/methods/morph.d.ts +6 -6
  28. package/out/methods/number.d.ts +8 -9
  29. package/out/methods/object.d.ts +39 -15
  30. package/out/methods/string.d.ts +9 -10
  31. package/out/parser/ast/bounds.d.ts +1 -1
  32. package/out/parser/ast/default.d.ts +2 -2
  33. package/out/parser/ast/generic.d.ts +17 -0
  34. package/out/parser/ast/infer.d.ts +8 -22
  35. package/out/parser/ast/validate.d.ts +13 -9
  36. package/out/parser/ast/validate.js +3 -1
  37. package/out/parser/definition.d.ts +17 -8
  38. package/out/parser/definition.js +38 -3
  39. package/out/parser/objectLiteral.d.ts +39 -39
  40. package/out/parser/objectLiteral.js +83 -67
  41. package/out/parser/property.d.ts +36 -0
  42. package/out/parser/property.js +16 -0
  43. package/out/parser/reduce/dynamic.d.ts +8 -9
  44. package/out/parser/reduce/shared.d.ts +1 -1
  45. package/out/parser/reduce/static.d.ts +4 -4
  46. package/out/parser/shift/operand/date.d.ts +1 -1
  47. package/out/parser/shift/operand/enclosed.d.ts +3 -4
  48. package/out/parser/shift/operand/operand.d.ts +3 -3
  49. package/out/parser/shift/operand/operand.js +2 -2
  50. package/out/parser/shift/operand/unenclosed.d.ts +13 -5
  51. package/out/parser/shift/operand/unenclosed.js +5 -4
  52. package/out/parser/shift/operator/bounds.d.ts +5 -5
  53. package/out/parser/shift/operator/bounds.js +5 -4
  54. package/out/parser/shift/operator/brand.d.ts +6 -0
  55. package/out/parser/shift/operator/brand.js +5 -0
  56. package/out/parser/shift/operator/default.d.ts +3 -2
  57. package/out/parser/shift/operator/default.js +4 -1
  58. package/out/parser/shift/operator/divisor.d.ts +2 -2
  59. package/out/parser/shift/operator/operator.d.ts +4 -3
  60. package/out/parser/shift/operator/operator.js +7 -5
  61. package/out/parser/shift/scanner.d.ts +31 -55
  62. package/out/parser/shift/scanner.js +24 -83
  63. package/out/parser/string.d.ts +5 -4
  64. package/out/parser/string.js +18 -1
  65. package/out/parser/tupleExpressions.d.ts +48 -0
  66. package/out/parser/tupleExpressions.js +67 -0
  67. package/out/parser/tupleLiteral.d.ts +95 -0
  68. package/out/parser/tupleLiteral.js +122 -0
  69. package/out/scope.d.ts +17 -12
  70. package/out/scope.js +25 -41
  71. package/out/type.d.ts +63 -5
  72. package/out/type.js +3 -2
  73. package/package.json +8 -8
  74. package/out/keywords/constructors/Date.d.ts +0 -31
  75. package/out/keywords/inference.d.ts +0 -220
  76. package/out/keywords/inference.js +0 -2
  77. package/out/keywords/number/epoch.d.ts +0 -9
  78. package/out/keywords/number/integer.d.ts +0 -3
  79. package/out/keywords/number/integer.js +0 -5
  80. package/out/keywords/number/number.d.ts +0 -53
  81. package/out/keywords/number/number.js +0 -21
  82. package/out/keywords/string/alpha.d.ts +0 -7
  83. package/out/keywords/string/alpha.js +0 -2
  84. package/out/keywords/string/alphanumeric.d.ts +0 -7
  85. package/out/keywords/string/alphanumeric.js +0 -2
  86. package/out/keywords/string/capitalize.d.ts +0 -15
  87. package/out/keywords/string/capitalize.js +0 -12
  88. package/out/keywords/string/creditCard.d.ts +0 -8
  89. package/out/keywords/string/creditCard.js +0 -37
  90. package/out/keywords/string/date.d.ts +0 -55
  91. package/out/keywords/string/date.js +0 -98
  92. package/out/keywords/string/digits.d.ts +0 -7
  93. package/out/keywords/string/digits.js +0 -2
  94. package/out/keywords/string/email.d.ts +0 -7
  95. package/out/keywords/string/email.js +0 -4
  96. package/out/keywords/string/integer.d.ts +0 -16
  97. package/out/keywords/string/integer.js +0 -16
  98. package/out/keywords/string/ip.d.ts +0 -20
  99. package/out/keywords/string/ip.js +0 -23
  100. package/out/keywords/string/json.d.ts +0 -16
  101. package/out/keywords/string/json.js +0 -53
  102. package/out/keywords/string/lower.d.ts +0 -15
  103. package/out/keywords/string/lower.js +0 -12
  104. package/out/keywords/string/normalize.d.ts +0 -88
  105. package/out/keywords/string/normalize.js +0 -43
  106. package/out/keywords/string/numeric.d.ts +0 -15
  107. package/out/keywords/string/numeric.js +0 -13
  108. package/out/keywords/string/semver.d.ts +0 -7
  109. package/out/keywords/string/semver.js +0 -4
  110. package/out/keywords/string/string.d.ts +0 -108
  111. package/out/keywords/string/string.js +0 -41
  112. package/out/keywords/string/trim.d.ts +0 -15
  113. package/out/keywords/string/trim.js +0 -14
  114. package/out/keywords/string/upper.d.ts +0 -15
  115. package/out/keywords/string/upper.js +0 -12
  116. package/out/keywords/string/url.d.ts +0 -15
  117. package/out/keywords/string/url.js +0 -37
  118. package/out/keywords/string/utils.d.ts +0 -2
  119. package/out/keywords/string/utils.js +0 -10
  120. package/out/keywords/string/uuid.d.ts +0 -42
  121. package/out/keywords/string/uuid.js +0 -19
  122. package/out/keywords/utils.d.ts +0 -1
  123. package/out/keywords/utils.js +0 -2
  124. package/out/methods/validator.d.ts +0 -11
  125. package/out/methods/validator.js +0 -1
  126. package/out/parser/tuple.d.ts +0 -143
  127. package/out/parser/tuple.js +0 -164
  128. /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
@@ -1,5 +1,6 @@
1
- import { normalizeIndex } from "@ark/schema";
2
- import { append, escapeToken, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
1
+ import { intrinsic, normalizeIndex } from "@ark/schema";
2
+ import { append, escapeChar, isArray, isEmptyObject, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
3
+ import { invalidDefaultableKeyKindMessage, invalidOptionalKeyKindMessage, parseProperty } from "./property.js";
3
4
  export const parseObjectLiteral = (def, ctx) => {
4
5
  let spread;
5
6
  const structure = {};
@@ -7,25 +8,74 @@ export const parseObjectLiteral = (def, ctx) => {
7
8
  // because to match JS behavior any keys before the spread are overwritten
8
9
  // by the values in the target object, so there'd be no useful purpose in having it
9
10
  // anywhere except for the beginning.
10
- const parsedEntries = stringAndSymbolicEntriesOf(def).flatMap(entry => parseEntry(entry[0], entry[1], ctx));
11
- if (parsedEntries[0]?.kind === "spread") {
12
- // remove the spread entry so we can iterate over the remaining entries
13
- // expecting non-spread entries
14
- const spreadEntry = parsedEntries.shift();
15
- if (!spreadEntry.node.hasKind("intersection") ||
16
- !spreadEntry.node.structure) {
17
- return throwParseError(writeInvalidSpreadTypeMessage(typeof spreadEntry.node.expression));
11
+ const defEntries = stringAndSymbolicEntriesOf(def);
12
+ for (const [k, v] of defEntries) {
13
+ const parsedKey = preparseKey(k);
14
+ if (parsedKey.kind === "spread") {
15
+ if (!isEmptyObject(structure))
16
+ return throwParseError(nonLeadingSpreadError);
17
+ const operand = ctx.$.parseOwnDefinitionFormat(v, ctx);
18
+ // treat object domain as empty for spreading (useful for generic constraints)
19
+ if (operand.equals(intrinsic.object))
20
+ continue;
21
+ if (!operand.hasKind("intersection") ||
22
+ // still error on attempts to spread proto nodes like ...Date
23
+ !operand.basis?.equals(intrinsic.object)) {
24
+ return throwParseError(writeInvalidSpreadTypeMessage(operand.expression));
25
+ }
26
+ spread = operand.structure;
27
+ continue;
18
28
  }
19
- spread = spreadEntry.node.structure;
20
- }
21
- for (const entry of parsedEntries) {
22
- if (entry.kind === "spread")
23
- return throwParseError(nonLeadingSpreadError);
24
- if (entry.kind === "undeclared") {
25
- structure.undeclared = entry.behavior;
29
+ if (parsedKey.kind === "undeclared") {
30
+ if (v !== "reject" && v !== "delete" && v !== "ignore")
31
+ throwParseError(writeInvalidUndeclaredBehaviorMessage(v));
32
+ structure.undeclared = v;
33
+ continue;
34
+ }
35
+ const parsedValue = parseProperty(v, ctx);
36
+ const parsedEntryKey = parsedKey;
37
+ if (parsedKey.kind === "required") {
38
+ if (!isArray(parsedValue)) {
39
+ appendNamedProp(structure, "required", {
40
+ key: parsedKey.normalized,
41
+ value: parsedValue
42
+ }, ctx);
43
+ }
44
+ else {
45
+ appendNamedProp(structure, "optional", parsedValue[1] === "=" ?
46
+ {
47
+ key: parsedKey.normalized,
48
+ value: parsedValue[0],
49
+ default: parsedValue[2]
50
+ }
51
+ : {
52
+ key: parsedKey.normalized,
53
+ value: parsedValue[0]
54
+ }, ctx);
55
+ }
56
+ continue;
57
+ }
58
+ if (isArray(parsedValue)) {
59
+ if (parsedValue[1] === "?")
60
+ throwParseError(invalidOptionalKeyKindMessage);
61
+ if (parsedValue[1] === "=")
62
+ throwParseError(invalidDefaultableKeyKindMessage);
63
+ }
64
+ // value must be a BaseRoot at this point
65
+ if (parsedKey.kind === "optional") {
66
+ appendNamedProp(structure, "optional", {
67
+ key: parsedKey.normalized,
68
+ value: parsedValue
69
+ }, ctx);
26
70
  continue;
27
71
  }
28
- structure[entry.kind] = append(structure[entry.kind], entry);
72
+ // must be index at this point
73
+ const signature = ctx.$.parseOwnDefinitionFormat(parsedEntryKey.normalized, ctx);
74
+ const normalized = normalizeIndex(signature, parsedValue, ctx.$);
75
+ if (normalized.index)
76
+ structure.index = append(structure.index, normalized.index);
77
+ if (normalized.required)
78
+ structure.required = append(structure.required, normalized.required);
29
79
  }
30
80
  const structureNode = ctx.$.node("structure", structure);
31
81
  return ctx.$.parseSchema({
@@ -33,64 +83,30 @@ export const parseObjectLiteral = (def, ctx) => {
33
83
  structure: spread?.merge(structureNode) ?? structureNode
34
84
  });
35
85
  };
86
+ const appendNamedProp = (structure, kind, inner, ctx) => {
87
+ structure[kind] = append(
88
+ // doesn't seem like this cast should be necessary
89
+ structure[kind], ctx.$.node(kind, inner));
90
+ };
36
91
  export const writeInvalidUndeclaredBehaviorMessage = (actual) => `Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${printable(actual)})`;
37
92
  export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
38
- export const parseEntry = (key, value, ctx) => {
39
- const parsedKey = parseKey(key);
40
- if (parsedKey.kind === "+") {
41
- if (value !== "reject" && value !== "delete" && value !== "ignore")
42
- throwParseError(writeInvalidUndeclaredBehaviorMessage(value));
43
- return { kind: "undeclared", behavior: value };
44
- }
45
- if (parsedKey.kind === "...")
46
- return { kind: "spread", node: ctx.$.parseOwnDefinitionFormat(value, ctx) };
47
- const parsedValue = ctx.$.parseOwnDefinitionFormat(value, ctx);
48
- if (parsedKey.kind === "index") {
49
- const signature = ctx.$.parseOwnDefinitionFormat(parsedKey.key, ctx);
50
- const normalized = normalizeIndex(signature, parsedValue, ctx.$);
51
- return (normalized.index ?
52
- normalized.required ?
53
- [normalized.index, ...normalized.required]
54
- : normalized.index
55
- : (normalized.required ?? []));
56
- }
57
- if (parsedValue.meta) {
58
- if ("default" in parsedValue.meta) {
59
- return ctx.$.node("optional", {
60
- key: parsedKey.key,
61
- value: parsedValue,
62
- default: parsedValue.meta.default
63
- });
64
- }
65
- if (parsedValue.meta.optional) {
66
- return ctx.$.node("optional", {
67
- key: parsedKey.key,
68
- value: parsedValue
69
- });
70
- }
71
- }
72
- return ctx.$.node(parsedKey.kind, {
73
- key: parsedKey.key,
74
- value: parsedValue
75
- });
76
- };
77
- const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
93
+ export const preparseKey = (key) => typeof key === "symbol" ? { kind: "required", normalized: key }
78
94
  : key.at(-1) === "?" ?
79
- key.at(-2) === escapeToken ?
80
- { kind: "required", key: `${key.slice(0, -2)}?` }
95
+ key.at(-2) === escapeChar ?
96
+ { kind: "required", normalized: `${key.slice(0, -2)}?` }
81
97
  : {
82
98
  kind: "optional",
83
- key: key.slice(0, -1)
99
+ normalized: key.slice(0, -1)
84
100
  }
85
101
  : key[0] === "[" && key.at(-1) === "]" ?
86
- { kind: "index", key: key.slice(1, -1) }
87
- : key[0] === escapeToken && key[1] === "[" && key.at(-1) === "]" ?
88
- { kind: "required", key: key.slice(1) }
89
- : key === "..." ? { kind: key, key }
90
- : key === "+" ? { kind: key, key }
102
+ { kind: "index", normalized: key.slice(1, -1) }
103
+ : key[0] === escapeChar && key[1] === "[" && key.at(-1) === "]" ?
104
+ { kind: "required", normalized: key.slice(1) }
105
+ : key === "..." ? { kind: "spread" }
106
+ : key === "+" ? { kind: "undeclared" }
91
107
  : {
92
108
  kind: "required",
93
- key: key === "\\..." ? "..."
109
+ normalized: key === "\\..." ? "..."
94
110
  : key === "\\+" ? "+"
95
111
  : key
96
112
  };
@@ -0,0 +1,36 @@
1
+ import type { BaseParseContext, BaseRoot, UndeclaredKeyBehavior } from "@ark/schema";
2
+ import { type anyOrNever, type ErrorMessage, type ErrorType, type typeToString } from "@ark/util";
3
+ import { type inferDefinition, type validateInnerDefinition } from "./definition.ts";
4
+ import type { ParsedKeyKind, writeInvalidSpreadTypeMessage } from "./objectLiteral.ts";
5
+ import type { ParsedDefaultableProperty } from "./shift/operator/default.ts";
6
+ import type { parseString } from "./string.ts";
7
+ export type ParsedPropertyKind = "plain" | "optional" | "defaultable";
8
+ export type ParsedProperty = ParsedRequiredProperty | ParsedOptionalProperty | ParsedDefaultableProperty;
9
+ export type ParsedRequiredProperty = BaseRoot;
10
+ export type ParsedOptionalProperty = readonly [BaseRoot, "?"];
11
+ export declare const parseProperty: (def: unknown, ctx: BaseParseContext) => ParsedProperty;
12
+ export type validateProperty<def, keyKind extends ParsedKeyKind, $, args> = [
13
+ def
14
+ ] extends [anyOrNever] ?
15
+ /** this extra [anyOrNever] check is required to ensure that nested `type` invocations
16
+ * like the following are not prematurely validated by the outer call:
17
+ *
18
+ * ```ts
19
+ * type({
20
+ * "test?": type("string").pipe(x => x === "true")
21
+ * })
22
+ * ```
23
+ */
24
+ def : keyKind extends "spread" ? validateSpread<def, inferDefinition<def, $, args>, $, args> : keyKind extends "undeclared" ? UndeclaredKeyBehavior : keyKind extends "required" ? validateInnerDefinition<def, $, args> : def extends OptionalPropertyDefinition ? ErrorMessage<invalidOptionalKeyKindMessage> : isDefaultable<def, $, args> extends true ? ErrorMessage<invalidDefaultableKeyKindMessage> : validateInnerDefinition<def, $, args>;
25
+ export type isDefaultable<def, $, args> = def extends DefaultablePropertyTuple ? true : def extends PossibleDefaultableStringDefinition ? parseString<def, $, args> extends DefaultablePropertyTuple ? true : false : false;
26
+ type validateSpread<def, inferredProperty, $, args> = inferredProperty extends object ? validateInnerDefinition<def, $, args> : ErrorType<writeInvalidSpreadTypeMessage<typeToString<inferredProperty>>>;
27
+ export type OptionalPropertyDefinition<baseDef = unknown> = OptionalPropertyTuple<baseDef> | OptionalPropertyString<baseDef & string>;
28
+ export type OptionalPropertyString<baseDef extends string = string> = `${baseDef}?`;
29
+ export type OptionalPropertyTuple<baseDef = unknown> = readonly [baseDef, "?"];
30
+ export type PossibleDefaultableStringDefinition = `${string}=${string}`;
31
+ export type DefaultablePropertyTuple<baseDef = unknown, thunkableProperty = unknown> = readonly [baseDef, "=", thunkableProperty];
32
+ export declare const invalidOptionalKeyKindMessage = "Only required keys may make their values optional, e.g. { [mySymbol]: ['number', '?'] }";
33
+ export type invalidOptionalKeyKindMessage = typeof invalidOptionalKeyKindMessage;
34
+ export declare const invalidDefaultableKeyKindMessage = "Only required keys may specify default values, e.g. { value: 'number = 0' }";
35
+ export type invalidDefaultableKeyKindMessage = typeof invalidDefaultableKeyKindMessage;
36
+ export {};
@@ -0,0 +1,16 @@
1
+ import { isArray } from "@ark/util";
2
+ import { parseInnerDefinition } from "./definition.js";
3
+ export const parseProperty = (def, ctx) => {
4
+ if (isArray(def)) {
5
+ if (def[1] === "=")
6
+ return [ctx.$.parseOwnDefinitionFormat(def[0], ctx), "=", def[2]];
7
+ if (def[1] === "?")
8
+ return [ctx.$.parseOwnDefinitionFormat(def[0], ctx), "?"];
9
+ }
10
+ // string-embedded defaults/optionals are handled by the string parser
11
+ return parseInnerDefinition(def, ctx);
12
+ };
13
+ // single quote use here is better for TypeScript's inlined error to avoid escapes
14
+ export const invalidOptionalKeyKindMessage = `Only required keys may make their values optional, e.g. { [mySymbol]: ['number', '?'] }`;
15
+ // single quote use here is better for TypeScript's inlined error to avoid escapes
16
+ export const invalidDefaultableKeyKindMessage = `Only required keys may specify default values, e.g. { value: 'number = 0' }`;
@@ -1,8 +1,7 @@
1
1
  import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys } from "@ark/util";
3
- import type { LimitLiteral } from "../../keywords/inference.ts";
4
- import type { InfixOperator } from "../ast/infer.ts";
5
- import type { Scanner } from "../shift/scanner.ts";
3
+ import type { LimitLiteral } from "../../attributes.ts";
4
+ import type { ArkTypeScanner } from "../shift/scanner.ts";
6
5
  import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
7
6
  type BranchState = {
8
7
  prefixes: StringifiablePrefixOperator[];
@@ -12,19 +11,19 @@ type BranchState = {
12
11
  };
13
12
  export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
14
13
  export declare class DynamicState {
15
- root: BaseRoot<any> | undefined;
14
+ root: BaseRoot | undefined;
16
15
  branches: BranchState;
17
- finalizer: Scanner.FinalizingLookahead | undefined;
16
+ finalizer: ArkTypeScanner.FinalizingLookahead | undefined;
18
17
  groups: BranchState[];
19
- scanner: Scanner;
18
+ scanner: ArkTypeScanner;
20
19
  ctx: BaseParseContext;
21
- constructor(scanner: Scanner, ctx: BaseParseContext);
20
+ constructor(scanner: ArkTypeScanner, ctx: BaseParseContext);
22
21
  error(message: string): never;
23
22
  hasRoot(): this is DynamicStateWithRoot;
24
23
  setRoot(root: BaseRoot): void;
25
24
  unsetRoot(): this["root"];
26
25
  constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
27
- finalize(finalizer: Scanner.FinalizingLookahead): void;
26
+ finalize(finalizer: ArkTypeScanner.FinalizingLookahead): void;
28
27
  reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
29
28
  finalizeBranches(): void;
30
29
  finalizeGroup(): void;
@@ -36,7 +35,7 @@ export declare class DynamicState {
36
35
  parseOperand(): void;
37
36
  private assertRangeUnset;
38
37
  reduceGroupOpen(): void;
39
- previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined;
38
+ previousOperator(): MinComparator | StringifiablePrefixOperator | ArkTypeScanner.InfixToken | undefined;
40
39
  shiftedByOne(): this;
41
40
  }
42
41
  export {};
@@ -1,4 +1,4 @@
1
- import type { LimitLiteral } from "../../keywords/inference.ts";
1
+ import type { LimitLiteral } from "../../attributes.ts";
2
2
  export type StringifiablePrefixOperator = "keyof";
3
3
  export declare const minComparators: {
4
4
  readonly ">": true;
@@ -1,12 +1,12 @@
1
1
  import type { Completion, ErrorMessage, defined } from "@ark/util";
2
- import type { LimitLiteral } from "../../keywords/inference.ts";
3
- import type { Scanner } from "../shift/scanner.ts";
2
+ import type { LimitLiteral } from "../../attributes.ts";
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: Scanner.FinalizingLookahead | ErrorMessage | undefined;
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 Scanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
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,4 +1,4 @@
1
- import type { DateLiteral } from "../../../keywords/inference.ts";
1
+ import type { DateLiteral } from "../../../attributes.ts";
2
2
  export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
3
3
  export declare const isValidDate: (d: Date) => boolean;
4
4
  export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
@@ -1,14 +1,13 @@
1
- import type { Date } from "../../../keywords/constructors/Date.ts";
2
- import type { string } from "../../../keywords/inference.ts";
1
+ import { type Scanner } from "@ark/util";
3
2
  import type { InferredAst } from "../../ast/infer.ts";
4
3
  import type { DynamicState } from "../../reduce/dynamic.ts";
5
4
  import type { StaticState, state } from "../../reduce/static.ts";
6
- import type { Scanner } from "../scanner.ts";
5
+ import type { ArkTypeScanner } from "../scanner.ts";
7
6
  export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
8
7
  export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
9
8
  export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
10
9
  export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
11
- export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? string.matching<scanned> : Date.literal<scanned>, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
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;
12
11
  export declare const enclosingQuote: {
13
12
  readonly "'": 1;
14
13
  readonly '"': 1;
@@ -1,9 +1,9 @@
1
- import { type WhiteSpaceToken } from "@ark/util";
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 { Scanner } from "../scanner.ts";
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 Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhiteSpaceToken ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
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 { whiteSpaceTokens } from "@ark/util";
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(whiteSpaceTokens) ? parseOperand(s.shiftedByOne())
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()}`)
@@ -2,17 +2,19 @@ import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericR
2
2
  import { type BigintLiteral, type NumberLiteral, type join, type lastOf } from "@ark/util";
3
3
  import type { ArkAmbient } from "../../../config.ts";
4
4
  import type { resolutionToAst } from "../../../scope.ts";
5
- import type { GenericInstantiationAst, InferredAst } from "../../ast/infer.ts";
5
+ import type { GenericInstantiationAst } from "../../ast/generic.ts";
6
+ import type { InferredAst } from "../../ast/infer.ts";
7
+ import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
6
8
  import type { DynamicState } from "../../reduce/dynamic.ts";
7
9
  import type { StaticState, state } from "../../reduce/static.ts";
8
10
  import type { BaseCompletions } from "../../string.ts";
9
- import type { Scanner } from "../scanner.ts";
11
+ import type { ArkTypeScanner } from "../scanner.ts";
10
12
  import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.ts";
11
13
  export declare const parseUnenclosed: (s: DynamicState) => void;
12
- export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? tryResolve<s, unscanned, token, $, args> extends state.from<infer s> ? s : never : never;
14
+ 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;
13
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, state.scanTo<s, unscanned>, $, args> : state.setRoot<s, ast, unscanned> : never;
14
16
  export declare const parseGenericInstantiation: (name: string, g: GenericRoot, s: DynamicState) => BaseRoot;
15
- 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> ? state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : state.error<writeInvalidGenericArgCountMessage<name, genericParamNames<g["paramsAst"]>, [
17
+ 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"]>, [
16
18
  ]>>;
17
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 $ ? 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, [
18
20
  submodule
@@ -27,7 +29,13 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
27
29
  ]> : unresolvableState<s, reference, resolution, {}, submodulePath> : state.error<writeNonSubmoduleDotMessage<lastOf<submodulePath>>>;
28
30
  /** Provide valid completions for the current token, or fallback to an
29
31
  * unresolvable error if there are none */
30
- export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
32
+ export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
33
+ token,
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>}`>;
31
39
  type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
32
40
  type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
33
41
  export declare const writeMissingOperandMessage: (s: DynamicState) => string;
@@ -19,10 +19,11 @@ export const parseGenericInstantiation = (name, g, s) => {
19
19
  };
20
20
  const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
21
21
  maybeParseUnenclosedLiteral(s, token) ??
22
- s.error(token === "" ? writeMissingOperandMessage(s)
23
- : token[0] === "#" ?
24
- writePrefixedPrivateReferenceMessage(token)
25
- : writeUnresolvableMessage(token));
22
+ s.error(token === "" ?
23
+ s.scanner.lookahead === "#" ?
24
+ writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.shiftUntilNextTerminator())
25
+ : writeMissingOperandMessage(s)
26
+ : writeUnresolvableMessage(token));
26
27
  const maybeParseReference = (s, token) => {
27
28
  if (s.ctx.args?.[token]) {
28
29
  const arg = s.ctx.args[token];
@@ -1,18 +1,18 @@
1
1
  import { type BaseRoot, type BoundKind } from "@ark/schema";
2
- import { type keySet } from "@ark/util";
3
- import type { DateLiteral } from "../../../keywords/inference.ts";
2
+ import { type KeySet } from "@ark/util";
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
6
  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 { Scanner } from "../scanner.ts";
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 (Scanner.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;
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: keySet<ComparatorStartChar>;
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;
@@ -41,7 +41,7 @@ export const getBoundKinds = (comparator, limit, root, boundKind) => {
41
41
  if (typeof limit !== "number") {
42
42
  return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
43
43
  }
44
- return (comparator === "==" ? ["minLength", "maxLength"]
44
+ return (comparator === "==" ? ["exactLength"]
45
45
  : comparator[0] === ">" ? ["minLength"]
46
46
  : ["maxLength"]);
47
47
  }
@@ -75,9 +75,10 @@ export const parseRightBound = (s, comparator) => {
75
75
  const limit = limitNode.unit;
76
76
  // apply the newly-parsed right bound
77
77
  const exclusive = comparator.length === 1;
78
- // if the comparator is ==, both the min and max of that pair will be applied
79
- for (const kind of getBoundKinds(comparator, typeof limit === "number" ? limit : limitToken, previousRoot, "right"))
80
- s.constrainRoot(kind, { rule: limit, exclusive });
78
+ const boundKinds = getBoundKinds(comparator, typeof limit === "number" ? limit : limitToken, previousRoot, "right");
79
+ for (const kind of boundKinds) {
80
+ s.constrainRoot(kind, comparator === "==" ? { rule: limit } : { rule: limit, exclusive });
81
+ }
81
82
  if (!s.branches.leftBound)
82
83
  return;
83
84
  // if there's an open left bound, perform additional validation and apply it
@@ -0,0 +1,6 @@
1
+ import type { emptyBrandNameMessage } from "@ark/schema";
2
+ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
+ import type { StaticState, state } from "../../reduce/static.ts";
4
+ import type { ArkTypeScanner } from "../scanner.ts";
5
+ export declare const parseBrand: (s: DynamicStateWithRoot) => void;
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;
@@ -0,0 +1,5 @@
1
+ export const parseBrand = (s) => {
2
+ s.scanner.shiftUntilNonWhitespace();
3
+ const brandName = s.scanner.shiftUntilNextTerminator();
4
+ s.root = s.root.brand(brandName);
5
+ };
@@ -1,11 +1,12 @@
1
1
  import type { BaseRoot } from "@ark/schema";
2
2
  import type { BigintLiteral, ErrorMessage, NumberLiteral, trim } from "@ark/util";
3
- import type { DateLiteral } from "../../../keywords/inference.ts";
3
+ import type { DateLiteral } from "../../../attributes.ts";
4
4
  import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
5
5
  import type { StringLiteral } from "../operand/enclosed.ts";
6
6
  type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
7
7
  export type UnitLiteral = StringLiteral | BigintLiteral | NumberLiteral | DateLiteral | UnitLiteralKeyword;
8
- export declare const parseDefault: (s: DynamicStateWithRoot) => BaseRoot;
8
+ export type ParsedDefaultableProperty = readonly [BaseRoot, "=", unknown];
9
+ export declare const parseDefault: (s: DynamicStateWithRoot) => ParsedDefaultableProperty;
9
10
  export type parseDefault<root, unscanned extends string> = trim<unscanned> extends infer defaultValue extends UnitLiteral ? [
10
11
  root,
11
12
  "=",
@@ -7,6 +7,9 @@ export const parseDefault = (s) => {
7
7
  // token from which it was parsed
8
8
  if (!defaultNode.hasKind("unit"))
9
9
  return s.error(writeNonLiteralDefaultMessage(defaultNode.expression));
10
- return baseNode.default(defaultNode.unit);
10
+ const defaultValue = defaultNode.unit instanceof Date ?
11
+ () => new Date(defaultNode.unit)
12
+ : defaultNode.unit;
13
+ return [baseNode, "=", defaultValue];
11
14
  };
12
15
  export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must a literal value`;
@@ -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 { Scanner } from "../scanner.ts";
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> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.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;
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,11 +1,12 @@
1
- import { type WhiteSpaceToken } from "@ark/util";
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 { Scanner } from "../scanner.ts";
4
+ import { ArkTypeScanner } from "../scanner.ts";
5
5
  import { parseBound, type ComparatorStartChar } from "./bounds.ts";
6
+ import { parseBrand } from "./brand.ts";
6
7
  import { parseDivisor } from "./divisor.ts";
7
8
  export declare const parseOperator: (s: DynamicStateWithRoot) => void;
8
- export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.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> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
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, "">;
9
10
  export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
10
11
  export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
11
12
  export declare const incompleteArrayTokenMessage = "Missing expected ']'";
@@ -1,6 +1,7 @@
1
- import { isKeyOf, whiteSpaceTokens } from "@ark/util";
2
- import { Scanner } from "../scanner.js";
1
+ import { isKeyOf, whitespaceChars } from "@ark/util";
2
+ import { ArkTypeScanner } from "../scanner.js";
3
3
  import { comparatorStartChars, parseBound } from "./bounds.js";
4
+ import { parseBrand } from "./brand.js";
4
5
  import { parseDivisor } from "./divisor.js";
5
6
  export const parseOperator = (s) => {
6
7
  const lookahead = s.scanner.shift();
@@ -11,12 +12,13 @@ export const parseOperator = (s) => {
11
12
  : s.error(incompleteArrayTokenMessage)
12
13
  : lookahead === "|" || lookahead === "&" ? s.pushRootToBranch(lookahead)
13
14
  : lookahead === ")" ? s.finalizeGroup()
14
- : Scanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
15
+ : ArkTypeScanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
15
16
  s.finalize(lookahead)
16
17
  : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
17
18
  : lookahead === "%" ? parseDivisor(s)
18
- : lookahead in whiteSpaceTokens ? parseOperator(s)
19
- : s.error(writeUnexpectedCharacterMessage(lookahead)));
19
+ : lookahead === "#" ? parseBrand(s)
20
+ : lookahead in whitespaceChars ? parseOperator(s)
21
+ : s.error(writeUnexpectedCharacterMessage(lookahead)));
20
22
  };
21
23
  export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
22
24
  export const incompleteArrayTokenMessage = `Missing expected ']'`;