arktype 2.0.0-rc.2 → 2.0.0-rc.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/out/attributes.d.ts +274 -0
  2. package/out/attributes.js +2 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +52 -55
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +4 -4
  7. package/out/index.js +2 -2
  8. package/out/keywords/builtins.js +2 -2
  9. package/out/keywords/constructors/Array.d.ts +2 -2
  10. package/out/keywords/constructors/Array.js +7 -7
  11. package/out/keywords/constructors/Date.d.ts +37 -0
  12. package/out/keywords/constructors/FormData.d.ts +2 -2
  13. package/out/keywords/constructors/FormData.js +8 -8
  14. package/out/keywords/constructors/TypedArray.js +2 -2
  15. package/out/keywords/constructors/constructors.d.ts +0 -1
  16. package/out/keywords/constructors/constructors.js +2 -2
  17. package/out/keywords/keywords.d.ts +64 -0
  18. package/out/keywords/{ark.js → keywords.js} +14 -9
  19. package/out/keywords/number/epoch.d.ts +1 -1
  20. package/out/keywords/number/epoch.js +2 -2
  21. package/out/keywords/number/integer.js +2 -2
  22. package/out/keywords/number/number.d.ts +44 -14
  23. package/out/keywords/number/number.js +17 -5
  24. package/out/keywords/string/alpha.d.ts +2 -2
  25. package/out/keywords/string/alphanumeric.d.ts +2 -2
  26. package/out/keywords/string/base64.d.ts +21 -0
  27. package/out/keywords/string/base64.js +6 -0
  28. package/out/keywords/string/capitalize.d.ts +3 -3
  29. package/out/keywords/string/capitalize.js +4 -4
  30. package/out/keywords/string/creditCard.d.ts +2 -2
  31. package/out/keywords/string/creditCard.js +2 -2
  32. package/out/keywords/string/date.d.ts +7 -11
  33. package/out/keywords/string/date.js +16 -16
  34. package/out/keywords/string/digits.d.ts +2 -2
  35. package/out/keywords/string/email.d.ts +2 -2
  36. package/out/keywords/string/integer.d.ts +3 -3
  37. package/out/keywords/string/integer.js +7 -7
  38. package/out/keywords/string/ip.d.ts +5 -5
  39. package/out/keywords/string/ip.js +5 -5
  40. package/out/keywords/string/json.d.ts +4 -3
  41. package/out/keywords/string/json.js +39 -30
  42. package/out/keywords/string/lower.d.ts +3 -3
  43. package/out/keywords/string/lower.js +4 -4
  44. package/out/keywords/string/normalize.d.ts +27 -31
  45. package/out/keywords/string/normalize.js +14 -14
  46. package/out/keywords/string/numeric.d.ts +3 -3
  47. package/out/keywords/string/numeric.js +7 -7
  48. package/out/keywords/string/semver.d.ts +2 -2
  49. package/out/keywords/string/string.d.ts +74 -51
  50. package/out/keywords/string/string.js +5 -3
  51. package/out/keywords/string/trim.d.ts +3 -3
  52. package/out/keywords/string/trim.js +4 -4
  53. package/out/keywords/string/upper.d.ts +3 -3
  54. package/out/keywords/string/upper.js +4 -4
  55. package/out/keywords/string/url.d.ts +3 -3
  56. package/out/keywords/string/url.js +8 -8
  57. package/out/keywords/string/uuid.d.ts +20 -20
  58. package/out/keywords/string/uuid.js +3 -3
  59. package/out/keywords/ts.d.ts +38 -1
  60. package/out/keywords/ts.js +20 -4
  61. package/out/keywords/utils.d.ts +1 -1
  62. package/out/keywords/utils.js +1 -1
  63. package/out/{subtypes → methods}/array.d.ts +6 -6
  64. package/out/methods/base.d.ts +183 -0
  65. package/out/{subtypes → methods}/date.d.ts +5 -5
  66. package/out/methods/instantiate.d.ts +17 -0
  67. package/out/methods/morph.d.ts +12 -0
  68. package/out/methods/number.d.ts +12 -0
  69. package/out/methods/object.d.ts +106 -0
  70. package/out/methods/string.d.ts +13 -0
  71. package/out/module.d.ts +2 -2
  72. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  73. package/out/parser/ast/default.d.ts +8 -0
  74. package/out/parser/ast/infer.d.ts +39 -0
  75. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  76. package/out/parser/{semantic → ast}/validate.d.ts +10 -10
  77. package/out/parser/ast/validate.js +1 -0
  78. package/out/parser/definition.d.ts +8 -9
  79. package/out/parser/objectLiteral.d.ts +14 -40
  80. package/out/parser/objectLiteral.js +8 -26
  81. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +9 -12
  82. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  83. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  84. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  85. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  86. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +6 -4
  87. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  88. package/out/parser/shift/operand/operand.d.ts +9 -0
  89. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  90. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +14 -7
  91. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  92. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  93. package/out/parser/shift/operator/brand.d.ts +6 -0
  94. package/out/parser/shift/operator/brand.js +5 -0
  95. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  96. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  97. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  98. package/out/parser/shift/operator/operator.d.ts +14 -0
  99. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  100. package/out/parser/shift/scanner.d.ts +47 -0
  101. package/out/parser/shift/scanner.js +42 -0
  102. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  103. package/out/parser/{string/string.js → string.js} +2 -0
  104. package/out/parser/tuple.d.ts +60 -44
  105. package/out/parser/tuple.js +36 -30
  106. package/out/scope.d.ts +38 -39
  107. package/out/scope.js +47 -36
  108. package/out/type.d.ts +45 -21
  109. package/out/type.js +14 -10
  110. package/package.json +3 -3
  111. package/out/intersect.d.ts +0 -28
  112. package/out/keys.d.ts +0 -16
  113. package/out/keywords/ark.d.ts +0 -39
  114. package/out/keywords/ast.d.ts +0 -193
  115. package/out/keywords/ast.js +0 -2
  116. package/out/parser/semantic/default.d.ts +0 -9
  117. package/out/parser/semantic/default.js +0 -1
  118. package/out/parser/semantic/infer.d.ts +0 -39
  119. package/out/parser/semantic/validate.js +0 -1
  120. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  121. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  122. package/out/parser/string/shift/scanner.d.ts +0 -69
  123. package/out/parser/string/shift/scanner.js +0 -100
  124. package/out/subtypes/base.d.ts +0 -85
  125. package/out/subtypes/instantiate.d.ts +0 -16
  126. package/out/subtypes/morph.d.ts +0 -13
  127. package/out/subtypes/number.d.ts +0 -12
  128. package/out/subtypes/object.d.ts +0 -33
  129. package/out/subtypes/string.d.ts +0 -13
  130. package/out/subtypes/validator.d.ts +0 -11
  131. package/out/subtypes/validator.js +0 -1
  132. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  133. /package/out/{subtypes → methods}/array.js +0 -0
  134. /package/out/{subtypes → methods}/base.js +0 -0
  135. /package/out/{subtypes → methods}/date.js +0 -0
  136. /package/out/{subtypes → methods}/instantiate.js +0 -0
  137. /package/out/{subtypes → methods}/morph.js +0 -0
  138. /package/out/{subtypes → methods}/number.js +0 -0
  139. /package/out/{subtypes → methods}/object.js +0 -0
  140. /package/out/{subtypes → methods}/string.js +0 -0
  141. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  142. /package/out/{keys.js → parser/ast/default.js} +0 -0
  143. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  144. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  145. /package/out/parser/{semantic → ast}/infer.js +0 -0
  146. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  147. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  148. /package/out/parser/{semantic → ast}/utils.js +0 -0
  149. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  150. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  151. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  152. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  153. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  154. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  155. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,6 +1,6 @@
1
1
  import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";
2
2
  import { printable, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber } from "@ark/util";
3
- import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js";
3
+ import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.js";
4
4
  import { parseGenericArgs, writeInvalidGenericArgCountMessage } from "./genericArgs.js";
5
5
  export const parseUnenclosed = (s) => {
6
6
  const token = s.scanner.shiftUntilNextTerminator();
@@ -19,13 +19,18 @@ 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
- if (s.ctx.args?.[token])
28
- return s.ctx.args[token].internal;
28
+ if (s.ctx.args?.[token]) {
29
+ const arg = s.ctx.args[token];
30
+ if (typeof arg !== "string")
31
+ return arg;
32
+ return s.ctx.$.node("alias", { reference: arg }, { prereduced: true });
33
+ }
29
34
  const resolution = s.ctx.$.maybeResolve(token);
30
35
  if (hasArkKind(resolution, "root"))
31
36
  return resolution;
@@ -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/ast.ts";
4
- import type { InferredAst } from "../../../semantic/infer.ts";
5
- import type { astToString } from "../../../semantic/utils.ts";
2
+ import { type KeySet } from "@ark/util";
3
+ import type { DateLiteral } from "../../../attributes.ts";
4
+ import type { InferredAst } from "../../ast/infer.ts";
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;
@@ -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,12 +1,11 @@
1
1
  import type { BaseRoot } from "@ark/schema";
2
- import { type BigintLiteral, type ErrorMessage, type NumberLiteral, type trim } from "@ark/util";
3
- import type { DateLiteral } from "../../../../keywords/ast.ts";
2
+ import type { BigintLiteral, ErrorMessage, NumberLiteral, trim } from "@ark/util";
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 type ParsedDefault = [BaseRoot, "=", unknown];
9
- export declare const parseDefault: (s: DynamicStateWithRoot) => ParsedDefault;
8
+ export declare const parseDefault: (s: DynamicStateWithRoot) => BaseRoot;
10
9
  export type parseDefault<root, unscanned extends string> = trim<unscanned> extends infer defaultValue extends UnitLiteral ? [
11
10
  root,
12
11
  "=",
@@ -14,6 +13,4 @@ export type parseDefault<root, unscanned extends string> = trim<unscanned> exten
14
13
  ] : ErrorMessage<writeNonLiteralDefaultMessage<trim<unscanned>>>;
15
14
  export declare const writeNonLiteralDefaultMessage: <defaultDef extends string>(defaultDef: defaultDef) => writeNonLiteralDefaultMessage<defaultDef>;
16
15
  export type writeNonLiteralDefaultMessage<defaultDef extends string> = `Default value '${defaultDef}' must a literal value`;
17
- export declare const shallowDefaultMessage = "Default values must be specified on objects like { isAdmin: 'boolean = false' }";
18
- export type shallowDefaultMessage = typeof shallowDefaultMessage;
19
16
  export {};
@@ -1,7 +1,4 @@
1
- import { throwParseError } from "@ark/util";
2
1
  export const parseDefault = (s) => {
3
- if (!s.defaultable)
4
- return throwParseError(shallowDefaultMessage);
5
2
  // store the node that will be bounded
6
3
  const baseNode = s.unsetRoot();
7
4
  s.parseOperand();
@@ -10,8 +7,9 @@ export const parseDefault = (s) => {
10
7
  // token from which it was parsed
11
8
  if (!defaultNode.hasKind("unit"))
12
9
  return s.error(writeNonLiteralDefaultMessage(defaultNode.expression));
13
- // assignability is checked in parseEntries
14
- return [baseNode, "=", defaultNode.unit];
10
+ const defaultValue = defaultNode.unit instanceof Date ?
11
+ () => new Date(defaultNode.unit)
12
+ : defaultNode.unit;
13
+ return baseNode.default(defaultValue);
15
14
  };
16
15
  export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must a literal value`;
17
- export const shallowDefaultMessage = `Default values must be specified on objects like { isAdmin: 'boolean = false' }`;
@@ -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})`;
@@ -0,0 +1,14 @@
1
+ import { type WhitespaceChar } from "@ark/util";
2
+ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
+ import type { StaticState, state } from "../../reduce/static.ts";
4
+ import { ArkTypeScanner } from "../scanner.ts";
5
+ import { parseBound, type ComparatorStartChar } from "./bounds.ts";
6
+ import { parseBrand } from "./brand.ts";
7
+ import { parseDivisor } from "./divisor.ts";
8
+ export declare const parseOperator: (s: DynamicStateWithRoot) => void;
9
+ export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends (ArkTypeScanner.shift<infer lookahead, infer unscanned>) ? lookahead extends "[" ? unscanned extends ArkTypeScanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : ArkTypeScanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & ArkTypeScanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhitespaceChar ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
10
+ export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
11
+ export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
12
+ export declare const incompleteArrayTokenMessage = "Missing expected ']'";
13
+ type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
14
+ export {};
@@ -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 ']'`;
@@ -0,0 +1,47 @@
1
+ import { Scanner, type EscapeChar, type WhitespaceChar } from "@ark/util";
2
+ import type { Comparator } from "../reduce/shared.ts";
3
+ export declare class ArkTypeScanner<lookahead extends string = string> extends Scanner<lookahead> {
4
+ shiftUntilNextTerminator(): string;
5
+ static terminatingChars: {
6
+ readonly " ": 1;
7
+ readonly "\n": 1;
8
+ readonly "\t": 1;
9
+ readonly "<": 1;
10
+ readonly ">": 1;
11
+ readonly "=": 1;
12
+ readonly "|": 1;
13
+ readonly "&": 1;
14
+ readonly ")": 1;
15
+ readonly "[": 1;
16
+ readonly "%": 1;
17
+ readonly ",": 1;
18
+ readonly ":": 1;
19
+ readonly "?": 1;
20
+ readonly "#": 1;
21
+ };
22
+ static finalizingLookaheads: {
23
+ readonly ">": 1;
24
+ readonly ",": 1;
25
+ readonly "": 1;
26
+ readonly "=": 1;
27
+ readonly "?": 1;
28
+ };
29
+ static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
30
+ }
31
+ export declare namespace ArkTypeScanner {
32
+ type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : ArkTypeScanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," | "?" ? true : false;
33
+ type TerminatingChar = keyof typeof ArkTypeScanner.terminatingChars;
34
+ type FinalizingLookahead = keyof typeof ArkTypeScanner.finalizingLookaheads;
35
+ type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "#" | "@" | "=";
36
+ type PostfixToken = "[]" | "?";
37
+ type OperatorToken = InfixToken | PostfixToken;
38
+ type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
39
+ type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeChar}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
40
+ type shiftUntilNot<unscanned extends string, nonTerminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends nonTerminator ? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`> : [scanned, unscanned] : [scanned, ""];
41
+ type shiftUntilNextTerminator<unscanned extends string> = shiftUntil<unscanned, TerminatingChar>;
42
+ type skipWhitespace<unscanned extends string> = shiftUntilNot<unscanned, WhitespaceChar>[1];
43
+ type shiftResult<scanned extends string, unscanned extends string> = [
44
+ scanned,
45
+ unscanned
46
+ ];
47
+ }
@@ -0,0 +1,42 @@
1
+ import { isKeyOf, Scanner, whitespaceChars } from "@ark/util";
2
+ export class ArkTypeScanner extends Scanner {
3
+ shiftUntilNextTerminator() {
4
+ this.shiftUntilNonWhitespace();
5
+ return this.shiftUntil(() => this.lookahead in ArkTypeScanner.terminatingChars);
6
+ }
7
+ static terminatingChars = {
8
+ "<": 1,
9
+ ">": 1,
10
+ "=": 1,
11
+ "|": 1,
12
+ "&": 1,
13
+ ")": 1,
14
+ "[": 1,
15
+ "%": 1,
16
+ ",": 1,
17
+ ":": 1,
18
+ "?": 1,
19
+ "#": 1,
20
+ ...whitespaceChars
21
+ };
22
+ static finalizingLookaheads = {
23
+ ">": 1,
24
+ ",": 1,
25
+ "": 1,
26
+ "=": 1,
27
+ "?": 1
28
+ };
29
+ static lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
30
+ unscanned[0] === "=" ?
31
+ // >== would only occur in an expression like Array<number>==5
32
+ // otherwise, >= would only occur as part of a bound like number>=5
33
+ unscanned[1] === "="
34
+ // if > is the end of a generic instantiation, the next token will be an operator or the end of the string
35
+ : unscanned.trimStart() === "" ||
36
+ isKeyOf(unscanned.trimStart()[0], ArkTypeScanner.terminatingChars)
37
+ // "=" is a finalizer on its own (representing a default value),
38
+ // but not with a second "=" (an equality comparator)
39
+ : lookahead === "=" ? unscanned[0] !== "="
40
+ // "," and "?" are unambiguously finalizers
41
+ : lookahead === "," || lookahead === "?";
42
+ }
@@ -1,13 +1,13 @@
1
1
  import type { BaseRoot, resolvableReferenceIn } from "@ark/schema";
2
2
  import { type ErrorMessage } from "@ark/util";
3
- import type { ArkAmbient } from "../../config.ts";
4
- import type { resolutionToAst } from "../../scope.ts";
5
- import type { inferAstRoot } from "../semantic/infer.ts";
3
+ import type { ArkAmbient } from "../config.ts";
4
+ import type { resolutionToAst } from "../scope.ts";
5
+ import type { inferAstRoot } from "./ast/infer.ts";
6
6
  import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.ts";
7
7
  import type { StringifiablePrefixOperator } from "./reduce/shared.ts";
8
8
  import type { state, StaticState } from "./reduce/static.ts";
9
9
  import type { parseOperand } from "./shift/operand/operand.ts";
10
- import { parseDefault, type ParsedDefault } from "./shift/operator/default.ts";
10
+ import { parseDefault } from "./shift/operator/default.ts";
11
11
  import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.ts";
12
12
  /**
13
13
  * Try to parse the definition from right to left using the most common syntax.
@@ -19,12 +19,11 @@ export type parseString<def extends string, $, args> = def extends keyof $ ? res
19
19
  ] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
20
20
  export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
21
21
  export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ArkAmbient.$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
22
- export type StringParseResult = BaseRoot | ParsedDefault;
23
- export declare const fullStringParse: (s: DynamicState) => StringParseResult;
22
+ export declare const fullStringParse: (s: DynamicState) => BaseRoot;
24
23
  type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
25
24
  export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
26
25
  export type parseUntilFinalizer<s extends StaticState, $, args> = s["finalizer"] extends undefined ? parseUntilFinalizer<next<s, $, args>, $, args> : s;
27
26
  declare const next: (s: DynamicState) => void;
28
27
  type next<s extends StaticState, $, args> = s["root"] extends undefined ? parseOperand<s, $, args> : parseOperator<s, $, args>;
29
- export type extractFinalizedResult<s extends StaticState> = s["finalizer"] extends "" ? s["root"] : s["finalizer"] extends ErrorMessage ? s["finalizer"] : s["finalizer"] extends "=" ? parseDefault<s["root"], s["unscanned"]> : state.error<writeUnexpectedCharacterMessage<`${s["finalizer"]}`>>;
28
+ 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"]> : state.error<writeUnexpectedCharacterMessage<`${s["finalizer"]}`>>;
30
29
  export {};
@@ -9,6 +9,8 @@ export const fullStringParse = (s) => {
9
9
  }
10
10
  if (s.finalizer === "=")
11
11
  result = parseDefault(s);
12
+ else if (s.finalizer === "?")
13
+ result = result.optional();
12
14
  s.scanner.shiftUntilNonWhitespace();
13
15
  if (s.scanner.lookahead) {
14
16
  // throw a parse error if non-whitespace characters made it here without being parsed
@@ -1,18 +1,22 @@
1
- import { type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
- import { type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
3
- import type { inferIntersection } from "../intersect.ts";
4
- import type { distillConstrainableIn, distillOut, inferMorphOut, inferPredicate, Out } from "../keywords/ast.ts";
5
- import type { ParseContext } from "../scope.ts";
1
+ import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
+ import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show, type Thunk } from "@ark/util";
3
+ import type { associateAttributes, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../attributes.ts";
4
+ import type { type } from "../keywords/keywords.ts";
5
+ import type { PostfixExpression } from "./ast/infer.ts";
6
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
7
- import type { InfixOperator, PostfixExpression } from "./semantic/infer.ts";
8
- import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.ts";
9
- import type { BaseCompletions } from "./string/string.ts";
10
- export declare const parseTuple: (def: array, ctx: ParseContext) => BaseRoot;
11
- export declare const parseTupleLiteral: (def: array, ctx: ParseContext) => BaseRoot;
12
- type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
7
+ import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
8
+ import type { ArkTypeScanner } from "./shift/scanner.ts";
9
+ import type { BaseCompletions } from "./string.ts";
10
+ export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
11
+ export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
12
+ type InfixExpression = readonly [
13
+ unknown,
14
+ ArkTypeScanner.InfixToken,
15
+ ...unknown[]
16
+ ];
13
17
  export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
14
18
  def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
15
- def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..." | "?"> : def[1]
19
+ def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
16
20
  ] : validateTupleLiteral<def, $, args>;
17
21
  export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
18
22
  type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
@@ -20,55 +24,75 @@ type SequenceParseState = {
20
24
  unscanned: array;
21
25
  inferred: array;
22
26
  validated: array;
27
+ includesOptional: boolean;
23
28
  };
24
29
  type parseSequence<def extends array, $, args> = parseNextElement<{
25
30
  unscanned: def;
26
31
  inferred: [];
27
32
  validated: [];
33
+ includesOptional: false;
28
34
  }, $, args>;
29
35
  type PreparsedElement = {
30
36
  head: unknown;
31
37
  tail: array;
38
+ inferred: unknown;
32
39
  optional: boolean;
33
40
  spread: boolean;
34
41
  };
35
42
  declare namespace PreparsedElement {
36
43
  type from<result extends PreparsedElement> = result;
37
44
  }
38
- type preparseNextElement<s extends SequenceParseState> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? tail extends readonly ["?", ...infer postOptionalTail] ? PreparsedElement.from<{
45
+ type preparseNextElement<s extends SequenceParseState, $, args> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
46
+ t
47
+ ] extends [anyOrNever] ? PreparsedElement.from<{
48
+ head: head;
49
+ tail: tail;
50
+ inferred: t;
51
+ optional: false;
52
+ spread: true;
53
+ }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
39
54
  head: head;
40
- tail: postOptionalTail;
55
+ tail: tail;
56
+ inferred: base;
41
57
  optional: true;
42
58
  spread: true;
43
59
  }> : PreparsedElement.from<{
44
60
  head: head;
45
61
  tail: tail;
62
+ inferred: t;
46
63
  optional: false;
47
64
  spread: true;
48
- }> : s["unscanned"] extends readonly [infer head, "?", ...infer tail] ? PreparsedElement.from<{
65
+ }> : never : s["unscanned"] extends readonly [infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
66
+ t
67
+ ] extends [anyOrNever] ? PreparsedElement.from<{
49
68
  head: head;
50
69
  tail: tail;
70
+ inferred: t;
71
+ optional: false;
72
+ spread: false;
73
+ }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
74
+ head: head;
75
+ tail: tail;
76
+ inferred: base;
51
77
  optional: true;
52
78
  spread: false;
53
- }> : s["unscanned"] extends readonly [infer head, ...infer tail] ? PreparsedElement.from<{
79
+ }> : PreparsedElement.from<{
54
80
  head: head;
55
81
  tail: tail;
82
+ inferred: t;
56
83
  optional: false;
57
84
  spread: false;
58
- }> : null;
59
- type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s> extends infer next extends PreparsedElement ? parseNextElement<{
85
+ }> : never : null;
86
+ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s, $, args> extends infer next extends PreparsedElement ? parseNextElement<{
60
87
  unscanned: next["tail"];
61
88
  inferred: next["spread"] extends true ? [
62
89
  ...s["inferred"],
63
- ...conform<inferDefinition<next["head"], $, args>, array>
64
- ] : next["optional"] extends true ? [
65
- ...s["inferred"],
66
- inferDefinition<next["head"], $, args>?
67
- ] : [...s["inferred"], inferDefinition<next["head"], $, args>];
90
+ ...conform<next["inferred"], array>
91
+ ] : next["optional"] extends true ? [...s["inferred"], next["inferred"]?] : [...s["inferred"], next["inferred"]];
68
92
  validated: [
69
93
  ...s["validated"],
70
94
  ...(next["spread"] extends true ? [
71
- inferDefinition<next["head"], $, args> extends (infer spreadOperand extends array) ? [
95
+ next["inferred"] extends infer spreadOperand extends array ? [
72
96
  number,
73
97
  number
74
98
  ] extends ([
@@ -76,17 +100,9 @@ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextEleme
76
100
  spreadOperand["length"]
77
101
  ]) ? ErrorMessage<multipleVariadicMessage> : "..." : ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
78
102
  ] : []),
79
- [
80
- next["optional"] | next["spread"],
81
- "?"
82
- ] extends ([
83
- false,
84
- s["validated"][number]
85
- ]) ? ErrorMessage<requiredPostOptionalMessage> : validateDefinition<next["head"], $, args>,
86
- ...(next["optional"] extends true ? [
87
- next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : number extends s["inferred"]["length"] ? ErrorMessage<optionalPostVariadicMessage> : "?"
88
- ] : [])
103
+ next["optional"] extends true ? next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : number extends s["inferred"]["length"] ? ErrorMessage<optionalPostVariadicMessage> : validateDefinition<next["head"], $, args> : [s["includesOptional"], next["spread"]] extends [true, false] ? ErrorMessage<requiredPostOptionalMessage> : validateDefinition<next["head"], $, args>
89
104
  ];
105
+ includesOptional: s["includesOptional"] | next["optional"] extends (false) ? false : true;
90
106
  }, $, args> : s;
91
107
  export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
92
108
  type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
@@ -99,13 +115,13 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
99
115
  export declare const spreadOptionalMessage = "A spread element cannot be optional";
100
116
  type spreadOptionalMessage = typeof optionalPostVariadicMessage;
101
117
  export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
102
- export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
118
+ export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? associateAttributes<inferDefinition<def[0], $, args>, Default<def[2] extends Thunk<infer returnValue> ? returnValue : def[2]>> : def[1] extends "?" ? associateAttributes<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
103
119
  export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never;
104
- export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]"]>;
120
+ export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
105
121
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
106
122
  validateDefinition<def[0], $, args>,
107
123
  def[1],
108
- def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<distillOut<inferDefinition<def[0], $, args>>> : def[1] extends "=>" ? Morph<distillOut<inferDefinition<def[0], $, args>>, unknown> : def[1] extends "@" ? MetaSchema : validateDefinition<def[2], $, args>
124
+ 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 "@" ? MetaSchema : def[1] extends "=" ? DefaultFor<type.infer.In<def[0], $, args>> : validateDefinition<def[2], $, args>
109
125
  ];
110
126
  export type UnparsedTupleExpressionInput = {
111
127
  instanceof: Constructor;
@@ -114,18 +130,18 @@ export type UnparsedTupleExpressionInput = {
114
130
  export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
115
131
  export declare const parseKeyOfTuple: PrefixParser<"keyof">;
116
132
  export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
117
- export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => BaseRoot;
118
- export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => BaseRoot;
133
+ export type IndexOneParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: BaseParseContext) => BaseRoot;
134
+ export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: BaseParseContext) => BaseRoot;
119
135
  export type TupleExpression = IndexZeroExpression | IndexOneExpression;
120
136
  export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
121
137
  export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
122
- export type TuplePostfixOperator = "[]";
123
- export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
138
+ export type TuplePostfixOperator = "[]" | "?";
139
+ export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@" | "=";
124
140
  export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
125
- export declare const parseMorphTuple: PostfixParser<"=>">;
141
+ export declare const parseMorphTuple: IndexOneParser<"=>">;
126
142
  export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
127
- export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distillConstrainableIn<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
128
- export declare const parseNarrowTuple: PostfixParser<":">;
143
+ export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.withAttributes.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
144
+ export declare const parseNarrowTuple: IndexOneParser<":">;
129
145
  export type IndexZeroOperator = "keyof" | "instanceof" | "===";
130
146
  export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
131
147
  export declare const writeInvalidConstructorMessage: <actual extends Domain | BuiltinObjectKind>(actual: actual) => string;