arktype 2.0.0-rc.1 → 2.0.0-rc.11

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 (141) hide show
  1. package/out/config.d.ts +1 -1
  2. package/out/generic.d.ts +47 -48
  3. package/out/generic.js +6 -8
  4. package/out/index.d.ts +4 -4
  5. package/out/index.js +2 -2
  6. package/out/keywords/builtins.js +2 -2
  7. package/out/keywords/constructors/Array.d.ts +2 -2
  8. package/out/keywords/constructors/Array.js +7 -7
  9. package/out/keywords/constructors/Date.d.ts +32 -0
  10. package/out/keywords/constructors/FormData.d.ts +2 -2
  11. package/out/keywords/constructors/FormData.js +8 -8
  12. package/out/keywords/constructors/TypedArray.js +2 -2
  13. package/out/keywords/constructors/constructors.d.ts +0 -1
  14. package/out/keywords/constructors/constructors.js +2 -2
  15. package/out/keywords/inference.d.ts +228 -0
  16. package/out/keywords/keywords.d.ts +62 -0
  17. package/out/keywords/{ark.js → keywords.js} +11 -8
  18. package/out/keywords/number/epoch.d.ts +1 -2
  19. package/out/keywords/number/epoch.js +2 -2
  20. package/out/keywords/number/integer.js +2 -2
  21. package/out/keywords/number/number.d.ts +32 -6
  22. package/out/keywords/number/number.js +17 -5
  23. package/out/keywords/string/alpha.d.ts +1 -1
  24. package/out/keywords/string/alphanumeric.d.ts +1 -1
  25. package/out/keywords/string/capitalize.d.ts +2 -2
  26. package/out/keywords/string/capitalize.js +4 -4
  27. package/out/keywords/string/creditCard.d.ts +1 -1
  28. package/out/keywords/string/creditCard.js +2 -2
  29. package/out/keywords/string/date.d.ts +4 -8
  30. package/out/keywords/string/date.js +16 -16
  31. package/out/keywords/string/digits.d.ts +1 -1
  32. package/out/keywords/string/email.d.ts +1 -1
  33. package/out/keywords/string/integer.d.ts +2 -2
  34. package/out/keywords/string/integer.js +7 -7
  35. package/out/keywords/string/ip.d.ts +2 -2
  36. package/out/keywords/string/ip.js +5 -5
  37. package/out/keywords/string/json.d.ts +3 -2
  38. package/out/keywords/string/json.js +24 -16
  39. package/out/keywords/string/lower.d.ts +2 -2
  40. package/out/keywords/string/lower.js +4 -4
  41. package/out/keywords/string/normalize.d.ts +23 -27
  42. package/out/keywords/string/normalize.js +14 -14
  43. package/out/keywords/string/numeric.d.ts +2 -2
  44. package/out/keywords/string/numeric.js +7 -7
  45. package/out/keywords/string/semver.d.ts +1 -1
  46. package/out/keywords/string/string.d.ts +39 -42
  47. package/out/keywords/string/string.js +3 -3
  48. package/out/keywords/string/trim.d.ts +2 -2
  49. package/out/keywords/string/trim.js +4 -4
  50. package/out/keywords/string/upper.d.ts +2 -2
  51. package/out/keywords/string/upper.js +4 -4
  52. package/out/keywords/string/url.d.ts +2 -2
  53. package/out/keywords/string/url.js +8 -8
  54. package/out/keywords/string/uuid.d.ts +11 -11
  55. package/out/keywords/string/uuid.js +3 -3
  56. package/out/keywords/ts.d.ts +38 -1
  57. package/out/keywords/ts.js +20 -4
  58. package/out/keywords/utils.d.ts +1 -1
  59. package/out/keywords/utils.js +1 -1
  60. package/out/{subtypes → methods}/array.d.ts +6 -6
  61. package/out/methods/base.d.ts +96 -0
  62. package/out/{subtypes → methods}/date.d.ts +5 -5
  63. package/out/{subtypes → methods}/instantiate.d.ts +5 -4
  64. package/out/methods/morph.d.ts +12 -0
  65. package/out/{subtypes → methods}/number.d.ts +6 -6
  66. package/out/methods/object.d.ts +81 -0
  67. package/out/{subtypes → methods}/string.d.ts +7 -7
  68. package/out/{subtypes → methods}/validator.d.ts +2 -2
  69. package/out/module.d.ts +2 -2
  70. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  71. package/out/parser/ast/default.d.ts +8 -0
  72. package/out/parser/{semantic → ast}/infer.d.ts +11 -11
  73. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  74. package/out/parser/{semantic → ast}/validate.d.ts +6 -6
  75. package/out/parser/definition.d.ts +8 -9
  76. package/out/parser/objectLiteral.d.ts +11 -37
  77. package/out/parser/objectLiteral.js +6 -24
  78. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
  79. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  80. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  81. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  82. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  83. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -2
  84. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  85. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
  86. package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
  87. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  88. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  89. package/out/parser/{string/shift → shift}/operator/default.js +1 -6
  90. package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
  91. package/out/parser/{string/shift → shift}/scanner.js +5 -3
  92. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  93. package/out/parser/{string/string.js → string.js} +2 -0
  94. package/out/parser/tuple.d.ts +54 -43
  95. package/out/parser/tuple.js +36 -30
  96. package/out/scope.d.ts +32 -39
  97. package/out/scope.js +43 -35
  98. package/out/type.d.ts +24 -21
  99. package/out/type.js +14 -10
  100. package/package.json +3 -3
  101. package/out/intersect.d.ts +0 -28
  102. package/out/keys.d.ts +0 -16
  103. package/out/keywords/ark.d.ts +0 -39
  104. package/out/keywords/ast.d.ts +0 -193
  105. package/out/parser/semantic/default.d.ts +0 -9
  106. package/out/parser/semantic/default.js +0 -1
  107. package/out/subtypes/base.d.ts +0 -85
  108. package/out/subtypes/morph.d.ts +0 -13
  109. package/out/subtypes/object.d.ts +0 -33
  110. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  111. /package/out/keywords/{ast.js → inference.js} +0 -0
  112. /package/out/{subtypes → methods}/array.js +0 -0
  113. /package/out/{subtypes → methods}/base.js +0 -0
  114. /package/out/{subtypes → methods}/date.js +0 -0
  115. /package/out/{subtypes → methods}/instantiate.js +0 -0
  116. /package/out/{subtypes → methods}/morph.js +0 -0
  117. /package/out/{subtypes → methods}/number.js +0 -0
  118. /package/out/{subtypes → methods}/object.js +0 -0
  119. /package/out/{subtypes → methods}/string.js +0 -0
  120. /package/out/{subtypes → methods}/validator.js +0 -0
  121. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  122. /package/out/{keys.js → parser/ast/default.js} +0 -0
  123. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  124. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  125. /package/out/parser/{semantic → ast}/infer.js +0 -0
  126. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  127. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  128. /package/out/parser/{semantic → ast}/utils.js +0 -0
  129. /package/out/parser/{semantic → ast}/validate.js +0 -0
  130. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  131. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  132. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  133. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  134. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  135. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  136. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  137. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  138. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  139. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
  140. /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
  141. /package/out/parser/{string/shift → shift}/operator/operator.js +0 -0
@@ -1,17 +1,17 @@
1
1
  import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
2
2
  import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
3
3
  import type { Generic } from "../../generic.ts";
4
- import type { Comparator } from "../string/reduce/shared.ts";
5
- import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.ts";
6
- import type { UnitLiteral } from "../string/shift/operator/default.ts";
7
- import type { parseString } from "../string/string.ts";
4
+ import type { Comparator } from "../reduce/shared.ts";
5
+ import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
6
+ import type { UnitLiteral } from "../shift/operator/default.ts";
7
+ import type { parseString } from "../string.ts";
8
8
  import type { validateRange } from "./bounds.ts";
9
9
  import type { validateDefault } from "./default.ts";
10
10
  import type { validateDivisor } from "./divisor.ts";
11
11
  import type { DefAst, GenericInstantiationAst, inferAstRoot, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
12
12
  import type { validateKeyof } from "./keyof.ts";
13
13
  import type { astToString } from "./utils.ts";
14
- export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : undefined : ast extends [infer baseAst, "=", infer unitLiteral extends UnitLiteral] ? validateDefault<baseAst, unitLiteral, $, args> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
14
+ export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : operator extends "?" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : never : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
15
15
  ast: ast;
16
16
  };
17
17
  type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
@@ -20,7 +20,7 @@ export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateD
20
20
  export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
21
21
  type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends {
22
22
  [arkKind]: "module";
23
- } ? "$root" extends keyof inferred ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : def extends ErrorMessage ? def : undefined;
23
+ } ? "root" extends keyof inferred ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : def extends ErrorMessage ? def : undefined;
24
24
  export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
25
25
  type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends infer e extends ErrorMessage ? e : validateAst<ast[2], $, args> extends infer e extends ErrorMessage ? e : undefined;
26
26
  export {};
@@ -1,17 +1,16 @@
1
- import { type BaseRoot } from "@ark/schema";
1
+ import { type BaseParseContext, type BaseRoot } from "@ark/schema";
2
2
  import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
3
- import type { type } from "../keywords/ark.ts";
3
+ import type { type } from "../keywords/keywords.ts";
4
4
  import type { string } from "../keywords/string/string.ts";
5
- import type { ParseContext } from "../scope.ts";
5
+ import type { validateString } from "./ast/validate.ts";
6
6
  import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
7
- import type { validateString } from "./semantic/validate.ts";
8
- import type { BaseCompletions, inferString } from "./string/string.ts";
7
+ import type { BaseCompletions, inferString } from "./string.ts";
9
8
  import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.ts";
10
- export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
9
+ export declare const parseObject: (def: object, ctx: BaseParseContext) => BaseRoot;
11
10
  export type inferDefinition<def, $, args> = [
12
11
  def
13
- ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<t, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
14
- export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
12
+ ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
13
+ export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : RegExp extends def ? def : validateObjectLiteral<def, $, args>;
15
14
  export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
16
15
  type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
17
16
  [i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
@@ -25,7 +24,7 @@ type declarationMismatch<def, declared, $, args> = {
25
24
  declared: declared;
26
25
  inferred: inferDefinition<def, $, args>;
27
26
  };
28
- type Terminal = RegExp | type.cast<unknown> | Fn;
27
+ type Terminal = type.cast<unknown> | Fn;
29
28
  export type ThunkCast<t = unknown> = () => type.cast<t>;
30
29
  type BadDefinitionType = Exclude<Primitive, string>;
31
30
  export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
@@ -1,11 +1,10 @@
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";
1
+ import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
2
+ import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
3
+ import type { constrain } from "../keywords/inference.ts";
4
+ import type { astToString } from "./ast/utils.ts";
5
+ import type { validateString } from "./ast/validate.ts";
5
6
  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;
7
+ export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
9
8
  export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
10
9
  export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
11
10
  export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
@@ -13,41 +12,18 @@ export type inferObjectLiteral<def extends object, $, args> = show<"..." extends
13
12
  * Infers the contents of an object literal, ignoring a spread definition
14
13
  */
15
14
  type _inferObjectLiteral<def extends object, $, args> = {
16
- -readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (DefaultValueTuple<infer baseDef, infer defaultValue>) ? [
15
+ -readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: [
17
16
  def[k]
18
- ] extends [anyOrNever] ? def[k] : (In?: inferDefinition<baseDef, $, args>) => Default<defaultValue> : inferDefinition<def[k], $, args>;
17
+ ] extends [anyOrNever] ? def[k] : inferDefinition<def[k], $, args>;
19
18
  } & {
20
19
  -readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
21
20
  };
22
21
  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>;
22
+ [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 : validateDefinition<def[k], $, args>;
24
23
  };
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
24
  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
25
  type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
50
- type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
26
+ export type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
51
27
  kind: kind;
52
28
  key: key;
53
29
  };
@@ -66,9 +42,7 @@ export type ParsedSpreadEntry = {
66
42
  kind: "spread";
67
43
  node: BaseRoot;
68
44
  };
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;
45
+ export declare const parseEntry: (key: Key, value: unknown, ctx: BaseParseContext) => listable<ParsedEntry>;
72
46
  declare const parseKey: (key: Key) => PreparsedKey;
73
47
  type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeToken}` ? PreparsedKey.from<{
74
48
  kind: "required";
@@ -1,6 +1,5 @@
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 { normalizeIndex } from "@ark/schema";
2
+ import { append, escapeToken, printable, stringAndSymbolicEntriesOf, throwParseError } from "@ark/util";
4
3
  export const parseObjectLiteral = (def, ctx) => {
5
4
  let spread;
6
5
  const structure = {};
@@ -29,7 +28,7 @@ export const parseObjectLiteral = (def, ctx) => {
29
28
  structure[entry.kind] = append(structure[entry.kind], entry);
30
29
  }
31
30
  const structureNode = ctx.$.node("structure", structure);
32
- return ctx.$.rootNode({
31
+ return ctx.$.parseSchema({
33
32
  domain: "object",
34
33
  structure: spread?.merge(structureNode) ?? structureNode
35
34
  });
@@ -44,25 +43,10 @@ export const parseEntry = (key, value, ctx) => {
44
43
  return { kind: "undeclared", behavior: value };
45
44
  }
46
45
  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
- }
46
+ return { kind: "spread", node: ctx.$.parseOwnDefinitionFormat(value, ctx) };
47
+ const parsedValue = ctx.$.parseOwnDefinitionFormat(value, ctx);
64
48
  if (parsedKey.kind === "index") {
65
- const signature = ctx.$.parse(parsedKey.key, ctx);
49
+ const signature = ctx.$.parseOwnDefinitionFormat(parsedKey.key, ctx);
66
50
  const normalized = normalizeIndex(signature, parsedValue, ctx.$);
67
51
  return (normalized.index ?
68
52
  normalized.required ?
@@ -75,8 +59,6 @@ export const parseEntry = (key, value, ctx) => {
75
59
  value: parsedValue
76
60
  });
77
61
  };
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
62
  const parseKey = (key) => typeof key === "symbol" ? { kind: "required", key }
81
63
  : key.at(-1) === "?" ?
82
64
  key.at(-2) === escapeToken ?
@@ -1,8 +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";
3
+ import type { LimitLiteral } from "../../keywords/inference.ts";
4
+ import type { InfixOperator } from "../ast/infer.ts";
6
5
  import type { Scanner } from "../shift/scanner.ts";
7
6
  import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
8
7
  type BranchState = {
@@ -18,9 +17,8 @@ export declare class DynamicState {
18
17
  finalizer: Scanner.FinalizingLookahead | undefined;
19
18
  groups: BranchState[];
20
19
  scanner: Scanner;
21
- ctx: ParseContext;
22
- defaultable: boolean;
23
- constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
20
+ ctx: BaseParseContext;
21
+ constructor(scanner: Scanner, ctx: BaseParseContext);
24
22
  error(message: string): never;
25
23
  hasRoot(): this is DynamicStateWithRoot;
26
24
  setRoot(root: BaseRoot): void;
@@ -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 "../../keywords/inference.ts";
2
2
  export type StringifiablePrefixOperator = "keyof";
3
3
  export declare const minComparators: {
4
4
  readonly ">": true;
@@ -1,5 +1,5 @@
1
1
  import type { Completion, ErrorMessage, defined } from "@ark/util";
2
- import type { LimitLiteral } from "../../../keywords/ast.ts";
2
+ import type { LimitLiteral } from "../../keywords/inference.ts";
3
3
  import type { Scanner } 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 = {
@@ -1,9 +1,11 @@
1
- import type { DateLiteral } from "../../../../keywords/ast.ts";
1
+ import type { DateLiteral } from "../../../keywords/inference.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,5 +1,6 @@
1
- import type { Date, string } from "../../../../keywords/ast.ts";
2
- import type { InferredAst } from "../../../semantic/infer.ts";
1
+ import type { Date } from "../../../keywords/constructors/Date.ts";
2
+ import type { string } from "../../../keywords/inference.ts";
3
+ import type { InferredAst } from "../../ast/infer.ts";
3
4
  import type { DynamicState } from "../../reduce/dynamic.ts";
4
5
  import type { StaticState, state } from "../../reduce/static.ts";
5
6
  import type { Scanner } from "../scanner.ts";
@@ -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
@@ -1,8 +1,8 @@
1
1
  import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type writeNonSubmoduleDotMessage } from "@ark/schema";
2
2
  import { type BigintLiteral, type NumberLiteral, type join, type lastOf } from "@ark/util";
3
- import type { ArkAmbient } from "../../../../config.ts";
4
- import type { resolutionToAst } from "../../../../scope.ts";
5
- import type { GenericInstantiationAst, InferredAst } from "../../../semantic/infer.ts";
3
+ import type { ArkAmbient } from "../../../config.ts";
4
+ import type { resolutionToAst } from "../../../scope.ts";
5
+ import type { GenericInstantiationAst, InferredAst } from "../../ast/infer.ts";
6
6
  import type { DynamicState } from "../../reduce/dynamic.ts";
7
7
  import type { StaticState, state } from "../../reduce/static.ts";
8
8
  import type { BaseCompletions } from "../../string.ts";
@@ -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();
@@ -24,8 +24,12 @@ const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
24
24
  writePrefixedPrivateReferenceMessage(token)
25
25
  : writeUnresolvableMessage(token));
26
26
  const maybeParseReference = (s, token) => {
27
- if (s.ctx.args?.[token])
28
- return s.ctx.args[token].internal;
27
+ if (s.ctx.args?.[token]) {
28
+ const arg = s.ctx.args[token];
29
+ if (typeof arg !== "string")
30
+ return arg;
31
+ return s.ctx.$.node("alias", { reference: arg }, { prereduced: true });
32
+ }
29
33
  const resolution = s.ctx.$.maybeResolve(token);
30
34
  if (hasArkKind(resolution, "root"))
31
35
  return resolution;
@@ -1,8 +1,8 @@
1
1
  import { type BaseRoot, type BoundKind } from "@ark/schema";
2
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";
3
+ import type { DateLiteral } from "../../../keywords/inference.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";
@@ -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 "../../../keywords/inference.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,6 @@ 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
+ return baseNode.default(defaultNode.unit);
15
11
  };
16
12
  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' }`;
@@ -34,19 +34,21 @@ export declare class Scanner<lookahead extends string = string> {
34
34
  readonly "%": true;
35
35
  readonly ",": true;
36
36
  readonly ":": true;
37
+ readonly "?": true;
37
38
  };
38
39
  static finalizingLookaheads: {
39
40
  readonly ">": true;
40
41
  readonly ",": true;
41
42
  readonly "": true;
42
43
  readonly "=": true;
44
+ readonly "?": true;
43
45
  };
44
46
  static lookaheadIsTerminator: Scanner.UntilCondition;
45
47
  static lookaheadIsNotWhitespace: Scanner.UntilCondition;
46
48
  static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
47
49
  }
48
50
  export declare namespace Scanner {
49
- type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," ? true : false;
51
+ type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," | "?" ? true : false;
50
52
  type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
51
53
  type OnInputEndFn = (scanner: Scanner, shifted: string) => string;
52
54
  type ShiftUntilOptions = {
@@ -74,13 +74,15 @@ export class Scanner {
74
74
  "%": true,
75
75
  ",": true,
76
76
  ":": true,
77
+ "?": true,
77
78
  ...whiteSpaceTokens
78
79
  };
79
80
  static finalizingLookaheads = {
80
81
  ">": true,
81
82
  ",": true,
82
83
  "": true,
83
- "=": true
84
+ "=": true,
85
+ "?": true
84
86
  };
85
87
  static lookaheadIsTerminator = (scanner) => scanner.lookahead in this.terminatingChars;
86
88
  static lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in whiteSpaceTokens);
@@ -95,6 +97,6 @@ export class Scanner {
95
97
  // "=" is a finalizer on its own (representing a default value),
96
98
  // but not with a second "=" (an equality comparator)
97
99
  : lookahead === "=" ? unscanned[0] !== "="
98
- // ","" is unambiguously a finalizer
99
- : lookahead === ",";
100
+ // "," and "?" are unambiguously finalizers
101
+ : lookahead === "," || lookahead === "?";
100
102
  }
@@ -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