arktype 2.0.0-rc.3 → 2.0.0-rc.31

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 (176) hide show
  1. package/out/attributes.d.ts +94 -0
  2. package/out/attributes.js +3 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +55 -58
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +6 -4
  7. package/out/index.js +4 -3
  8. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +3 -3
  9. package/out/keywords/{constructors/Array.js → Array.js} +7 -7
  10. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +3 -3
  11. package/out/keywords/{constructors/FormData.js → FormData.js} +8 -8
  12. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  13. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
  14. package/out/keywords/builtins.js +2 -2
  15. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -2
  16. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  17. package/out/keywords/keywords.d.ts +61 -0
  18. package/out/keywords/keywords.js +29 -0
  19. package/out/keywords/number.d.ts +23 -0
  20. package/out/keywords/{number/epoch.js → number.js} +24 -2
  21. package/out/keywords/string.d.ts +327 -0
  22. package/out/keywords/string.js +398 -0
  23. package/out/keywords/ts.d.ts +42 -4
  24. package/out/keywords/ts.js +24 -7
  25. package/out/methods/array.d.ts +12 -0
  26. package/out/methods/base.d.ts +178 -0
  27. package/out/methods/date.d.ts +10 -0
  28. package/out/methods/instantiate.d.ts +17 -0
  29. package/out/methods/morph.d.ts +12 -0
  30. package/out/methods/number.d.ts +11 -0
  31. package/out/methods/object.d.ts +106 -0
  32. package/out/methods/string.d.ts +12 -0
  33. package/out/module.d.ts +2 -2
  34. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  35. package/out/parser/ast/default.d.ts +8 -0
  36. package/out/parser/ast/generic.d.ts +17 -0
  37. package/out/parser/ast/infer.d.ts +25 -0
  38. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  39. package/out/parser/ast/validate.d.ts +30 -0
  40. package/out/parser/ast/validate.js +3 -0
  41. package/out/parser/definition.d.ts +21 -13
  42. package/out/parser/definition.js +20 -2
  43. package/out/parser/objectLiteral.d.ts +41 -67
  44. package/out/parser/objectLiteral.js +84 -71
  45. package/out/parser/property.d.ts +36 -0
  46. package/out/parser/property.js +16 -0
  47. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +10 -13
  48. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  49. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  50. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  51. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  52. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -4
  53. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  54. package/out/parser/shift/operand/operand.d.ts +9 -0
  55. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  56. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
  57. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  58. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  59. package/out/parser/{string/shift → shift}/operator/bounds.js +5 -4
  60. package/out/parser/shift/operator/brand.d.ts +6 -0
  61. package/out/parser/shift/operator/brand.js +5 -0
  62. package/out/parser/{string/shift → shift}/operator/default.d.ts +4 -6
  63. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  64. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  65. package/out/parser/shift/operator/operator.d.ts +14 -0
  66. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  67. package/out/parser/shift/scanner.d.ts +47 -0
  68. package/out/parser/shift/scanner.js +43 -0
  69. package/out/parser/{string/string.d.ts → string.d.ts} +9 -9
  70. package/out/parser/{string/string.js → string.js} +19 -0
  71. package/out/parser/tupleExpressions.d.ts +47 -0
  72. package/out/parser/tupleExpressions.js +67 -0
  73. package/out/parser/tupleLiteral.d.ts +95 -0
  74. package/out/parser/tupleLiteral.js +122 -0
  75. package/out/scope.d.ts +41 -34
  76. package/out/scope.js +54 -62
  77. package/out/type.d.ts +46 -22
  78. package/out/type.js +15 -11
  79. package/package.json +3 -3
  80. package/out/intersect.d.ts +0 -28
  81. package/out/keys.d.ts +0 -16
  82. package/out/keywords/ark.d.ts +0 -39
  83. package/out/keywords/ark.js +0 -24
  84. package/out/keywords/ast.d.ts +0 -193
  85. package/out/keywords/ast.js +0 -2
  86. package/out/keywords/number/epoch.d.ts +0 -10
  87. package/out/keywords/number/integer.d.ts +0 -3
  88. package/out/keywords/number/integer.js +0 -5
  89. package/out/keywords/number/number.d.ts +0 -28
  90. package/out/keywords/number/number.js +0 -9
  91. package/out/keywords/string/alpha.d.ts +0 -7
  92. package/out/keywords/string/alpha.js +0 -2
  93. package/out/keywords/string/alphanumeric.d.ts +0 -7
  94. package/out/keywords/string/alphanumeric.js +0 -2
  95. package/out/keywords/string/capitalize.d.ts +0 -15
  96. package/out/keywords/string/capitalize.js +0 -12
  97. package/out/keywords/string/creditCard.d.ts +0 -8
  98. package/out/keywords/string/creditCard.js +0 -37
  99. package/out/keywords/string/date.d.ts +0 -59
  100. package/out/keywords/string/date.js +0 -98
  101. package/out/keywords/string/digits.d.ts +0 -7
  102. package/out/keywords/string/digits.js +0 -2
  103. package/out/keywords/string/email.d.ts +0 -7
  104. package/out/keywords/string/email.js +0 -4
  105. package/out/keywords/string/integer.d.ts +0 -16
  106. package/out/keywords/string/integer.js +0 -16
  107. package/out/keywords/string/ip.d.ts +0 -20
  108. package/out/keywords/string/ip.js +0 -23
  109. package/out/keywords/string/json.d.ts +0 -15
  110. package/out/keywords/string/json.js +0 -45
  111. package/out/keywords/string/lower.d.ts +0 -15
  112. package/out/keywords/string/lower.js +0 -12
  113. package/out/keywords/string/normalize.d.ts +0 -92
  114. package/out/keywords/string/normalize.js +0 -43
  115. package/out/keywords/string/numeric.d.ts +0 -15
  116. package/out/keywords/string/numeric.js +0 -13
  117. package/out/keywords/string/semver.d.ts +0 -7
  118. package/out/keywords/string/semver.js +0 -4
  119. package/out/keywords/string/string.d.ts +0 -112
  120. package/out/keywords/string/string.js +0 -41
  121. package/out/keywords/string/trim.d.ts +0 -15
  122. package/out/keywords/string/trim.js +0 -14
  123. package/out/keywords/string/upper.d.ts +0 -15
  124. package/out/keywords/string/upper.js +0 -12
  125. package/out/keywords/string/url.d.ts +0 -15
  126. package/out/keywords/string/url.js +0 -37
  127. package/out/keywords/string/utils.d.ts +0 -2
  128. package/out/keywords/string/utils.js +0 -10
  129. package/out/keywords/string/uuid.d.ts +0 -42
  130. package/out/keywords/string/uuid.js +0 -19
  131. package/out/keywords/utils.d.ts +0 -1
  132. package/out/keywords/utils.js +0 -2
  133. package/out/parser/semantic/default.d.ts +0 -9
  134. package/out/parser/semantic/default.js +0 -1
  135. package/out/parser/semantic/infer.d.ts +0 -39
  136. package/out/parser/semantic/validate.d.ts +0 -26
  137. package/out/parser/semantic/validate.js +0 -1
  138. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  139. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  140. package/out/parser/string/shift/scanner.d.ts +0 -69
  141. package/out/parser/string/shift/scanner.js +0 -100
  142. package/out/parser/tuple.d.ts +0 -132
  143. package/out/parser/tuple.js +0 -158
  144. package/out/subtypes/array.d.ts +0 -13
  145. package/out/subtypes/base.d.ts +0 -85
  146. package/out/subtypes/date.d.ts +0 -11
  147. package/out/subtypes/instantiate.d.ts +0 -16
  148. package/out/subtypes/morph.d.ts +0 -13
  149. package/out/subtypes/number.d.ts +0 -12
  150. package/out/subtypes/object.d.ts +0 -33
  151. package/out/subtypes/string.d.ts +0 -13
  152. package/out/subtypes/validator.d.ts +0 -11
  153. package/out/subtypes/validator.js +0 -1
  154. /package/out/{subtypes → methods}/array.js +0 -0
  155. /package/out/{subtypes → methods}/base.js +0 -0
  156. /package/out/{subtypes → methods}/date.js +0 -0
  157. /package/out/{subtypes → methods}/instantiate.js +0 -0
  158. /package/out/{subtypes → methods}/morph.js +0 -0
  159. /package/out/{subtypes → methods}/number.js +0 -0
  160. /package/out/{subtypes → methods}/object.js +0 -0
  161. /package/out/{subtypes → methods}/string.js +0 -0
  162. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  163. /package/out/{intersect.js → parser/ast/default.js} +0 -0
  164. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  165. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  166. /package/out/{keys.js → parser/ast/generic.js} +0 -0
  167. /package/out/parser/{semantic → ast}/infer.js +0 -0
  168. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  169. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  170. /package/out/parser/{semantic → ast}/utils.js +0 -0
  171. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  172. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  173. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  174. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  175. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  176. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,94 +1,68 @@
1
- import { type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
2
- import { type anyOrNever, type conform, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
3
- import type { constrain, Default } from "../keywords/ast.ts";
4
- import type { ParseContext } from "../scope.ts";
5
- import type { inferDefinition, validateDefinition } from "./definition.ts";
6
- import type { astToString } from "./semantic/utils.ts";
7
- import type { validateString } from "./semantic/validate.ts";
8
- export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => BaseRoot;
9
- export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
10
- export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
1
+ import { type BaseParseContext, type BaseRoot, type writeInvalidPropertyKeyMessage } from "@ark/schema";
2
+ import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeChar, type Key, type merge, type show } from "@ark/util";
3
+ import type { validateString } from "./ast/validate.ts";
4
+ import type { inferDefinition } from "./definition.ts";
5
+ import { type OptionalPropertyDefinition, type validateProperty } from "./property.ts";
6
+ export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
11
7
  export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
12
8
  /**
13
9
  * Infers the contents of an object literal, ignoring a spread definition
14
10
  */
15
11
  type _inferObjectLiteral<def extends object, $, args> = {
16
- -readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (DefaultValueTuple<infer baseDef, infer defaultValue>) ? [
17
- def[k]
18
- ] extends [anyOrNever] ? def[k] : (In?: inferDefinition<baseDef, $, args>) => Default<defaultValue> : inferDefinition<def[k], $, args>;
12
+ -readonly [k in keyof def as nonOptionalKeyFromEntry<k, def[k], $, args>]: inferDefinition<def[k], $, args>;
19
13
  } & {
20
- -readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
14
+ -readonly [k in keyof def as optionalKeyFromEntry<k, def[k]>]?: def[k] extends OptionalPropertyDefinition<infer baseDef> ? inferDefinition<baseDef, $, args> : inferDefinition<def[k], $, args>;
21
15
  };
22
16
  export type validateObjectLiteral<def, $, args> = {
23
- [k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | constrain<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefaultableValue<def, k, $, args>;
17
+ [k in keyof def]: preparseKey<k> extends (infer parsedKey extends PreparsedKey) ? parsedKey extends PreparsedEntryKey<"index"> ? validateString<parsedKey["normalized"], $, args> extends (ErrorMessage<infer message>) ? ErrorType<message> : inferDefinition<parsedKey["normalized"], $, args> extends Key ? validateProperty<def[k], parsedKey["kind"], $, args> : ErrorMessage<writeInvalidPropertyKeyMessage<parsedKey["normalized"]>> : validateProperty<def[k], parsedKey["kind"], $, args> : never;
24
18
  };
25
- type validateDefaultableValue<def, k extends keyof def, $, args> = def[k] extends DefaultValueTuple ? [
26
- def[k]
27
- ] extends [anyOrNever] ?
28
- /** this extra [anyOrNever] check is required to ensure that nested `type` invocations
29
- * like the following are not prematurely validated by the outer call:
30
- *
31
- * ```ts
32
- * type({
33
- * "test?": type("string").pipe(x => x === "true")
34
- * })
35
- * ```
36
- */
37
- def[k] : validateDefaultValueTuple<def[k], k, $, args> : validateDefinition<def[k], $, args>;
38
- type DefaultValueTuple<baseDef = unknown, defaultValue = unknown> = readonly [
39
- baseDef,
40
- "=",
41
- defaultValue
42
- ];
43
- type validateDefaultValueTuple<def extends DefaultValueTuple, k extends PropertyKey, $, args> = parseKey<k>["kind"] extends "required" ? conform<def, readonly [
44
- validateDefinition<def[0], $, args>,
45
- "=",
46
- inferDefinition<def[0], $, args>
47
- ]> : ErrorMessage<invalidDefaultKeyKindMessage>;
48
- type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> extends infer t extends Key ? t : never : never;
49
- type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
50
- type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
19
+ type nonOptionalKeyFromEntry<k extends PropertyKey, v, $, args> = preparseKey<k> extends (infer parsedKey extends PreparsedEntryKey<"required" | "index">) ? parsedKey["kind"] extends "index" ? inferDefinition<parsedKey["normalized"], $, args> & Key : [v] extends [OptionalPropertyDefinition] ? [
20
+ v
21
+ ] extends [anyOrNever] ? parsedKey["normalized"] : never : parsedKey["normalized"] : never;
22
+ type optionalKeyFromEntry<k extends PropertyKey, v> = preparseKey<k> extends PreparsedEntryKey<"optional", infer name> ? name : v extends OptionalPropertyDefinition ? k : never;
23
+ export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
24
+ export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
25
+ export type PreparsedKey = PreparsedEntryKey | PreparsedSpecialKey;
26
+ type normalizedKeyKind<kind extends EntryKeyKind> = kind extends "index" ? string : Key;
27
+ export type PreparsedEntryKey<kind extends EntryKeyKind = EntryKeyKind, normalized extends normalizedKeyKind<kind> = normalizedKeyKind<kind>> = {
28
+ kind: kind;
29
+ normalized: normalized;
30
+ };
31
+ export type PreparsedSpecialKey<kind extends SpecialKeyKind = SpecialKeyKind> = {
51
32
  kind: kind;
52
- key: key;
53
33
  };
54
34
  declare namespace PreparsedKey {
55
35
  type from<t extends PreparsedKey> = t;
56
36
  }
57
- type ParsedKeyKind = "required" | "optional" | "index" | MetaKey;
37
+ export type ParsedKeyKind = EntryKeyKind | SpecialKeyKind;
38
+ export type EntryKeyKind = "required" | "optional" | "index";
39
+ export type SpecialKeyKind = "spread" | "undeclared";
58
40
  export type MetaKey = "..." | "+";
59
41
  export type IndexKey<def extends string = string> = `[${def}]`;
60
- export type ParsedEntry = ParsedUndeclaredEntry | ParsedSpreadEntry | Required.Node | Optional.Node | Index.Node;
61
- export type ParsedUndeclaredEntry = {
62
- kind: "undeclared";
63
- behavior: UndeclaredKeyBehavior;
64
- };
65
- export type ParsedSpreadEntry = {
66
- kind: "spread";
67
- node: BaseRoot;
68
- };
69
- export declare const parseEntry: (key: Key, value: unknown, ctx: ParseContext) => listable<ParsedEntry>;
70
- export declare const invalidDefaultKeyKindMessage = "Only required keys may specify default values, e.g. { value: 'number = 0' }";
71
- export type invalidDefaultKeyKindMessage = typeof invalidDefaultKeyKindMessage;
72
- declare const parseKey: (key: Key) => PreparsedKey;
73
- type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeToken}` ? PreparsedKey.from<{
42
+ export declare const preparseKey: (key: Key) => PreparsedKey;
43
+ export type preparseKey<k> = k extends symbol ? PreparsedKey.from<{
74
44
  kind: "required";
75
- key: `${baseName}?`;
45
+ normalized: k;
46
+ }> : k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeChar}` ? PreparsedKey.from<{
47
+ kind: "required";
48
+ normalized: `${baseName}?`;
76
49
  }> : PreparsedKey.from<{
77
50
  kind: "optional";
78
- key: inner;
79
- }> : k extends MetaKey ? PreparsedKey.from<{
80
- kind: k;
81
- key: k;
82
- }> : k extends `${EscapeToken}${infer escapedMeta extends MetaKey}` ? PreparsedKey.from<{
51
+ normalized: inner;
52
+ }> : k extends "+" ? {
53
+ kind: "undeclared";
54
+ } : k extends "..." ? {
55
+ kind: "spread";
56
+ } : k extends `${EscapeChar}${infer escapedMeta extends MetaKey}` ? PreparsedKey.from<{
83
57
  kind: "required";
84
- key: escapedMeta;
58
+ normalized: escapedMeta;
85
59
  }> : k extends IndexKey<infer def> ? PreparsedKey.from<{
86
60
  kind: "index";
87
- key: def;
61
+ normalized: def;
88
62
  }> : PreparsedKey.from<{
89
63
  kind: "required";
90
- key: k extends `${EscapeToken}${infer escapedIndexKey extends IndexKey}` ? escapedIndexKey : k extends Key ? k : `${k & number}`;
64
+ normalized: k extends (`${EscapeChar}${infer escapedIndexKey extends IndexKey}`) ? escapedIndexKey : k extends Key ? k : `${k & number}`;
91
65
  }>;
92
66
  export declare const writeInvalidSpreadTypeMessage: <def extends string>(def: def) => writeInvalidSpreadTypeMessage<def>;
93
- type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
67
+ export type writeInvalidSpreadTypeMessage<def extends string> = `Spread operand must resolve to an object literal type (was ${def})`;
94
68
  export {};
@@ -1,6 +1,6 @@
1
- import { ArkErrors, normalizeIndex } from "@ark/schema";
2
- import { append, escapeToken, isArray, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
3
- import { writeUnassignableDefaultValueMessage } from "./semantic/default.js";
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";
4
4
  export const parseObjectLiteral = (def, ctx) => {
5
5
  let spread;
6
6
  const structure = {};
@@ -8,92 +8,105 @@ export const parseObjectLiteral = (def, ctx) => {
8
8
  // because to match JS behavior any keys before the spread are overwritten
9
9
  // by the values in the target object, so there'd be no useful purpose in having it
10
10
  // anywhere except for the beginning.
11
- const parsedEntries = stringAndSymbolicEntriesOf(def).flatMap(entry => parseEntry(entry[0], entry[1], ctx));
12
- if (parsedEntries[0]?.kind === "spread") {
13
- // remove the spread entry so we can iterate over the remaining entries
14
- // expecting non-spread entries
15
- const spreadEntry = parsedEntries.shift();
16
- if (!spreadEntry.node.hasKind("intersection") ||
17
- !spreadEntry.node.structure) {
18
- 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;
19
28
  }
20
- spread = spreadEntry.node.structure;
21
- }
22
- for (const entry of parsedEntries) {
23
- if (entry.kind === "spread")
24
- return throwParseError(nonLeadingSpreadError);
25
- if (entry.kind === "undeclared") {
26
- 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);
27
70
  continue;
28
71
  }
29
- 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);
30
79
  }
31
80
  const structureNode = ctx.$.node("structure", structure);
32
- return ctx.$.rootNode({
81
+ return ctx.$.parseSchema({
33
82
  domain: "object",
34
83
  structure: spread?.merge(structureNode) ?? structureNode
35
84
  });
36
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
+ };
37
91
  export const writeInvalidUndeclaredBehaviorMessage = (actual) => `Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${printable(actual)})`;
38
92
  export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
39
- export const parseEntry = (key, value, ctx) => {
40
- const parsedKey = parseKey(key);
41
- if (parsedKey.kind === "+") {
42
- if (value !== "reject" && value !== "delete" && value !== "ignore")
43
- throwParseError(writeInvalidUndeclaredBehaviorMessage(value));
44
- return { kind: "undeclared", behavior: value };
45
- }
46
- if (parsedKey.kind === "...")
47
- return { kind: "spread", node: ctx.$.parse(value, ctx) };
48
- const parsedValue = isArray(value) && value[1] === "=" ?
49
- [ctx.$.parse(value[0], ctx), "=", value[2]]
50
- : ctx.$.parse(value, ctx, true);
51
- if (isArray(parsedValue)) {
52
- if (parsedKey.kind !== "required")
53
- throwParseError(invalidDefaultKeyKindMessage);
54
- const out = parsedValue[0].traverse(parsedValue[2]);
55
- if (out instanceof ArkErrors) {
56
- throwParseError(writeUnassignableDefaultValueMessage(printable(parsedKey.key), out.message));
57
- }
58
- return ctx.$.node("optional", {
59
- key: parsedKey.key,
60
- value: parsedValue[0],
61
- default: parsedValue[2]
62
- });
63
- }
64
- if (parsedKey.kind === "index") {
65
- const signature = ctx.$.parse(parsedKey.key, ctx);
66
- const normalized = normalizeIndex(signature, parsedValue, ctx.$);
67
- return (normalized.index ?
68
- normalized.required ?
69
- [normalized.index, ...normalized.required]
70
- : normalized.index
71
- : (normalized.required ?? []));
72
- }
73
- return ctx.$.node(parsedKey.kind, {
74
- key: parsedKey.key,
75
- value: parsedValue
76
- });
77
- };
78
- // single quote use here is better for TypeScript's inlined error to avoid escapes
79
- export const invalidDefaultKeyKindMessage = `Only required keys may specify default values, e.g. { value: 'number = 0' }`;
80
- const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
93
+ export const preparseKey = (key) => typeof key === "symbol" ? { kind: "required", normalized: key }
81
94
  : key.at(-1) === "?" ?
82
- key.at(-2) === escapeToken ?
83
- { kind: "required", key: `${key.slice(0, -2)}?` }
95
+ key.at(-2) === escapeChar ?
96
+ { kind: "required", normalized: `${key.slice(0, -2)}?` }
84
97
  : {
85
98
  kind: "optional",
86
- key: key.slice(0, -1)
99
+ normalized: key.slice(0, -1)
87
100
  }
88
101
  : key[0] === "[" && key.at(-1) === "]" ?
89
- { kind: "index", key: key.slice(1, -1) }
90
- : key[0] === escapeToken && key[1] === "[" && key.at(-1) === "]" ?
91
- { kind: "required", key: key.slice(1) }
92
- : key === "..." ? { kind: key, key }
93
- : 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" }
94
107
  : {
95
108
  kind: "required",
96
- key: key === "\\..." ? "..."
109
+ normalized: key === "\\..." ? "..."
97
110
  : key === "\\+" ? "+"
98
111
  : key
99
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,9 +1,7 @@
1
- import type { BaseRoot } from "@ark/schema";
1
+ import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys } from "@ark/util";
3
- import type { LimitLiteral } from "../../../keywords/ast.ts";
4
- import type { ParseContext } from "../../../scope.ts";
5
- import type { InfixOperator } from "../../semantic/infer.ts";
6
- import type { Scanner } from "../shift/scanner.ts";
3
+ import type { LimitLiteral } from "../../attributes.ts";
4
+ import type { ArkTypeScanner } from "../shift/scanner.ts";
7
5
  import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
8
6
  type BranchState = {
9
7
  prefixes: StringifiablePrefixOperator[];
@@ -13,20 +11,19 @@ type BranchState = {
13
11
  };
14
12
  export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
15
13
  export declare class DynamicState {
16
- root: BaseRoot<any> | undefined;
14
+ root: BaseRoot | undefined;
17
15
  branches: BranchState;
18
- finalizer: Scanner.FinalizingLookahead | undefined;
16
+ finalizer: ArkTypeScanner.FinalizingLookahead | undefined;
19
17
  groups: BranchState[];
20
- scanner: Scanner;
21
- ctx: ParseContext;
22
- defaultable: boolean;
23
- constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
18
+ scanner: ArkTypeScanner;
19
+ ctx: BaseParseContext;
20
+ constructor(scanner: ArkTypeScanner, ctx: BaseParseContext);
24
21
  error(message: string): never;
25
22
  hasRoot(): this is DynamicStateWithRoot;
26
23
  setRoot(root: BaseRoot): void;
27
24
  unsetRoot(): this["root"];
28
25
  constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
29
- finalize(finalizer: Scanner.FinalizingLookahead): void;
26
+ finalize(finalizer: ArkTypeScanner.FinalizingLookahead): void;
30
27
  reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
31
28
  finalizeBranches(): void;
32
29
  finalizeGroup(): void;
@@ -38,7 +35,7 @@ export declare class DynamicState {
38
35
  parseOperand(): void;
39
36
  private assertRangeUnset;
40
37
  reduceGroupOpen(): void;
41
- previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined;
38
+ previousOperator(): MinComparator | StringifiablePrefixOperator | ArkTypeScanner.InfixToken | undefined;
42
39
  shiftedByOne(): this;
43
40
  }
44
41
  export {};
@@ -16,11 +16,9 @@ export class DynamicState {
16
16
  groups = [];
17
17
  scanner;
18
18
  ctx;
19
- defaultable;
20
- constructor(scanner, ctx, defaultable) {
19
+ constructor(scanner, ctx) {
21
20
  this.scanner = scanner;
22
21
  this.ctx = ctx;
23
- this.defaultable = defaultable;
24
22
  }
25
23
  error(message) {
26
24
  return throwParseError(message);
@@ -93,17 +91,18 @@ export class DynamicState {
93
91
  this.assertRangeUnset();
94
92
  this.applyPrefixes();
95
93
  const root = this.root;
96
- this.branches.intersection = this.branches.intersection?.and(root) ?? root;
94
+ this.branches.intersection =
95
+ this.branches.intersection?.rawAnd(root) ?? root;
97
96
  if (token === "|") {
98
97
  this.branches.union =
99
- this.branches.union?.or(this.branches.intersection) ??
98
+ this.branches.union?.rawOr(this.branches.intersection) ??
100
99
  this.branches.intersection;
101
100
  this.branches.intersection = null;
102
101
  }
103
102
  this.root = undefined;
104
103
  }
105
104
  parseUntilFinalizer() {
106
- return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx, false));
105
+ return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx));
107
106
  }
108
107
  parseOperator() {
109
108
  return parseOperator(this);
@@ -1,4 +1,4 @@
1
- import type { LimitLiteral } from "../../../keywords/ast.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/ast.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,9 +1,11 @@
1
- import type { DateLiteral } from "../../../../keywords/ast.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>;
5
+ type extractDateLiteralSource<literal extends DateLiteral> = literal extends DateLiteral<infer source> ? source : never;
5
6
  export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
6
7
  export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
7
8
  export type DateInput = ConstructorParameters<typeof Date>[0];
8
9
  export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
9
10
  export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
11
+ export {};
@@ -1,13 +1,13 @@
1
- import type { Date, string } from "../../../../keywords/ast.ts";
2
- import type { InferredAst } from "../../../semantic/infer.ts";
1
+ import { type Scanner } from "@ark/util";
2
+ import type { InferredAst } from "../../ast/infer.ts";
3
3
  import type { DynamicState } from "../../reduce/dynamic.ts";
4
4
  import type { StaticState, state } from "../../reduce/static.ts";
5
- import type { Scanner } from "../scanner.ts";
5
+ import type { ArkTypeScanner } from "../scanner.ts";
6
6
  export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
7
7
  export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
8
8
  export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
9
9
  export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
10
- 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;
11
11
  export declare const enclosingQuote: {
12
12
  readonly "'": 1;
13
13
  readonly '"': 1;
@@ -1,4 +1,4 @@
1
- import { isKeyOf } from "@ark/util";
1
+ import { isKeyOf, throwParseError } from "@ark/util";
2
2
  import { tryParseDate, writeInvalidDateMessage } from "./date.js";
3
3
  export const parseEnclosed = (s, enclosing) => {
4
4
  const enclosed = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
@@ -7,8 +7,12 @@ export const parseEnclosed = (s, enclosing) => {
7
7
  // Shift the scanner one additional time for the second enclosing token
8
8
  s.scanner.shift();
9
9
  if (enclosing === "/") {
10
- // fail parsing if the regex is invalid
11
- new RegExp(enclosed);
10
+ try {
11
+ new RegExp(enclosed);
12
+ }
13
+ catch (e) {
14
+ throwParseError(String(e));
15
+ }
12
16
  s.root = s.ctx.$.node("intersection", {
13
17
  domain: "string",
14
18
  pattern: enclosed
@@ -0,0 +1,9 @@
1
+ import { type WhitespaceChar } from "@ark/util";
2
+ import type { DynamicState } from "../../reduce/dynamic.ts";
3
+ import type { StaticState, state } from "../../reduce/static.ts";
4
+ import type { BaseCompletions } from "../../string.ts";
5
+ import type { ArkTypeScanner } from "../scanner.ts";
6
+ import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
7
+ import { parseUnenclosed } from "./unenclosed.ts";
8
+ export declare const parseOperand: (s: DynamicState) => void;
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()}`)