@thomasfosterau/effect-parse 0.4.1 → 0.6.0

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 (157) hide show
  1. package/CHANGELOG.md +202 -0
  2. package/README.md +56 -14
  3. package/dist/Ascii.d.ts +11 -4
  4. package/dist/Ascii.d.ts.map +1 -1
  5. package/dist/Ascii.js +12 -4
  6. package/dist/Ascii.js.map +1 -1
  7. package/dist/Binary.d.ts +5 -2
  8. package/dist/Binary.d.ts.map +1 -1
  9. package/dist/Binary.js +83 -37
  10. package/dist/Binary.js.map +1 -1
  11. package/dist/Bits.d.ts.map +1 -1
  12. package/dist/Bits.js +11 -4
  13. package/dist/Bits.js.map +1 -1
  14. package/dist/Compiler.d.ts +74 -2
  15. package/dist/Compiler.d.ts.map +1 -1
  16. package/dist/Compiler.js +78 -1
  17. package/dist/Compiler.js.map +1 -1
  18. package/dist/Expression.d.ts.map +1 -1
  19. package/dist/Expression.js +86 -74
  20. package/dist/Expression.js.map +1 -1
  21. package/dist/Input.d.ts +56 -5
  22. package/dist/Input.d.ts.map +1 -1
  23. package/dist/Input.js +70 -1
  24. package/dist/Input.js.map +1 -1
  25. package/dist/Nom.d.ts +5 -15
  26. package/dist/Nom.d.ts.map +1 -1
  27. package/dist/Nom.js.map +1 -1
  28. package/dist/ParseError.d.ts +69 -11
  29. package/dist/ParseError.d.ts.map +1 -1
  30. package/dist/ParseError.js +129 -28
  31. package/dist/ParseError.js.map +1 -1
  32. package/dist/Parser.d.ts +375 -29
  33. package/dist/Parser.d.ts.map +1 -1
  34. package/dist/Parser.js +394 -37
  35. package/dist/Parser.js.map +1 -1
  36. package/dist/ParserSchema.d.ts.map +1 -1
  37. package/dist/ParserSchema.js +2 -3
  38. package/dist/ParserSchema.js.map +1 -1
  39. package/dist/ParserStream.d.ts +122 -14
  40. package/dist/ParserStream.d.ts.map +1 -1
  41. package/dist/ParserStream.js +293 -62
  42. package/dist/ParserStream.js.map +1 -1
  43. package/dist/Syntax.d.ts +23 -5
  44. package/dist/Syntax.d.ts.map +1 -1
  45. package/dist/Syntax.js +1 -1
  46. package/dist/Syntax.js.map +1 -1
  47. package/dist/Text.d.ts.map +1 -1
  48. package/dist/Text.js +21 -15
  49. package/dist/Text.js.map +1 -1
  50. package/dist/Token.d.ts +65 -11
  51. package/dist/Token.d.ts.map +1 -1
  52. package/dist/Token.js +73 -26
  53. package/dist/Token.js.map +1 -1
  54. package/dist/internal/compiler/closure.d.ts +1 -1
  55. package/dist/internal/compiler/closure.d.ts.map +1 -1
  56. package/dist/internal/compiler/closure.js +263 -113
  57. package/dist/internal/compiler/closure.js.map +1 -1
  58. package/dist/internal/compiler/entries.d.ts +3 -1
  59. package/dist/internal/compiler/entries.d.ts.map +1 -1
  60. package/dist/internal/compiler/entries.js +3 -2
  61. package/dist/internal/compiler/entries.js.map +1 -1
  62. package/dist/internal/compiler/first.d.ts.map +1 -1
  63. package/dist/internal/compiler/first.js +9 -2
  64. package/dist/internal/compiler/first.js.map +1 -1
  65. package/dist/internal/compiler/graph.d.ts +39 -0
  66. package/dist/internal/compiler/graph.d.ts.map +1 -0
  67. package/dist/internal/compiler/graph.js +78 -0
  68. package/dist/internal/compiler/graph.js.map +1 -0
  69. package/dist/internal/compiler/jit.d.ts +5 -0
  70. package/dist/internal/compiler/jit.d.ts.map +1 -1
  71. package/dist/internal/compiler/jit.js +208 -106
  72. package/dist/internal/compiler/jit.js.map +1 -1
  73. package/dist/internal/compiler/registry.d.ts +11 -3
  74. package/dist/internal/compiler/registry.d.ts.map +1 -1
  75. package/dist/internal/compiler/registry.js.map +1 -1
  76. package/dist/internal/compiler/search.d.ts +32 -0
  77. package/dist/internal/compiler/search.d.ts.map +1 -0
  78. package/dist/internal/compiler/search.js +68 -0
  79. package/dist/internal/compiler/search.js.map +1 -0
  80. package/dist/internal/compiler/sets.d.ts.map +1 -1
  81. package/dist/internal/compiler/sets.js +1 -1
  82. package/dist/internal/compiler/sets.js.map +1 -1
  83. package/dist/internal/compiler/wasm.d.ts +8 -0
  84. package/dist/internal/compiler/wasm.d.ts.map +1 -0
  85. package/dist/internal/compiler/wasm.js +2840 -0
  86. package/dist/internal/compiler/wasm.js.map +1 -0
  87. package/dist/internal/compiler/wasmAsm.d.ts +199 -0
  88. package/dist/internal/compiler/wasmAsm.d.ts.map +1 -0
  89. package/dist/internal/compiler/wasmAsm.js +427 -0
  90. package/dist/internal/compiler/wasmAsm.js.map +1 -0
  91. package/dist/internal/entries.d.ts +3 -1
  92. package/dist/internal/entries.d.ts.map +1 -1
  93. package/dist/internal/entries.js.map +1 -1
  94. package/dist/internal/node.d.ts +77 -3
  95. package/dist/internal/node.d.ts.map +1 -1
  96. package/dist/internal/node.js +54 -10
  97. package/dist/internal/node.js.map +1 -1
  98. package/dist/internal/numbers.d.ts.map +1 -1
  99. package/dist/internal/numbers.js.map +1 -1
  100. package/dist/internal/run.d.ts +14 -0
  101. package/dist/internal/run.d.ts.map +1 -1
  102. package/dist/internal/run.js +53 -11
  103. package/dist/internal/run.js.map +1 -1
  104. package/dist/internal/stack.d.ts +14 -0
  105. package/dist/internal/stack.d.ts.map +1 -1
  106. package/dist/internal/stack.js +24 -2
  107. package/dist/internal/stack.js.map +1 -1
  108. package/dist/internal/syntax.d.ts +4 -4
  109. package/dist/internal/syntax.d.ts.map +1 -1
  110. package/dist/internal/syntax.js +18 -10
  111. package/dist/internal/syntax.js.map +1 -1
  112. package/dist/internal/text.d.ts +32 -0
  113. package/dist/internal/text.d.ts.map +1 -1
  114. package/dist/internal/text.js +68 -14
  115. package/dist/internal/text.js.map +1 -1
  116. package/dist/internal/tokens.d.ts +20 -0
  117. package/dist/internal/tokens.d.ts.map +1 -1
  118. package/dist/internal/tokens.js +72 -39
  119. package/dist/internal/tokens.js.map +1 -1
  120. package/dist/internal/tuple.d.ts +6 -0
  121. package/dist/internal/tuple.d.ts.map +1 -0
  122. package/dist/internal/tuple.js +170 -0
  123. package/dist/internal/tuple.js.map +1 -0
  124. package/package.json +18 -10
  125. package/src/Ascii.ts +47 -12
  126. package/src/Binary.ts +174 -73
  127. package/src/Bits.ts +16 -6
  128. package/src/Compiler.ts +101 -10
  129. package/src/Expression.ts +94 -81
  130. package/src/Input.ts +99 -7
  131. package/src/Nom.ts +15 -5
  132. package/src/ParseError.ts +209 -52
  133. package/src/Parser.ts +684 -143
  134. package/src/ParserSchema.ts +1 -2
  135. package/src/ParserStream.ts +361 -68
  136. package/src/Syntax.ts +60 -36
  137. package/src/Text.ts +32 -27
  138. package/src/Token.ts +152 -34
  139. package/src/internal/compiler/closure.ts +371 -153
  140. package/src/internal/compiler/entries.ts +4 -2
  141. package/src/internal/compiler/first.ts +16 -0
  142. package/src/internal/compiler/graph.ts +96 -0
  143. package/src/internal/compiler/jit.ts +319 -169
  144. package/src/internal/compiler/registry.ts +10 -2
  145. package/src/internal/compiler/search.ts +68 -0
  146. package/src/internal/compiler/sets.ts +7 -3
  147. package/src/internal/compiler/wasm.ts +3276 -0
  148. package/src/internal/compiler/wasmAsm.ts +484 -0
  149. package/src/internal/entries.ts +8 -2
  150. package/src/internal/node.ts +103 -7
  151. package/src/internal/numbers.ts +3 -1
  152. package/src/internal/run.ts +73 -12
  153. package/src/internal/stack.ts +25 -1
  154. package/src/internal/syntax.ts +39 -18
  155. package/src/internal/text.ts +97 -9
  156. package/src/internal/tokens.ts +106 -14
  157. package/src/internal/tuple.ts +141 -0
@@ -1 +1 @@
1
- {"version":3,"file":"ParserSchema.d.ts","names":[],"sources":["../src/ParserSchema.ts"],"mappings":";;;;;;;;;;;qBA4Da;;YAGD;cACE;;;;;;gBAME,iBAAiB;;;;;;;;;;iBAWhB,QAAQ;;WAEd,WAAW,OAAO;;WAElB;;;;;;;;iBASM,aAAa,WAAW,OAAO,SAAS,OAAO,QAAQ,IAAI,OAAO;;;;;;;;qBA0CtE,OAAQ,GAAG,GAAG,QAAQ,OAAO,GAAG,mBAAmB,UAAU,QAAQ,OAAK,aAAa;;;;;;;;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C;GAEV,WACC,YAAY,WAAW,MACrB,UAAU,OAAO,KAAK,MAAM,MAAM,YAAY,kCAAkC;GACnF,UAAU,OAAO,KAAK,MAAM,GAAG,YAAY,WAAW,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAsDzD,WAAY,UAAU,OAAO,4BACxC,QAAQ,MACP,OAAO,WAAW,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAmCf,YAAa,UAAU,OAAO,mDACzC,QAAQ,QACL,OAAO,cAAc,OAAO,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;;;;;qBAmC1C,aAAc,UAAU,OAAO,kDAAkD,OAAO,KACnG,QAAQ,GACR;WAAqB,WAAW,OAAO;MACtC,OAAO,SAAS,OAAO,OAAO,IAAI,OAAO"}
@@ -8,10 +8,10 @@ import * as Arr from "effect/Array";
8
8
  import * as Ascii from "./Ascii.js";
9
9
  import * as Effect from "effect/Effect";
10
10
  import { dual } from "effect/Function";
11
+ import * as Record from "effect/Record";
11
12
  import * as Match from "effect/Match";
12
13
  import * as MutableHashMap from "effect/MutableHashMap";
13
14
  import * as Order from "effect/Order";
14
- import * as Record from "effect/Record";
15
15
  import * as Schema from "effect/Schema";
16
16
  import * as SchemaAST from "effect/SchemaAST";
17
17
  import * as SchemaIssue from "effect/SchemaIssue";
@@ -66,8 +66,7 @@ const decodeWith = (target, parser, encode) => Schema.String.pipe(Schema.decodeT
66
66
  },
67
67
  encode: (value, parseOptions) => {
68
68
  if (encode === void 0) return Effect.fail(new SchemaIssue.Forbidden({ message: "Encoding is not supported" }, value, parseOptions));
69
- const result = encode(value);
70
- return Result.isSuccess(result) ? Effect.succeed(result.success) : Effect.fail(result.failure);
69
+ return Effect.fromResult(encode(value));
71
70
  }
72
71
  })));
73
72
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ParserSchema.js","names":[],"sources":["../src/ParserSchema.ts"],"sourcesContent":["/**\n * Effect `Schema`s and parsers, in both directions.\n *\n * {@link make} turns a parser over strings into a schema that decodes a\n * `string` into the parser's output. Parse errors become schema issues\n * carrying the rendered `ParseError` message. Encoding needs a printer,\n * supplied as `encode`; without one, encoding is forbidden.\n *\n * {@link toParser} goes the other way: it derives a parser from a schema,\n * guided by annotations ({@link annotate}) that say how each part is\n * written. {@link toPrinter} derives the printer that writes that text, and\n * {@link fromSchema} wraps both as a schema.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { Ascii, Parser, ParserSchema, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const Version = ParserSchema.make(\n * Parser.struct({\n * major: Ascii.decUint,\n * minor: Parser.preceded(Token.literal(\".\"), Ascii.decUint)\n * }),\n * { encode: ({ major, minor }) => `${major}.${minor}` }\n * )\n *\n * Schema.decodeUnknownSync(Version)(\"1.2\") // { major: 1, minor: 2 }\n * Schema.encodeSync(Version)({ major: 3, minor: 4 }) // \"3.4\"\n * ```\n *\n * @since 0.1.0\n */\nimport * as Arr from \"effect/Array\"\nimport * as Effect from \"effect/Effect\"\nimport { dual } from \"effect/Function\"\nimport * as Match from \"effect/Match\"\nimport * as MutableHashMap from \"effect/MutableHashMap\"\nimport * as Option from \"effect/Option\"\nimport * as Order from \"effect/Order\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Record from \"effect/Record\"\nimport * as Result from \"effect/Result\"\nimport * as Schema from \"effect/Schema\"\nimport * as SchemaAST from \"effect/SchemaAST\"\nimport * as SchemaIssue from \"effect/SchemaIssue\"\nimport * as SchemaTransformation from \"effect/SchemaTransformation\"\nimport * as Ascii from \"./Ascii.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\nimport { describeLiteral } from \"./internal/tokens.js\"\n\n/**\n * The key of the annotation that says how a schema is written as text\n * ({@link Annotation}), namespaced to this package so it cannot collide with\n * another library's. {@link annotate} sets it.\n *\n * @since 0.3.0\n * @category annotations\n */\nexport const annotationKey = \"@thomasfosterau/effect-parse/ParserSchema\" as const\n\ndeclare module \"effect/Schema\" {\n namespace Annotations {\n interface Annotations {\n /**\n * How the schema is written as text, read by `ParserSchema.toParser`\n * and `ParserSchema.toPrinter`: a parser for the schema's type, or a\n * `ParserSchema.Grammar`.\n */\n readonly [annotationKey]?: Annotation<any> | undefined\n }\n }\n}\n\n/**\n * Options for {@link make}.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface Options<A> {\n /** Prints a value back to a string. Without it, encoding fails. */\n readonly encode?: ((value: A) => string) | undefined\n /** A description of the decoded type, used by schema tooling. */\n readonly description?: string | undefined\n}\n\n/**\n * A schema decoding strings with a parser.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface ParserSchema<A> extends Schema.decodeTo<Schema.declare<A>, Schema.String> {}\n\ntype Encode<A> = (value: A) => Result.Result<string, SchemaIssue.Issue>\n\nconst encodeWith =\n <A>(encode: (value: A) => string): Encode<A> =>\n (value) =>\n Result.succeed(encode(value))\n\nconst decodeWith = <T extends Schema.Top>(\n target: T,\n parser: Parser<T[\"Encoded\"], unknown, never, string>,\n encode: Encode<T[\"Encoded\"]> | undefined\n) =>\n Schema.String.pipe(\n Schema.decodeTo(\n target,\n SchemaTransformation.transformEffect<T[\"Encoded\"], string>({\n decode: (input, parseOptions) => {\n const result = P.parse(parser, input)\n return Result.isSuccess(result)\n ? Effect.succeed(result.success)\n : Effect.fail(new SchemaIssue.InvalidValue({ message: result.failure.message }, input, parseOptions))\n },\n encode: (value, parseOptions) => {\n if (encode === undefined) {\n return Effect.fail(new SchemaIssue.Forbidden({ message: \"Encoding is not supported\" }, value, parseOptions))\n }\n const result = encode(value)\n return Result.isSuccess(result) ? Effect.succeed(result.success) : Effect.fail(result.failure)\n }\n })\n )\n )\n\n/**\n * Creates a schema that decodes a string with `parser`, which must consume\n * the whole string.\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const make = <A, E>(parser: Parser<A, E, never, string>, options?: Options<A>): ParserSchema<A> =>\n decodeWith(\n Schema.declare<A>(\n (_u): _u is A => true,\n options?.description !== undefined ? { description: options.description } : undefined\n ),\n parser,\n options?.encode === undefined ? undefined : encodeWith(options.encode)\n )\n\n// -----------------------------------------------------------------------------\n// Deriving parsers and printers from schemas\n// -----------------------------------------------------------------------------\n\n/**\n * How a schema is written as text, given in its annotation (see\n * {@link annotate}) and read by {@link toParser} and {@link toPrinter}.\n * Every field is optional; a schema without one is written as described on\n * {@link toParser}.\n *\n * @since 0.3.0\n * @category models\n */\nexport interface Grammar<A = unknown> {\n /**\n * Parses the schema's type outright, replacing what {@link toParser} would\n * derive. Its output is still validated against the schema's type and\n * checks, and its failures' causes become `SchemaError`s with their message.\n * Give a {@link Grammar.print} with it, or the schema cannot be printed.\n */\n readonly parser?: Parser<A, unknown, never, string> | undefined\n /** Writes a value as the text {@link Grammar.parser} reads, replacing what {@link toPrinter} would derive. */\n readonly print?: ((value: A) => string) | undefined\n /** Text written before the value. */\n readonly prefix?: string | undefined\n /** Text written after the value. */\n readonly suffix?: string | undefined\n /** Text written between the fields of a struct, the elements of a tuple or array, or the entries of a record. */\n readonly separator?: string | undefined\n /**\n * Text written between a key and its value. On a struct, it writes each\n * field as `key`, separator, value, in any order; records always need one.\n */\n readonly keySeparator?: string | undefined\n /**\n * Whether whitespace may surround the text this schema writes (its prefix,\n * suffix and separators), and whitespace around unannotated strings is\n * trimmed. Inherited by the schemas inside it. Printers write no\n * whitespace.\n */\n readonly whitespace?: boolean | undefined\n}\n\n/**\n * The value of the annotation under {@link annotationKey}: a\n * {@link Grammar}, or a parser for the schema's type (short for\n * `{ parser }`, which cannot be printed).\n *\n * @since 0.3.0\n * @category models\n */\nexport type Annotation<A = unknown> = Grammar<A> | Parser<A, unknown, never, string>\n\n/**\n * Annotates a schema with how it is written as text, for {@link toParser}\n * and {@link toPrinter}. The same as\n * `schema.annotate({ [ParserSchema.annotationKey]: annotation })`, except\n * that the parser's output must have the schema's type.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Point = Schema.Struct({ x: Schema.Int, y: Schema.Int }).pipe(\n * ParserSchema.annotate({ prefix: \"(\", separator: \",\", suffix: \")\" })\n * )\n * ```\n *\n * @since 0.3.0\n * @category annotations\n */\nexport const annotate: {\n // A grammar without a parser constrains nothing\n <A = never>(\n annotation: Annotation<A>\n ): <S extends Schema.Top>(self: S & ([A] extends [S[\"Type\"]] ? unknown : never)) => S[\"Rebuild\"]\n <S extends Schema.Top>(self: S, annotation: Annotation<S[\"Type\"]>): S[\"Rebuild\"]\n} = /*#__PURE__*/ dual(2, <S extends Schema.Top>(self: S, annotation: Annotation<S[\"Type\"]>): S[\"Rebuild\"] =>\n self.annotate({ [annotationKey]: annotation })\n)\n\n/**\n * Derives a parser from a schema. The parser reads the text the schema's\n * annotations ({@link Grammar}) describe and returns a value of the schema's\n * type, which the schema's checks and transformations have already\n * validated; their failures become parse errors whose `cause` is the\n * `SchemaError`.\n *\n * Without an annotation, a schema is parsed as follows:\n *\n * - `String`: one or more characters up to the next separator, key\n * separator, suffix or literal around it (to the end of the input at the\n * top level).\n * - `Number`: a decimal number (`Ascii.float`), or a decimal integer when\n * the schema checks `isInt` (as `Schema.Int` does). `BigInt`: a decimal\n * integer. `Boolean`: `true` or `false`. `Null`: `null`. `Undefined` and\n * `Void`: nothing.\n * - `Literal`, `Enum` and `TemplateLiteral`: their text.\n * - `Struct` and `Tuple`: their fields or elements in order, between\n * separators; an optional one may be left out along with its separator.\n * `Array`: elements between separators.\n * - `Record`, and `Struct` with a `keySeparator`: `key`, key separator,\n * value entries in any order, between separators.\n * - `Union`: the first member that parses, in order (literals longest\n * first). `suspend`: recursion.\n * - A transformation (a `Class`, `NumberFromString`, ...): its encoded side,\n * decoded by the schema. A grammar on it with a separator applies to the\n * encoded side.\n *\n * A parser that fails where the schema starts reports the schema's\n * `identifier` annotation (or its `expected` annotation, unless that belongs\n * to a check) as what it expected. Other declarations, `Unknown`, `Any`,\n * symbols and `object` need a parser in their annotation; without one,\n * `toParser` throws. Transformations must decode synchronously.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { Parser, ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Version = Schema.Struct({ major: Schema.Int, minor: Schema.Int }).pipe(\n * ParserSchema.annotate({ separator: \".\" })\n * )\n *\n * Parser.parse(ParserSchema.toParser(Version), \"1.2\") // Result.succeed({ major: 1, minor: 2 })\n * ```\n *\n * @since 0.3.0\n * @category derivation\n */\nexport const toParser = <S extends Schema.ConstraintDecoder<unknown>>(\n schema: S\n): Parser<S[\"Type\"], Schema.SchemaError, never, string> => {\n const ast = schema.ast\n const parser = derive(ast, initial<AnyParser>())\n return grammarOf(ast).whitespace === true ? P.delimited(Ascii.multispace0, parser, Ascii.multispace0) : parser\n}\n\n/**\n * Derives a printer from a schema: it writes a value of the schema's type as\n * the text {@link toParser} reads, following the same annotations, with no\n * optional whitespace. Transformations encode the value first, and a\n * {@link Grammar.print} replaces the derived printer.\n *\n * The printer fails with a `SchemaError` when the value is not of the\n * schema's type, or cannot be written so that it reads back: a string that\n * is empty or contains a character that would end it (a separator, a\n * suffix), or a part annotated with a parser but no `print`. Where the\n * grammar is ambiguous (an optional field followed by a field of the same\n * type), the text can still read back as a different value;\n * {@link fromSchema} checks that it doesn't.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Version = Schema.Struct({ major: Schema.Int, minor: Schema.Int }).pipe(\n * ParserSchema.annotate({ separator: \".\" })\n * )\n *\n * ParserSchema.toPrinter(Version)({ major: 1, minor: 2 }) // Result.succeed(\"1.2\")\n * ```\n *\n * @since 0.3.0\n * @category derivation\n */\nexport const toPrinter = <S extends Schema.ConstraintCodec<unknown, unknown, unknown, never>>(\n schema: S\n): ((value: S[\"Type\"]) => Result.Result<string, Schema.SchemaError>) => {\n const validate = typeDecoder(schema.ast)\n const print = printerOf(schema.ast, initial<Printer>())\n return (value) => {\n const valid = validate(value)\n if (Result.isFailure(valid)) return Result.fail(valid.failure)\n const out: Array<string> = []\n const issue = print(valid.success, out)\n return issue === undefined ? Result.succeed(out.join(\"\")) : Result.fail(schemaError(issue))\n }\n}\n\n/**\n * Creates a schema that decodes a string with the parser {@link toParser}\n * derives from `schema`, into `schema`'s type, and encodes with the printer\n * {@link toPrinter} derives, or with `encode` when given. A derived printer's\n * text is parsed back, and encoding fails unless it gives a value equivalent\n * to the one encoded, so decoding what was encoded always gives it back.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Pair = ParserSchema.fromSchema(\n * Schema.Tuple([Schema.String, Schema.Number]).pipe(ParserSchema.annotate({ separator: \"=\" }))\n * )\n *\n * Schema.decodeUnknownSync(Pair)(\"width=10\") // [\"width\", 10]\n * Schema.encodeSync(Pair)([\"height\", 2]) // \"height=2\"\n * ```\n *\n * @since 0.3.0\n * @category constructors\n */\nexport const fromSchema = <S extends Schema.ConstraintCodec<unknown, unknown, never, never> & Schema.Top>(\n schema: S,\n options?: { readonly encode?: ((value: S[\"Type\"]) => string) | undefined }\n): Schema.decodeTo<Schema.toType<S>, Schema.String> => {\n const parser = toParser(schema)\n const encode = options?.encode\n return decodeWith<Schema.toType<S>>(\n Schema.toType(schema),\n parser,\n encode === undefined ? roundTrip(schema, parser) : encodeWith(encode)\n )\n}\n\n/** Prints with the derived printer, then checks that the text reads back as the value. */\nconst roundTrip = <S extends Schema.ConstraintCodec<unknown, unknown, never, never> & Schema.Top>(\n schema: S,\n parser: Parser<S[\"Type\"], Schema.SchemaError, never, string>\n): Encode<S[\"Type\"]> => {\n const print = toPrinter(schema)\n const equivalent = Schema.toEquivalence(Schema.toType(schema))\n return (value) =>\n Result.flatMap(\n Result.mapError(print(value), (error) => error.issue),\n (text) => {\n const back = P.parse(parser, text)\n return Result.isSuccess(back) && equivalent(back.success, value)\n ? Result.succeed(text)\n : Result.fail(\n new SchemaIssue.InvalidValue({\n message: `The value is written ${describeLiteral(text)}, which does not read back as the value`\n })\n )\n }\n )\n}\n\n// -----------------------------------------------------------------------------\n// The walk shared by parsers and printers\n// -----------------------------------------------------------------------------\n\ninterface Context<T> {\n /** Characters ending an unannotated string, sorted. */\n readonly stop: string\n readonly whitespace: boolean\n /** Grammar passed from a transformation to its encoded side. */\n readonly inherit: Grammar | undefined\n readonly path: ReadonlyArray<PropertyKey>\n /** What was derived for the recursive schemas met so far, by context. */\n readonly recursions: Array<Recursion<T>>\n}\n\ninterface Recursion<T> {\n readonly ast: SchemaAST.Suspend\n readonly key: string\n readonly derived: T\n}\n\nconst initial = <T>(): Context<T> => ({ stop: \"\", whitespace: false, inherit: undefined, path: [], recursions: [] })\n\n/** The annotation `key` on `ast`, from its last check back to the node, as `Schema.resolveAnnotations` resolves it. */\nconst lookup = (ast: SchemaAST.AST, key: string): unknown => {\n const checks = ast.checks\n if (checks !== undefined) {\n for (let i = checks.length - 1; i >= 0; i--) {\n const value = checks[i].annotations?.[key]\n if (value !== undefined) return value\n }\n }\n return ast.annotations?.[key]\n}\n\nconst grammarOf = (ast: SchemaAST.AST): Grammar => {\n const value = lookup(ast, annotationKey)\n if (value === undefined) return {}\n // SAFETY: the annotation is typed `Annotation`, a parser or a grammar\n return P.isParser(value) ? { parser: value as ForeignParser } : (value as Grammar)\n}\n\nconst isAnnotated = (ast: SchemaAST.AST): boolean => lookup(ast, annotationKey) !== undefined\n\nconst withStop = <T>(ctx: Context<T>, text: string | undefined): Context<T> => {\n if (text === undefined || text === \"\" || ctx.stop.includes(text[0])) return ctx\n return { ...ctx, stop: Arr.sort([...ctx.stop.split(\"\"), text[0]], Order.String).join(\"\") }\n}\n\nconst at = <T>(ctx: Context<T>, key: PropertyKey): Context<T> => ({\n ...ctx,\n inherit: undefined,\n path: [...ctx.path, key]\n})\n\nconst where = <T>(ctx: Context<T>): string => `[${ctx.path.map(String).join(\", \")}]`\n\nconst unsupported = <T>(ast: SchemaAST.AST, ctx: Context<T>, what: string): never => {\n throw new TypeError(`ParserSchema: cannot derive a ${what} for ${ast._tag} at ${where(ctx)}; annotate it`)\n}\n\ninterface Resolved<T> {\n readonly grammar: Grammar\n readonly whitespace: boolean\n /** The context of what the node contains. */\n readonly inner: Context<T>\n}\n\n/** The node's grammar, with what its transformation passed down, and the context inside it. */\nconst resolve = <T>(ast: SchemaAST.AST, ctx: Context<T>): Resolved<T> => {\n const own = grammarOf(ast)\n const inherit = ctx.inherit\n const grammar: Grammar =\n inherit === undefined\n ? own\n : {\n ...own,\n separator: own.separator ?? inherit.separator,\n keySeparator: own.keySeparator ?? inherit.keySeparator\n }\n const whitespace = grammar.whitespace ?? ctx.whitespace\n return { grammar, whitespace, inner: { ...withStop(ctx, grammar.suffix), whitespace, inherit: undefined } }\n}\n\n/** The context of a transformation's encoded side, which the transformation's separators apply to. */\nconst encodedContext = <T>(grammar: Grammar, ctx: Context<T>): Context<T> => ({\n ...ctx,\n inherit: { separator: grammar.separator, keySeparator: grammar.keySeparator }\n})\n\n/**\n * The node with its chain of links ending at the type of its encoded side,\n * which is what the encoded side is parsed into and printed from.\n */\nconst linkTarget = (ast: SchemaAST.AST, links: SchemaAST.Encoding): SchemaAST.AST => {\n const last = links[links.length - 1]\n let target = SchemaAST.toType(ast)\n for (const link of links) {\n const source = link === last ? SchemaAST.toType(last.to) : link.to\n // SAFETY: `decodeTo` appends the link as it is, middleware included, as the schema's own links are\n target = SchemaAST.decodeTo(source, target, link.transformation as SchemaTransformation.Transformation<any, any>)\n }\n return target\n}\n\n/**\n * What is derived for a recursive schema: deriving it again in the same\n * context gives the same result, so the derivation ends.\n */\nconst recursive = <T>(ast: SchemaAST.Suspend, ctx: Context<T>, make: () => T): T => {\n const key = `${ctx.whitespace ? 1 : 0}${ctx.stop}`\n const known = ctx.recursions.find((r) => r.ast === ast && r.key === key)\n if (known !== undefined) return known.derived\n const derived = make()\n ctx.recursions.push({ ast, key, derived })\n return derived\n}\n\n/** The context for the items of a sequence: unannotated strings also stop at the separator. */\nconst itemContext = <T>(grammar: Grammar, ctx: Context<T>): Context<T> => withStop(ctx, grammar.separator)\n\n/** The rest element of an array schema, if any; elements after it are not supported. */\nconst restOf = <T>(ast: SchemaAST.Arrays, ctx: Context<T>, what: string): SchemaAST.AST | undefined => {\n const [head, ...after] = ast.rest\n // Elements after the rest would need the rest to stop short\n return Arr.isReadonlyArrayNonEmpty(after) ? unsupported(ast, ctx, what) : head\n}\n\n/** The contexts of an array schema's elements and its rest. */\nconst elementContexts = <T>(\n ast: SchemaAST.Arrays,\n rest: SchemaAST.AST | undefined,\n grammar: Grammar,\n ctx: Context<T>\n): ReadonlyArray<Context<T>> => {\n const n = ast.elements.length\n return ast.elements.map((_, i) => at(i < n - 1 || rest !== undefined ? itemContext(grammar, ctx) : ctx, i))\n}\n\n/** The contexts of a struct's fields, written in order. */\nconst fieldContexts = <T>(ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<T>): ReadonlyArray<Context<T>> => {\n const fields = ast.propertySignatures\n return fields.map((field, i) => at(i < fields.length - 1 ? itemContext(grammar, ctx) : ctx, field.name))\n}\n\nconst isKeyed = (ast: SchemaAST.Objects, grammar: Grammar): boolean =>\n grammar.keySeparator !== undefined || Arr.isReadonlyArrayNonEmpty(ast.indexSignatures)\n\nconst keySeparatorOf = <T>(grammar: Grammar, ctx: Context<T>): string => {\n if (grammar.keySeparator === undefined) {\n throw new TypeError(`ParserSchema: a record at ${where(ctx)} needs a keySeparator in its annotation`)\n }\n return grammar.keySeparator\n}\n\n/** The field name of a struct in keyed form: a string. */\nconst keyName = <T>(ast: SchemaAST.Objects, field: SchemaAST.PropertySignature, ctx: Context<T>, what: string) =>\n Predicate.isString(field.name) ? field.name : unsupported(ast, ctx, what)\n\nconst propertyName = (key: PropertyKey): string | symbol => (Predicate.isNumber(key) ? String(key) : key)\n\n/** Whether a check (as `Schema.Int` has) restricts numbers to integers. */\nconst isIntegral = (checks: SchemaAST.Checks | undefined): boolean =>\n checks !== undefined &&\n checks.some((check) =>\n check instanceof SchemaAST.FilterGroup\n ? isIntegral(check.checks)\n : check.annotations?.arbitraryConstraint?.[\"number\"] === \"integer\"\n )\n\ntype LiteralValue = SchemaAST.Literal[\"literal\"]\n\n/** Literals with the longest text first, so a literal is never cut short by one it starts with. */\nconst byLength = <A extends LiteralValue>(values: ReadonlyArray<A>): Array<A> =>\n Arr.sort(\n values,\n Order.mapInput(Order.Number, (value: A) => -String(value).length)\n )\n\nconst isPlainLiteral = (ast: SchemaAST.AST): ast is SchemaAST.Literal =>\n SchemaAST.isLiteral(ast) && ast.encoding === undefined && !isAnnotated(ast)\n\n/** The literals of a union of plain literals, longest first, or `undefined`. */\nconst plainLiterals = (ast: SchemaAST.Union): ReadonlyArray<LiteralValue> | undefined => {\n const literals = Arr.filter(ast.types, isPlainLiteral)\n return literals.length === ast.types.length ? byLength(literals.map((member) => member.literal)) : undefined\n}\n\nconst schemaError = (issue: SchemaIssue.Issue) => new Schema.SchemaError(issue)\n\nconst decoder = (schema: Schema.ConstraintDecoder<unknown>) => Schema.decodeUnknownResult(schema)\n\n/** Decodes into the type of `ast`, checks included. */\nconst typeDecoder = (ast: SchemaAST.AST) => decoder(Schema.make<Schema.Codec<unknown>>(SchemaAST.toType(ast)))\n\n// -----------------------------------------------------------------------------\n// Parsers\n// -----------------------------------------------------------------------------\n\ntype AnyParser = Parser<any, Schema.SchemaError, never, string>\n\ntype ForeignParser = Parser<unknown, unknown, never, string>\n\nconst messageOf = (cause: unknown): string =>\n Predicate.isString(cause)\n ? cause\n : Predicate.hasProperty(cause, \"message\") && Predicate.isString(cause.message)\n ? cause.message\n : String(cause)\n\n/** A parser whose failures' causes are `SchemaError`s, as {@link toParser}'s are. */\nconst asSchemaErrors = (parser: ForeignParser): AnyParser =>\n P.mapError(parser, (cause) =>\n cause instanceof Schema.SchemaError\n ? cause\n : schemaError(new SchemaIssue.InvalidValue({ message: messageOf(cause) }))\n )\n\n/** Literal text, with optional whitespace around it. */\nconst text = (s: string, ws: boolean): AnyParser =>\n ws ? P.delimited(Ascii.multispace0, Token.literal(s), Ascii.multispace0) : Token.literal(s)\n\nconst derive = (ast: SchemaAST.AST, ctx: Context<AnyParser>): AnyParser => {\n const { grammar, inner, whitespace } = resolve(ast, ctx)\n let parser: AnyParser\n if (grammar.parser !== undefined) parser = P.tryMap(asSchemaErrors(grammar.parser), typeDecoder(ast))\n else if (ast.encoding !== undefined) parser = decoded(ast, ast.encoding, grammar, inner)\n else parser = checked(ast, structural(ast, grammar, inner))\n if (grammar.prefix !== undefined) parser = P.preceded(text(grammar.prefix, whitespace), parser)\n if (grammar.suffix !== undefined) parser = P.terminated(parser, text(grammar.suffix, whitespace))\n // A check's own `expected` describes the check, not the text\n const label = lookup(ast, \"identifier\") ?? ast.annotations?.expected\n return Predicate.isString(label) ? P.expected(parser, label) : parser\n}\n\n/** Runs the checks on `ast` (its filters) on the parser's output. */\nconst checked = (ast: SchemaAST.AST, parser: AnyParser): AnyParser =>\n ast.checks === undefined ? parser : P.tryMap(parser, decoder(Schema.Unknown.check(...ast.checks)))\n\n/**\n * Parses the encoded side of a transformation and decodes it. The encoded\n * side is parsed into its own type, so the last link decodes from that type\n * rather than from the fully encoded form.\n */\nconst decoded = (\n ast: SchemaAST.AST,\n links: SchemaAST.Encoding,\n grammar: Grammar,\n ctx: Context<AnyParser>\n): AnyParser => {\n const from = derive(links[links.length - 1].to, encodedContext(grammar, ctx))\n return P.tryMap(from, decoder(Schema.make<Schema.Codec<unknown>>(linkTarget(ast, links))))\n}\n\nconst structural = (ast: SchemaAST.AST, grammar: Grammar, ctx: Context<AnyParser>): AnyParser =>\n Match.valueTags(ast, {\n String: () => unannotatedString(ctx, 1),\n Number: (number) => (isIntegral(number.checks) ? integer : Ascii.float),\n BigInt: () => Ascii.decBigInt,\n Boolean: () => P.alt(P.as(Token.literal(\"true\"), true), P.as(Token.literal(\"false\"), false)),\n Null: () => P.as(Token.literal(\"null\"), null),\n Undefined: () => P.succeed(undefined),\n Void: () => P.succeed(undefined),\n Never: () => P.reject,\n Literal: (lit) => literal(lit.literal),\n Enum: (e) => P.alt(...byLength(e.enums.map(([, value]) => value)).map(literal)),\n TemplateLiteral: (template) => templateLiteral(template, ctx),\n Arrays: (arrays) => sequenceOf(arrays, grammar, ctx),\n Objects: (objects) =>\n isKeyed(objects, grammar) ? keyed(objects, grammar, ctx) : positional(objects, grammar, ctx),\n Union: (union) => alternatives(union, ctx),\n Suspend: (suspend) => recursive(suspend, ctx, () => P.suspend(() => derive(suspend.thunk(), ctx))),\n Declaration: (other) => unsupported(other, ctx, \"parser\"),\n Unknown: (other) => unsupported(other, ctx, \"parser\"),\n Any: (other) => unsupported(other, ctx, \"parser\"),\n Symbol: (other) => unsupported(other, ctx, \"parser\"),\n UniqueSymbol: (other) => unsupported(other, ctx, \"parser\"),\n ObjectKeyword: (other) => unsupported(other, ctx, \"parser\")\n })\n\nconst unannotatedString = (ctx: Context<AnyParser>, min: number): AnyParser => {\n const s = Token.takeTill(ctx.stop, { min })\n // Leading whitespace is skipped first, so it doesn't count towards `min`\n return ctx.whitespace\n ? P.preceded(\n Ascii.multispace0,\n P.map(s, (value) => value.trimEnd())\n )\n : s\n}\n\nconst integer: AnyParser = /*#__PURE__*/ asSchemaErrors(Ascii.decInt)\n\nconst literal = (value: LiteralValue): AnyParser => P.as(Token.literal(String(value)), value)\n\nconst templateLiteral = (ast: SchemaAST.TemplateLiteral, ctx: Context<AnyParser>): AnyParser =>\n P.taken(\n P.seq(\n ...ast.parts.map((part, i) => {\n const next = ast.parts[i + 1]\n const partCtx = next !== undefined && SchemaAST.isLiteral(next) ? withStop(ctx, String(next.literal)) : ctx\n // An interpolated string may be empty\n return SchemaAST.isString(part) && !isAnnotated(part)\n ? unannotatedString(partCtx, 0)\n : derive(part, at(partCtx, i))\n })\n )\n )\n\nconst alternatives = (ast: SchemaAST.Union, ctx: Context<AnyParser>): AnyParser => {\n const literals = plainLiterals(ast)\n return literals !== undefined\n ? P.alt(...literals.map(literal))\n : P.alt(...ast.types.map((member) => derive(member, ctx)))\n}\n\ninterface Item {\n readonly parser: AnyParser\n readonly optional: boolean\n}\n\ntype Values = Parser<Array<unknown>, Schema.SchemaError, never, string>\n\n/**\n * Parses `items` in order, then any number of `rest`, with `separator`\n * between the ones present. The output has the value of item `i` at index\n * `i` (a hole when an optional item is missing), then the rest.\n */\nconst sequence = (\n items: ReadonlyArray<Item>,\n rest: AnyParser | undefined,\n separator: AnyParser | undefined\n): Values => {\n const n = items.length\n const tail = (needSeparator: boolean): Values => {\n if (rest === undefined) return P.sync(() => new Array(n))\n const values =\n separator === undefined\n ? P.repeat(rest)\n : needSeparator\n ? P.repeat(P.preceded(separator, rest))\n : P.separated(rest, separator)\n return P.map(values, (xs) => {\n const out = new Array(n)\n for (let j = 0; j < xs.length; j++) out[n + j] = xs[j]\n return out\n })\n }\n // One parser per position and whether a separator comes first, at index `2 * i + needSeparator`\n const memo: Array<Values | undefined> = []\n const from = (i: number, needSeparator: boolean): Values => {\n const key = i * 2 + (needSeparator ? 1 : 0)\n const known = memo[key]\n if (known !== undefined) return known\n let parser: Values\n if (i === n) parser = tail(needSeparator)\n else {\n const item = items[i]\n const head = needSeparator && separator !== undefined ? P.preceded(separator, item.parser) : item.parser\n const present = P.map(P.seq(head, from(i + 1, true)), ([value, out]) => {\n out[i] = value\n return out\n })\n parser = item.optional ? P.alt(present, from(i + 1, needSeparator)) : present\n }\n memo[key] = parser\n return parser\n }\n return from(0, false)\n}\n\nconst separatorOf = (grammar: Grammar, ctx: Context<AnyParser>): AnyParser | undefined =>\n grammar.separator === undefined ? undefined : text(grammar.separator, ctx.whitespace)\n\nconst sequenceOf = (ast: SchemaAST.Arrays, grammar: Grammar, ctx: Context<AnyParser>): AnyParser => {\n const head = restOf(ast, ctx, \"parser\")\n const contexts = elementContexts(ast, head, grammar, ctx)\n const items = ast.elements.map((element, i) => ({\n parser: derive(element, contexts[i]),\n optional: SchemaAST.isOptional(element)\n }))\n const rest = head === undefined ? undefined : derive(head, at(itemContext(grammar, ctx), items.length))\n // Optional elements come last, so the present values are the first ones\n return P.map(sequence(items, rest, separatorOf(grammar, ctx)), (out) => out.filter((_, i) => i in out))\n}\n\nconst positional = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<AnyParser>): AnyParser => {\n const fields = ast.propertySignatures\n const contexts = fieldContexts(ast, grammar, ctx)\n const items = fields.map((field, i) => ({\n parser: derive(field.type, contexts[i]),\n optional: SchemaAST.isOptional(field.type)\n }))\n return P.map(sequence(items, undefined, separatorOf(grammar, ctx)), (out) =>\n Record.fromEntries(fields.flatMap((field, i) => (i in out ? [[propertyName(field.name), out[i]] as const] : [])))\n )\n}\n\ntype Entry = readonly [key: string | symbol, value: unknown, known: boolean]\n\nconst keyed = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<AnyParser>): AnyParser => {\n const keySeparator = keySeparatorOf(grammar, ctx)\n const between = text(keySeparator, ctx.whitespace)\n const valueCtx = itemContext(grammar, ctx)\n const known = ast.propertySignatures.map((field): AnyParser => {\n const name = keyName(ast, field, ctx, \"parser\")\n const value = derive(field.type, at(valueCtx, name))\n return P.map(P.preceded(P.seq(Token.literal(name), between), value), (v): Entry => [name, v, true])\n })\n const indexed = ast.indexSignatures.map((signature): AnyParser => {\n const key = derive(signature.parameter, at(withStop(ctx, keySeparator), \"<key>\"))\n const value = derive(signature.type, at(valueCtx, \"<value>\"))\n return P.map(P.separatedPair(key, between, value), ([k, v]): Entry => [propertyName(k), v, false])\n })\n const entry = P.alt(...known, ...indexed)\n const separator = separatorOf(grammar, ctx)\n const entries = separator === undefined ? P.repeat(entry) : P.separated(entry, separator)\n // A missing field fails where its entry could have been, as a syntax error, so a\n // failure further in (the entry that ended the repetition early) is reported instead\n const missing = ast.propertySignatures.map((field) =>\n P.expected(P.reject, describeLiteral(`${String(field.name)}${keySeparator}`))\n )\n return P.flatMap(\n P.tryMap(entries, (es: ReadonlyArray<Entry>) => assemble(ast, es)),\n ([value, absent]) => (absent === undefined ? P.succeed(value) : missing[absent])\n )\n}\n\n/**\n * Builds the object from its entries, declared fields first, rejecting\n * duplicate keys. Also returns the index of the first required field\n * missing, if any.\n */\nconst assemble = (\n ast: SchemaAST.Objects,\n entries: ReadonlyArray<Entry>\n): Result.Result<readonly [object, number | undefined], Schema.SchemaError> => {\n const values = MutableHashMap.empty<string | symbol, unknown>()\n for (const [key, value] of entries) {\n if (MutableHashMap.has(values, key)) {\n return Result.fail(\n schemaError(new SchemaIssue.Pointer([key], new SchemaIssue.InvalidValue({ message: \"Duplicate key\" })))\n )\n }\n MutableHashMap.set(values, key, value)\n }\n const out: Array<readonly [string | symbol, unknown]> = []\n let absent: number | undefined\n ast.propertySignatures.forEach((field, i) => {\n const name = propertyName(field.name)\n const value = MutableHashMap.get(values, name)\n if (Option.isSome(value)) out.push([name, value.value])\n else if (absent === undefined && !SchemaAST.isOptional(field.type)) absent = i\n })\n for (const [key, value, isKnown] of entries) if (!isKnown) out.push([key, value])\n return Result.succeed([Record.fromEntries(out), absent])\n}\n\n// -----------------------------------------------------------------------------\n// Printers\n// -----------------------------------------------------------------------------\n\n/**\n * Writes the text of a value, already validated against the schema's type,\n * to `out`, or returns why it cannot be written.\n */\ntype Printer = (value: any, out: Array<string>) => SchemaIssue.Issue | undefined\n\n/** The issue for a value that cannot be written at the node `ctx` is at. */\nconst unwritable = <T>(ctx: Context<T>, message: string, value: unknown): SchemaIssue.Issue => {\n const issue = new SchemaIssue.InvalidValue({ message }, value, { reportInput: true })\n return Arr.isReadonlyArrayNonEmpty(ctx.path) ? new SchemaIssue.Pointer(ctx.path, issue) : issue\n}\n\nconst writing =\n (show: (value: any) => string): Printer =>\n (value, out) => {\n out.push(show(value))\n return undefined\n }\n\nconst nothing: Printer = (_, __) => undefined\n\nconst printerOf = (ast: SchemaAST.AST, ctx: Context<Printer>): Printer => {\n const { grammar, inner } = resolve(ast, ctx)\n let print: Printer\n if (grammar.print !== undefined) print = writing(grammar.print)\n else if (grammar.parser !== undefined) print = unprintable(ctx)\n else if (ast.encoding !== undefined) print = encoded(ast, ast.encoding, grammar, inner)\n else print = printerFor(ast, grammar, inner)\n const prefix = grammar.prefix\n const suffix = grammar.suffix\n if (prefix === undefined && suffix === undefined) return print\n const inside = print\n return (value, out) => {\n if (prefix !== undefined) out.push(prefix)\n const issue = inside(value, out)\n if (suffix !== undefined) out.push(suffix)\n return issue\n }\n}\n\nconst unprintable =\n (ctx: Context<Printer>): Printer =>\n (value) =>\n unwritable(ctx, \"This value has a parser in its annotation but no print, so it cannot be written\", value)\n\n/** Encodes a transformation's value and prints its encoded side. */\nconst encoded = (ast: SchemaAST.AST, links: SchemaAST.Encoding, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const to = printerOf(links[links.length - 1].to, encodedContext(grammar, ctx))\n const encode = Schema.encodeUnknownResult(Schema.make<Schema.Codec<unknown, unknown>>(linkTarget(ast, links)))\n return (value, out) => {\n const result = encode(value)\n return Result.isSuccess(result) ? to(result.success, out) : result.failure.issue\n }\n}\n\nconst printerFor = (ast: SchemaAST.AST, grammar: Grammar, ctx: Context<Printer>): Printer =>\n Match.valueTags(ast, {\n String: () => stringPrinter(ctx),\n Number: () => writing(String),\n BigInt: () => writing(String),\n Boolean: () => writing(String),\n Null: () => writing(String),\n Undefined: () => nothing,\n Void: () => nothing,\n Never: () => nothing,\n Literal: () => writing(String),\n Enum: () => writing(String),\n TemplateLiteral: () => writing(String),\n Arrays: (arrays) => arraysPrinter(arrays, grammar, ctx),\n Objects: (objects) =>\n isKeyed(objects, grammar) ? keyedPrinter(objects, grammar, ctx) : positionalPrinter(objects, grammar, ctx),\n Union: (union) => unionPrinter(union, ctx),\n Suspend: (suspend) =>\n recursive(suspend, ctx, () => {\n let print: Printer | undefined\n return (value, out) => (print ??= printerOf(suspend.thunk(), ctx))(value, out)\n }),\n Declaration: (other) => unsupported(other, ctx, \"printer\"),\n Unknown: (other) => unsupported(other, ctx, \"printer\"),\n Any: (other) => unsupported(other, ctx, \"printer\"),\n Symbol: (other) => unsupported(other, ctx, \"printer\"),\n UniqueSymbol: (other) => unsupported(other, ctx, \"printer\"),\n ObjectKeyword: (other) => unsupported(other, ctx, \"printer\")\n })\n\n/**\n * Writes a string as an unannotated string is parsed: refusing one that\n * would not read back, being empty or holding a character that ends it.\n */\nconst stringPrinter =\n (ctx: Context<Printer>): Printer =>\n (value: string, out) => {\n if (value === \"\") return unwritable(ctx, \"An empty string cannot be written here\", value)\n const stop = Arr.findFirst(Array.from(ctx.stop), (c) => value.includes(c))\n if (Option.isSome(stop)) {\n return unwritable(ctx, `A string containing ${describeLiteral(stop.value)} cannot be written here`, value)\n }\n if (ctx.whitespace && value.trim() !== value) {\n return unwritable(ctx, \"A string with whitespace around it cannot be written here\", value)\n }\n out.push(value)\n return undefined\n }\n\n/** Writes values with a separator between them, stopping at the first that cannot be written. */\nconst writeAll = (\n writes: ReadonlyArray<(out: Array<string>) => SchemaIssue.Issue | undefined>,\n separator: string,\n out: Array<string>\n): SchemaIssue.Issue | undefined => {\n for (let i = 0; i < writes.length; i++) {\n if (i > 0) out.push(separator)\n const issue = writes[i](out)\n if (issue !== undefined) return issue\n }\n return undefined\n}\n\nconst arraysPrinter = (ast: SchemaAST.Arrays, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const head = restOf(ast, ctx, \"printer\")\n const contexts = elementContexts(ast, head, grammar, ctx)\n const elements = ast.elements.map((element, i) => printerOf(element, contexts[i]))\n const rest = head === undefined ? nothing : printerOf(head, at(itemContext(grammar, ctx), elements.length))\n const separator = grammar.separator ?? \"\"\n return (value: ReadonlyArray<unknown>, out) =>\n writeAll(\n value.map((element, i) => (o: Array<string>) => (elements[i] ?? rest)(element, o)),\n separator,\n out\n )\n}\n\nconst positionalPrinter = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const contexts = fieldContexts(ast, grammar, ctx)\n const fields = ast.propertySignatures.map((field, i) => ({\n name: propertyName(field.name),\n print: printerOf(field.type, contexts[i])\n }))\n const separator = grammar.separator ?? \"\"\n return (value: Record.ReadonlyRecord<string | symbol, unknown>, out) =>\n writeAll(\n fields\n .filter((field) => Record.has(value, field.name))\n .map((field) => (o: Array<string>) => field.print(value[field.name], o)),\n separator,\n out\n )\n}\n\nconst keyedPrinter = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const keySeparator = keySeparatorOf(grammar, ctx)\n const valueCtx = itemContext(grammar, ctx)\n const fields = ast.propertySignatures.map((field) => {\n const name = keyName(ast, field, ctx, \"printer\")\n return { name, print: printerOf(field.type, at(valueCtx, name)) }\n })\n const names = fields.map((field) => field.name)\n const indexed = ast.indexSignatures.map((signature) => ({\n is: Schema.is(Schema.make<Schema.Top>(SchemaAST.toType(signature.parameter))),\n key: printerOf(signature.parameter, at(withStop(ctx, keySeparator), \"<key>\")),\n value: printerOf(signature.type, at(valueCtx, \"<value>\"))\n }))\n const entry =\n (key: Printer, print: Printer, k: unknown, v: unknown) =>\n (out: Array<string>): SchemaIssue.Issue | undefined =>\n key(k, out) ?? (out.push(keySeparator), print(v, out))\n return (value: Record.ReadonlyRecord<string, unknown>, out) => {\n const writes = fields\n .filter((field) => Record.has(value, field.name))\n .map((field) => entry(writing(String), field.print, field.name, value[field.name]))\n for (const key of Record.keys(value)) {\n const signature = names.includes(key) ? undefined : indexed.find((s) => s.is(key))\n if (signature !== undefined) writes.push(entry(signature.key, signature.value, key, value[key]))\n }\n return writeAll(writes, grammar.separator ?? \"\", out)\n }\n}\n\n/** Writes a union's value with the first member it belongs to that can write it. */\nconst unionPrinter = (ast: SchemaAST.Union, ctx: Context<Printer>): Printer => {\n if (plainLiterals(ast) !== undefined) return writing(String)\n const members = ast.types.map((member) => ({\n is: Schema.is(Schema.make<Schema.Top>(SchemaAST.toType(member))),\n print: printerOf(member, ctx)\n }))\n return (value, out) => {\n let issue: SchemaIssue.Issue | undefined\n for (const member of members) {\n if (!member.is(value)) continue\n const mark = out.length\n issue = member.print(value, out)\n if (issue === undefined) return undefined\n out.length = mark\n }\n return issue ?? unwritable(ctx, \"No member of the union can write this value\", value)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,MAAa,gBAAgB;AAsC7B,MAAM,cACA,YACH,UACC,OAAO,QAAQ,OAAO,KAAK,CAAC;AAEhC,MAAM,cACJ,QACA,QACA,WAEA,OAAO,OAAO,KACZ,OAAO,SACL,QACA,qBAAqB,gBAAsC;CACzD,SAAS,OAAO,iBAAiB;EAC/B,MAAM,SAAS,EAAE,MAAM,QAAQ,KAAK;EACpC,OAAO,OAAO,UAAU,MAAM,IAC1B,OAAO,QAAQ,OAAO,OAAO,IAC7B,OAAO,KAAK,IAAI,YAAY,aAAa,EAAE,SAAS,OAAO,QAAQ,QAAQ,GAAG,OAAO,YAAY,CAAC;CACxG;CACA,SAAS,OAAO,iBAAiB;EAC/B,IAAI,WAAW,KAAA,GACb,OAAO,OAAO,KAAK,IAAI,YAAY,UAAU,EAAE,SAAS,4BAA4B,GAAG,OAAO,YAAY,CAAC;EAE7G,MAAM,SAAS,OAAO,KAAK;EAC3B,OAAO,OAAO,UAAU,MAAM,IAAI,OAAO,QAAQ,OAAO,OAAO,IAAI,OAAO,KAAK,OAAO,OAAO;CAC/F;AACF,CAAC,CACH,CACF;;;;;;;;AASF,MAAa,QAAc,QAAqC,YAC9D,WACE,OAAO,SACJ,OAAgB,MACjB,SAAS,gBAAgB,KAAA,IAAY,EAAE,aAAa,QAAQ,YAAY,IAAI,KAAA,CAC9E,GACA,QACA,SAAS,WAAW,KAAA,IAAY,KAAA,IAAY,WAAW,QAAQ,MAAM,CACvE;;;;;;;;;;;;;;;;;;;;AA0EF,MAAa,WAMK,mBAAK,IAA0B,MAAS,eACxD,KAAK,SAAS,GAAG,gBAAgB,WAAW,CAAC,CAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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rB,IAAI;EACJ,KAAK,MAAM,UAAU,SAAS;GAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,GAAG;GACvB,MAAM,OAAO,IAAI;GACjB,QAAQ,OAAO,MAAM,OAAO,GAAG;GAC/B,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;GAChC,IAAI,SAAS;EACf;EACA,OAAO,SAAS,WAAW,KAAK,+CAA+C,KAAK;CACtF;AACF"}
1
+ {"version":3,"file":"ParserSchema.js","names":[],"sources":["../src/ParserSchema.ts"],"sourcesContent":["/**\n * Effect `Schema`s and parsers, in both directions.\n *\n * {@link make} turns a parser over strings into a schema that decodes a\n * `string` into the parser's output. Parse errors become schema issues\n * carrying the rendered `ParseError` message. Encoding needs a printer,\n * supplied as `encode`; without one, encoding is forbidden.\n *\n * {@link toParser} goes the other way: it derives a parser from a schema,\n * guided by annotations ({@link annotate}) that say how each part is\n * written. {@link toPrinter} derives the printer that writes that text, and\n * {@link fromSchema} wraps both as a schema.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { Ascii, Parser, ParserSchema, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const Version = ParserSchema.make(\n * Parser.struct({\n * major: Ascii.decUint,\n * minor: Parser.preceded(Token.literal(\".\"), Ascii.decUint)\n * }),\n * { encode: ({ major, minor }) => `${major}.${minor}` }\n * )\n *\n * Schema.decodeUnknownSync(Version)(\"1.2\") // { major: 1, minor: 2 }\n * Schema.encodeSync(Version)({ major: 3, minor: 4 }) // \"3.4\"\n * ```\n *\n * @since 0.1.0\n */\nimport * as Arr from \"effect/Array\"\nimport * as Effect from \"effect/Effect\"\nimport { dual } from \"effect/Function\"\nimport * as Match from \"effect/Match\"\nimport * as MutableHashMap from \"effect/MutableHashMap\"\nimport * as Option from \"effect/Option\"\nimport * as Order from \"effect/Order\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Record from \"effect/Record\"\nimport * as Result from \"effect/Result\"\nimport * as Schema from \"effect/Schema\"\nimport * as SchemaAST from \"effect/SchemaAST\"\nimport * as SchemaIssue from \"effect/SchemaIssue\"\nimport * as SchemaTransformation from \"effect/SchemaTransformation\"\nimport * as Ascii from \"./Ascii.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\nimport { describeLiteral } from \"./internal/tokens.js\"\n\n/**\n * The key of the annotation that says how a schema is written as text\n * ({@link Annotation}), namespaced to this package so it cannot collide with\n * another library's. {@link annotate} sets it.\n *\n * @since 0.3.0\n * @category annotations\n */\nexport const annotationKey = \"@thomasfosterau/effect-parse/ParserSchema\" as const\n\ndeclare module \"effect/Schema\" {\n namespace Annotations {\n interface Annotations {\n /**\n * How the schema is written as text, read by `ParserSchema.toParser`\n * and `ParserSchema.toPrinter`: a parser for the schema's type, or a\n * `ParserSchema.Grammar`.\n */\n readonly [annotationKey]?: Annotation<any> | undefined\n }\n }\n}\n\n/**\n * Options for {@link make}.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface Options<A> {\n /** Prints a value back to a string. Without it, encoding fails. */\n readonly encode?: ((value: A) => string) | undefined\n /** A description of the decoded type, used by schema tooling. */\n readonly description?: string | undefined\n}\n\n/**\n * A schema decoding strings with a parser.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface ParserSchema<A> extends Schema.decodeTo<Schema.declare<A>, Schema.String> {}\n\ntype Encode<A> = (value: A) => Result.Result<string, SchemaIssue.Issue>\n\nconst encodeWith =\n <A>(encode: (value: A) => string): Encode<A> =>\n (value) =>\n Result.succeed(encode(value))\n\nconst decodeWith = <T extends Schema.Top>(\n target: T,\n parser: Parser<T[\"Encoded\"], unknown, never, string>,\n encode: Encode<T[\"Encoded\"]> | undefined\n) =>\n Schema.String.pipe(\n Schema.decodeTo(\n target,\n SchemaTransformation.transformEffect<T[\"Encoded\"], string>({\n decode: (input, parseOptions) => {\n const result = P.parse(parser, input)\n return Result.isSuccess(result)\n ? Effect.succeed(result.success)\n : Effect.fail(new SchemaIssue.InvalidValue({ message: result.failure.message }, input, parseOptions))\n },\n encode: (value, parseOptions) => {\n if (encode === undefined) {\n return Effect.fail(new SchemaIssue.Forbidden({ message: \"Encoding is not supported\" }, value, parseOptions))\n }\n return Effect.fromResult(encode(value))\n }\n })\n )\n )\n\n/**\n * Creates a schema that decodes a string with `parser`, which must consume\n * the whole string.\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const make = <A, E>(parser: Parser<A, E, never, string>, options?: Options<A>): ParserSchema<A> =>\n decodeWith(\n Schema.declare<A>(\n (_u): _u is A => true,\n options?.description !== undefined ? { description: options.description } : undefined\n ),\n parser,\n options?.encode === undefined ? undefined : encodeWith(options.encode)\n )\n\n// -----------------------------------------------------------------------------\n// Deriving parsers and printers from schemas\n// -----------------------------------------------------------------------------\n\n/**\n * How a schema is written as text, given in its annotation (see\n * {@link annotate}) and read by {@link toParser} and {@link toPrinter}.\n * Every field is optional; a schema without one is written as described on\n * {@link toParser}.\n *\n * @since 0.3.0\n * @category models\n */\nexport interface Grammar<A = unknown> {\n /**\n * Parses the schema's type outright, replacing what {@link toParser} would\n * derive. Its output is still validated against the schema's type and\n * checks, and its failures' causes become `SchemaError`s with their message.\n * Give a {@link Grammar.print} with it, or the schema cannot be printed.\n */\n readonly parser?: Parser<A, unknown, never, string> | undefined\n /** Writes a value as the text {@link Grammar.parser} reads, replacing what {@link toPrinter} would derive. */\n readonly print?: ((value: A) => string) | undefined\n /** Text written before the value. */\n readonly prefix?: string | undefined\n /** Text written after the value. */\n readonly suffix?: string | undefined\n /** Text written between the fields of a struct, the elements of a tuple or array, or the entries of a record. */\n readonly separator?: string | undefined\n /**\n * Text written between a key and its value. On a struct, it writes each\n * field as `key`, separator, value, in any order; records always need one.\n */\n readonly keySeparator?: string | undefined\n /**\n * Whether whitespace may surround the text this schema writes (its prefix,\n * suffix and separators), and whitespace around unannotated strings is\n * trimmed. Inherited by the schemas inside it. Printers write no\n * whitespace.\n */\n readonly whitespace?: boolean | undefined\n}\n\n/**\n * The value of the annotation under {@link annotationKey}: a\n * {@link Grammar}, or a parser for the schema's type (short for\n * `{ parser }`, which cannot be printed).\n *\n * @since 0.3.0\n * @category models\n */\nexport type Annotation<A = unknown> = Grammar<A> | Parser<A, unknown, never, string>\n\n/**\n * Annotates a schema with how it is written as text, for {@link toParser}\n * and {@link toPrinter}. The same as\n * `schema.annotate({ [ParserSchema.annotationKey]: annotation })`, except\n * that the parser's output must have the schema's type.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Point = Schema.Struct({ x: Schema.Int, y: Schema.Int }).pipe(\n * ParserSchema.annotate({ prefix: \"(\", separator: \",\", suffix: \")\" })\n * )\n * ```\n *\n * @since 0.3.0\n * @category annotations\n */\nexport const annotate: {\n // A grammar without a parser constrains nothing\n <A = never>(\n annotation: Annotation<A>\n ): <S extends Schema.Top>(self: S & ([A] extends [S[\"Type\"]] ? unknown : never)) => S[\"Rebuild\"]\n <S extends Schema.Top>(self: S, annotation: Annotation<S[\"Type\"]>): S[\"Rebuild\"]\n} = /*#__PURE__*/ dual(2, <S extends Schema.Top>(self: S, annotation: Annotation<S[\"Type\"]>): S[\"Rebuild\"] =>\n self.annotate({ [annotationKey]: annotation })\n)\n\n/**\n * Derives a parser from a schema. The parser reads the text the schema's\n * annotations ({@link Grammar}) describe and returns a value of the schema's\n * type, which the schema's checks and transformations have already\n * validated; their failures become parse errors whose `cause` is the\n * `SchemaError`.\n *\n * Without an annotation, a schema is parsed as follows:\n *\n * - `String`: one or more characters up to the next separator, key\n * separator, suffix or literal around it (to the end of the input at the\n * top level).\n * - `Number`: a decimal number (`Ascii.float`), or a decimal integer when\n * the schema checks `isInt` (as `Schema.Int` does). `BigInt`: a decimal\n * integer. `Boolean`: `true` or `false`. `Null`: `null`. `Undefined` and\n * `Void`: nothing.\n * - `Literal`, `Enum` and `TemplateLiteral`: their text.\n * - `Struct` and `Tuple`: their fields or elements in order, between\n * separators; an optional one may be left out along with its separator.\n * `Array`: elements between separators.\n * - `Record`, and `Struct` with a `keySeparator`: `key`, key separator,\n * value entries in any order, between separators.\n * - `Union`: the first member that parses, in order (literals longest\n * first). `suspend`: recursion.\n * - A transformation (a `Class`, `NumberFromString`, ...): its encoded side,\n * decoded by the schema. A grammar on it with a separator applies to the\n * encoded side.\n *\n * A parser that fails where the schema starts reports the schema's\n * `identifier` annotation (or its `expected` annotation, unless that belongs\n * to a check) as what it expected. Other declarations, `Unknown`, `Any`,\n * symbols and `object` need a parser in their annotation; without one,\n * `toParser` throws. Transformations must decode synchronously.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { Parser, ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Version = Schema.Struct({ major: Schema.Int, minor: Schema.Int }).pipe(\n * ParserSchema.annotate({ separator: \".\" })\n * )\n *\n * Parser.parse(ParserSchema.toParser(Version), \"1.2\") // Result.succeed({ major: 1, minor: 2 })\n * ```\n *\n * @since 0.3.0\n * @category derivation\n */\nexport const toParser = <S extends Schema.ConstraintDecoder<unknown>>(\n schema: S\n): Parser<S[\"Type\"], Schema.SchemaError, never, string> => {\n const ast = schema.ast\n const parser = derive(ast, initial<AnyParser>())\n return grammarOf(ast).whitespace === true ? P.delimited(Ascii.multispace0, parser, Ascii.multispace0) : parser\n}\n\n/**\n * Derives a printer from a schema: it writes a value of the schema's type as\n * the text {@link toParser} reads, following the same annotations, with no\n * optional whitespace. Transformations encode the value first, and a\n * {@link Grammar.print} replaces the derived printer.\n *\n * The printer fails with a `SchemaError` when the value is not of the\n * schema's type, or cannot be written so that it reads back: a string that\n * is empty or contains a character that would end it (a separator, a\n * suffix), or a part annotated with a parser but no `print`. Where the\n * grammar is ambiguous (an optional field followed by a field of the same\n * type), the text can still read back as a different value;\n * {@link fromSchema} checks that it doesn't.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Version = Schema.Struct({ major: Schema.Int, minor: Schema.Int }).pipe(\n * ParserSchema.annotate({ separator: \".\" })\n * )\n *\n * ParserSchema.toPrinter(Version)({ major: 1, minor: 2 }) // Result.succeed(\"1.2\")\n * ```\n *\n * @since 0.3.0\n * @category derivation\n */\nexport const toPrinter = <S extends Schema.ConstraintCodec<unknown, unknown, unknown, never>>(\n schema: S\n): ((value: S[\"Type\"]) => Result.Result<string, Schema.SchemaError>) => {\n const validate = typeDecoder(schema.ast)\n const print = printerOf(schema.ast, initial<Printer>())\n return (value) => {\n const valid = validate(value)\n if (Result.isFailure(valid)) return Result.fail(valid.failure)\n const out: Array<string> = []\n const issue = print(valid.success, out)\n return issue === undefined ? Result.succeed(out.join(\"\")) : Result.fail(schemaError(issue))\n }\n}\n\n/**\n * Creates a schema that decodes a string with the parser {@link toParser}\n * derives from `schema`, into `schema`'s type, and encodes with the printer\n * {@link toPrinter} derives, or with `encode` when given. A derived printer's\n * text is parsed back, and encoding fails unless it gives a value equivalent\n * to the one encoded, so decoding what was encoded always gives it back.\n *\n * @example\n * ```ts\n * import { Schema } from \"effect\"\n * import { ParserSchema } from \"@thomasfosterau/effect-parse\"\n *\n * const Pair = ParserSchema.fromSchema(\n * Schema.Tuple([Schema.String, Schema.Number]).pipe(ParserSchema.annotate({ separator: \"=\" }))\n * )\n *\n * Schema.decodeUnknownSync(Pair)(\"width=10\") // [\"width\", 10]\n * Schema.encodeSync(Pair)([\"height\", 2]) // \"height=2\"\n * ```\n *\n * @since 0.3.0\n * @category constructors\n */\nexport const fromSchema = <S extends Schema.ConstraintCodec<unknown, unknown, never, never> & Schema.Top>(\n schema: S,\n options?: { readonly encode?: ((value: S[\"Type\"]) => string) | undefined }\n): Schema.decodeTo<Schema.toType<S>, Schema.String> => {\n const parser = toParser(schema)\n const encode = options?.encode\n return decodeWith<Schema.toType<S>>(\n Schema.toType(schema),\n parser,\n encode === undefined ? roundTrip(schema, parser) : encodeWith(encode)\n )\n}\n\n/** Prints with the derived printer, then checks that the text reads back as the value. */\nconst roundTrip = <S extends Schema.ConstraintCodec<unknown, unknown, never, never> & Schema.Top>(\n schema: S,\n parser: Parser<S[\"Type\"], Schema.SchemaError, never, string>\n): Encode<S[\"Type\"]> => {\n const print = toPrinter(schema)\n const equivalent = Schema.toEquivalence(Schema.toType(schema))\n return (value) =>\n Result.flatMap(\n Result.mapError(print(value), (error) => error.issue),\n (text) => {\n const back = P.parse(parser, text)\n return Result.isSuccess(back) && equivalent(back.success, value)\n ? Result.succeed(text)\n : Result.fail(\n new SchemaIssue.InvalidValue({\n message: `The value is written ${describeLiteral(text)}, which does not read back as the value`\n })\n )\n }\n )\n}\n\n// -----------------------------------------------------------------------------\n// The walk shared by parsers and printers\n// -----------------------------------------------------------------------------\n\ninterface Context<T> {\n /** Characters ending an unannotated string, sorted. */\n readonly stop: string\n readonly whitespace: boolean\n /** Grammar passed from a transformation to its encoded side. */\n readonly inherit: Grammar | undefined\n readonly path: ReadonlyArray<PropertyKey>\n /** What was derived for the recursive schemas met so far, by context. */\n readonly recursions: Array<Recursion<T>>\n}\n\ninterface Recursion<T> {\n readonly ast: SchemaAST.Suspend\n readonly key: string\n readonly derived: T\n}\n\nconst initial = <T>(): Context<T> => ({ stop: \"\", whitespace: false, inherit: undefined, path: [], recursions: [] })\n\n/** The annotation `key` on `ast`, from its last check back to the node, as `Schema.resolveAnnotations` resolves it. */\nconst lookup = (ast: SchemaAST.AST, key: string): unknown => {\n const checks = ast.checks\n if (checks !== undefined) {\n for (let i = checks.length - 1; i >= 0; i--) {\n const value = checks[i].annotations?.[key]\n if (value !== undefined) return value\n }\n }\n return ast.annotations?.[key]\n}\n\nconst grammarOf = (ast: SchemaAST.AST): Grammar => {\n const value = lookup(ast, annotationKey)\n if (value === undefined) return {}\n // SAFETY: the annotation is typed `Annotation`, a parser or a grammar\n return P.isParser(value) ? { parser: value as ForeignParser } : (value as Grammar)\n}\n\nconst isAnnotated = (ast: SchemaAST.AST): boolean => lookup(ast, annotationKey) !== undefined\n\nconst withStop = <T>(ctx: Context<T>, text: string | undefined): Context<T> => {\n if (text === undefined || text === \"\" || ctx.stop.includes(text[0])) return ctx\n return { ...ctx, stop: Arr.sort([...ctx.stop.split(\"\"), text[0]], Order.String).join(\"\") }\n}\n\nconst at = <T>(ctx: Context<T>, key: PropertyKey): Context<T> => ({\n ...ctx,\n inherit: undefined,\n path: [...ctx.path, key]\n})\n\nconst where = <T>(ctx: Context<T>): string => `[${ctx.path.map(String).join(\", \")}]`\n\nconst unsupported = <T>(ast: SchemaAST.AST, ctx: Context<T>, what: string): never => {\n throw new TypeError(`ParserSchema: cannot derive a ${what} for ${ast._tag} at ${where(ctx)}; annotate it`)\n}\n\ninterface Resolved<T> {\n readonly grammar: Grammar\n readonly whitespace: boolean\n /** The context of what the node contains. */\n readonly inner: Context<T>\n}\n\n/** The node's grammar, with what its transformation passed down, and the context inside it. */\nconst resolve = <T>(ast: SchemaAST.AST, ctx: Context<T>): Resolved<T> => {\n const own = grammarOf(ast)\n const inherit = ctx.inherit\n const grammar: Grammar =\n inherit === undefined\n ? own\n : {\n ...own,\n separator: own.separator ?? inherit.separator,\n keySeparator: own.keySeparator ?? inherit.keySeparator\n }\n const whitespace = grammar.whitespace ?? ctx.whitespace\n return { grammar, whitespace, inner: { ...withStop(ctx, grammar.suffix), whitespace, inherit: undefined } }\n}\n\n/** The context of a transformation's encoded side, which the transformation's separators apply to. */\nconst encodedContext = <T>(grammar: Grammar, ctx: Context<T>): Context<T> => ({\n ...ctx,\n inherit: { separator: grammar.separator, keySeparator: grammar.keySeparator }\n})\n\n/**\n * The node with its chain of links ending at the type of its encoded side,\n * which is what the encoded side is parsed into and printed from.\n */\nconst linkTarget = (ast: SchemaAST.AST, links: SchemaAST.Encoding): SchemaAST.AST => {\n const last = links[links.length - 1]\n let target = SchemaAST.toType(ast)\n for (const link of links) {\n const source = link === last ? SchemaAST.toType(last.to) : link.to\n // SAFETY: `decodeTo` appends the link as it is, middleware included, as the schema's own links are\n target = SchemaAST.decodeTo(source, target, link.transformation as SchemaTransformation.Transformation<any, any>)\n }\n return target\n}\n\n/**\n * What is derived for a recursive schema: deriving it again in the same\n * context gives the same result, so the derivation ends.\n */\nconst recursive = <T>(ast: SchemaAST.Suspend, ctx: Context<T>, make: () => T): T => {\n const key = `${ctx.whitespace ? 1 : 0}${ctx.stop}`\n const known = ctx.recursions.find((r) => r.ast === ast && r.key === key)\n if (known !== undefined) return known.derived\n const derived = make()\n ctx.recursions.push({ ast, key, derived })\n return derived\n}\n\n/** The context for the items of a sequence: unannotated strings also stop at the separator. */\nconst itemContext = <T>(grammar: Grammar, ctx: Context<T>): Context<T> => withStop(ctx, grammar.separator)\n\n/** The rest element of an array schema, if any; elements after it are not supported. */\nconst restOf = <T>(ast: SchemaAST.Arrays, ctx: Context<T>, what: string): SchemaAST.AST | undefined => {\n const [head, ...after] = ast.rest\n // Elements after the rest would need the rest to stop short\n return Arr.isReadonlyArrayNonEmpty(after) ? unsupported(ast, ctx, what) : head\n}\n\n/** The contexts of an array schema's elements and its rest. */\nconst elementContexts = <T>(\n ast: SchemaAST.Arrays,\n rest: SchemaAST.AST | undefined,\n grammar: Grammar,\n ctx: Context<T>\n): ReadonlyArray<Context<T>> => {\n const n = ast.elements.length\n return ast.elements.map((_, i) => at(i < n - 1 || rest !== undefined ? itemContext(grammar, ctx) : ctx, i))\n}\n\n/** The contexts of a struct's fields, written in order. */\nconst fieldContexts = <T>(ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<T>): ReadonlyArray<Context<T>> => {\n const fields = ast.propertySignatures\n return fields.map((field, i) => at(i < fields.length - 1 ? itemContext(grammar, ctx) : ctx, field.name))\n}\n\nconst isKeyed = (ast: SchemaAST.Objects, grammar: Grammar): boolean =>\n grammar.keySeparator !== undefined || Arr.isReadonlyArrayNonEmpty(ast.indexSignatures)\n\nconst keySeparatorOf = <T>(grammar: Grammar, ctx: Context<T>): string => {\n if (grammar.keySeparator === undefined) {\n throw new TypeError(`ParserSchema: a record at ${where(ctx)} needs a keySeparator in its annotation`)\n }\n return grammar.keySeparator\n}\n\n/** The field name of a struct in keyed form: a string. */\nconst keyName = <T>(ast: SchemaAST.Objects, field: SchemaAST.PropertySignature, ctx: Context<T>, what: string) =>\n Predicate.isString(field.name) ? field.name : unsupported(ast, ctx, what)\n\nconst propertyName = (key: PropertyKey): string | symbol => (Predicate.isNumber(key) ? String(key) : key)\n\n/** Whether a check (as `Schema.Int` has) restricts numbers to integers. */\nconst isIntegral = (checks: SchemaAST.Checks | undefined): boolean =>\n checks !== undefined &&\n checks.some((check) =>\n check instanceof SchemaAST.FilterGroup\n ? isIntegral(check.checks)\n : check.annotations?.arbitraryConstraint?.[\"number\"] === \"integer\"\n )\n\ntype LiteralValue = SchemaAST.Literal[\"literal\"]\n\n/** Literals with the longest text first, so a literal is never cut short by one it starts with. */\nconst byLength = <A extends LiteralValue>(values: ReadonlyArray<A>): Array<A> =>\n Arr.sort(\n values,\n Order.mapInput(Order.Number, (value: A) => -String(value).length)\n )\n\nconst isPlainLiteral = (ast: SchemaAST.AST): ast is SchemaAST.Literal =>\n SchemaAST.isLiteral(ast) && ast.encoding === undefined && !isAnnotated(ast)\n\n/** The literals of a union of plain literals, longest first, or `undefined`. */\nconst plainLiterals = (ast: SchemaAST.Union): ReadonlyArray<LiteralValue> | undefined => {\n const literals = Arr.filter(ast.types, isPlainLiteral)\n return literals.length === ast.types.length ? byLength(literals.map((member) => member.literal)) : undefined\n}\n\nconst schemaError = (issue: SchemaIssue.Issue) => new Schema.SchemaError(issue)\n\nconst decoder = (schema: Schema.ConstraintDecoder<unknown>) => Schema.decodeUnknownResult(schema)\n\n/** Decodes into the type of `ast`, checks included. */\nconst typeDecoder = (ast: SchemaAST.AST) => decoder(Schema.make<Schema.Codec<unknown>>(SchemaAST.toType(ast)))\n\n// -----------------------------------------------------------------------------\n// Parsers\n// -----------------------------------------------------------------------------\n\ntype AnyParser = Parser<any, Schema.SchemaError, never, string>\n\ntype ForeignParser = Parser<unknown, unknown, never, string>\n\nconst messageOf = (cause: unknown): string =>\n Predicate.isString(cause)\n ? cause\n : Predicate.hasProperty(cause, \"message\") && Predicate.isString(cause.message)\n ? cause.message\n : String(cause)\n\n/** A parser whose failures' causes are `SchemaError`s, as {@link toParser}'s are. */\nconst asSchemaErrors = (parser: ForeignParser): AnyParser =>\n P.mapError(parser, (cause) =>\n cause instanceof Schema.SchemaError\n ? cause\n : schemaError(new SchemaIssue.InvalidValue({ message: messageOf(cause) }))\n )\n\n/** Literal text, with optional whitespace around it. */\nconst text = (s: string, ws: boolean): AnyParser =>\n ws ? P.delimited(Ascii.multispace0, Token.literal(s), Ascii.multispace0) : Token.literal(s)\n\nconst derive = (ast: SchemaAST.AST, ctx: Context<AnyParser>): AnyParser => {\n const { grammar, inner, whitespace } = resolve(ast, ctx)\n let parser: AnyParser\n if (grammar.parser !== undefined) parser = P.tryMap(asSchemaErrors(grammar.parser), typeDecoder(ast))\n else if (ast.encoding !== undefined) parser = decoded(ast, ast.encoding, grammar, inner)\n else parser = checked(ast, structural(ast, grammar, inner))\n if (grammar.prefix !== undefined) parser = P.preceded(text(grammar.prefix, whitespace), parser)\n if (grammar.suffix !== undefined) parser = P.terminated(parser, text(grammar.suffix, whitespace))\n // A check's own `expected` describes the check, not the text\n const label = lookup(ast, \"identifier\") ?? ast.annotations?.expected\n return Predicate.isString(label) ? P.expected(parser, label) : parser\n}\n\n/** Runs the checks on `ast` (its filters) on the parser's output. */\nconst checked = (ast: SchemaAST.AST, parser: AnyParser): AnyParser =>\n ast.checks === undefined ? parser : P.tryMap(parser, decoder(Schema.Unknown.check(...ast.checks)))\n\n/**\n * Parses the encoded side of a transformation and decodes it. The encoded\n * side is parsed into its own type, so the last link decodes from that type\n * rather than from the fully encoded form.\n */\nconst decoded = (\n ast: SchemaAST.AST,\n links: SchemaAST.Encoding,\n grammar: Grammar,\n ctx: Context<AnyParser>\n): AnyParser => {\n const from = derive(links[links.length - 1].to, encodedContext(grammar, ctx))\n return P.tryMap(from, decoder(Schema.make<Schema.Codec<unknown>>(linkTarget(ast, links))))\n}\n\nconst structural = (ast: SchemaAST.AST, grammar: Grammar, ctx: Context<AnyParser>): AnyParser =>\n Match.valueTags(ast, {\n String: () => unannotatedString(ctx, 1),\n Number: (number) => (isIntegral(number.checks) ? integer : Ascii.float),\n BigInt: () => Ascii.decBigInt,\n Boolean: () => P.alt(P.as(Token.literal(\"true\"), true), P.as(Token.literal(\"false\"), false)),\n Null: () => P.as(Token.literal(\"null\"), null),\n Undefined: () => P.succeed(undefined),\n Void: () => P.succeed(undefined),\n Never: () => P.reject,\n Literal: (lit) => literal(lit.literal),\n Enum: (e) => P.alt(...byLength(e.enums.map(([, value]) => value)).map(literal)),\n TemplateLiteral: (template) => templateLiteral(template, ctx),\n Arrays: (arrays) => sequenceOf(arrays, grammar, ctx),\n Objects: (objects) =>\n isKeyed(objects, grammar) ? keyed(objects, grammar, ctx) : positional(objects, grammar, ctx),\n Union: (union) => alternatives(union, ctx),\n Suspend: (suspend) => recursive(suspend, ctx, () => P.suspend(() => derive(suspend.thunk(), ctx))),\n Declaration: (other) => unsupported(other, ctx, \"parser\"),\n Unknown: (other) => unsupported(other, ctx, \"parser\"),\n Any: (other) => unsupported(other, ctx, \"parser\"),\n Symbol: (other) => unsupported(other, ctx, \"parser\"),\n UniqueSymbol: (other) => unsupported(other, ctx, \"parser\"),\n ObjectKeyword: (other) => unsupported(other, ctx, \"parser\")\n })\n\nconst unannotatedString = (ctx: Context<AnyParser>, min: number): AnyParser => {\n const s = Token.takeTill(ctx.stop, { min })\n // Leading whitespace is skipped first, so it doesn't count towards `min`\n return ctx.whitespace\n ? P.preceded(\n Ascii.multispace0,\n P.map(s, (value) => value.trimEnd())\n )\n : s\n}\n\nconst integer: AnyParser = /*#__PURE__*/ asSchemaErrors(Ascii.decInt)\n\nconst literal = (value: LiteralValue): AnyParser => P.as(Token.literal(String(value)), value)\n\nconst templateLiteral = (ast: SchemaAST.TemplateLiteral, ctx: Context<AnyParser>): AnyParser =>\n P.taken(\n P.seq(\n ...ast.parts.map((part, i) => {\n const next = ast.parts[i + 1]\n const partCtx = next !== undefined && SchemaAST.isLiteral(next) ? withStop(ctx, String(next.literal)) : ctx\n // An interpolated string may be empty\n return SchemaAST.isString(part) && !isAnnotated(part)\n ? unannotatedString(partCtx, 0)\n : derive(part, at(partCtx, i))\n })\n )\n )\n\nconst alternatives = (ast: SchemaAST.Union, ctx: Context<AnyParser>): AnyParser => {\n const literals = plainLiterals(ast)\n return literals !== undefined\n ? P.alt(...literals.map(literal))\n : P.alt(...ast.types.map((member) => derive(member, ctx)))\n}\n\ninterface Item {\n readonly parser: AnyParser\n readonly optional: boolean\n}\n\ntype Values = Parser<Array<unknown>, Schema.SchemaError, never, string>\n\n/**\n * Parses `items` in order, then any number of `rest`, with `separator`\n * between the ones present. The output has the value of item `i` at index\n * `i` (a hole when an optional item is missing), then the rest.\n */\nconst sequence = (\n items: ReadonlyArray<Item>,\n rest: AnyParser | undefined,\n separator: AnyParser | undefined\n): Values => {\n const n = items.length\n const tail = (needSeparator: boolean): Values => {\n if (rest === undefined) return P.sync(() => new Array(n))\n const values =\n separator === undefined\n ? P.repeat(rest)\n : needSeparator\n ? P.repeat(P.preceded(separator, rest))\n : P.separated(rest, separator)\n return P.map(values, (xs) => {\n const out = new Array(n)\n for (let j = 0; j < xs.length; j++) out[n + j] = xs[j]\n return out\n })\n }\n // One parser per position and whether a separator comes first, at index `2 * i + needSeparator`\n const memo: Array<Values | undefined> = []\n const from = (i: number, needSeparator: boolean): Values => {\n const key = i * 2 + (needSeparator ? 1 : 0)\n const known = memo[key]\n if (known !== undefined) return known\n let parser: Values\n if (i === n) parser = tail(needSeparator)\n else {\n const item = items[i]\n const head = needSeparator && separator !== undefined ? P.preceded(separator, item.parser) : item.parser\n const present = P.map(P.seq(head, from(i + 1, true)), ([value, out]) => {\n out[i] = value\n return out\n })\n parser = item.optional ? P.alt(present, from(i + 1, needSeparator)) : present\n }\n memo[key] = parser\n return parser\n }\n return from(0, false)\n}\n\nconst separatorOf = (grammar: Grammar, ctx: Context<AnyParser>): AnyParser | undefined =>\n grammar.separator === undefined ? undefined : text(grammar.separator, ctx.whitespace)\n\nconst sequenceOf = (ast: SchemaAST.Arrays, grammar: Grammar, ctx: Context<AnyParser>): AnyParser => {\n const head = restOf(ast, ctx, \"parser\")\n const contexts = elementContexts(ast, head, grammar, ctx)\n const items = ast.elements.map((element, i) => ({\n parser: derive(element, contexts[i]),\n optional: SchemaAST.isOptional(element)\n }))\n const rest = head === undefined ? undefined : derive(head, at(itemContext(grammar, ctx), items.length))\n // Optional elements come last, so the present values are the first ones\n return P.map(sequence(items, rest, separatorOf(grammar, ctx)), (out) => out.filter((_, i) => i in out))\n}\n\nconst positional = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<AnyParser>): AnyParser => {\n const fields = ast.propertySignatures\n const contexts = fieldContexts(ast, grammar, ctx)\n const items = fields.map((field, i) => ({\n parser: derive(field.type, contexts[i]),\n optional: SchemaAST.isOptional(field.type)\n }))\n return P.map(sequence(items, undefined, separatorOf(grammar, ctx)), (out) =>\n Record.fromEntries(fields.flatMap((field, i) => (i in out ? [[propertyName(field.name), out[i]] as const] : [])))\n )\n}\n\ntype Entry = readonly [key: string | symbol, value: unknown, known: boolean]\n\nconst keyed = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<AnyParser>): AnyParser => {\n const keySeparator = keySeparatorOf(grammar, ctx)\n const between = text(keySeparator, ctx.whitespace)\n const valueCtx = itemContext(grammar, ctx)\n const known = ast.propertySignatures.map((field): AnyParser => {\n const name = keyName(ast, field, ctx, \"parser\")\n const value = derive(field.type, at(valueCtx, name))\n return P.map(P.preceded(P.seq(Token.literal(name), between), value), (v): Entry => [name, v, true])\n })\n const indexed = ast.indexSignatures.map((signature): AnyParser => {\n const key = derive(signature.parameter, at(withStop(ctx, keySeparator), \"<key>\"))\n const value = derive(signature.type, at(valueCtx, \"<value>\"))\n return P.map(P.separatedPair(key, between, value), ([k, v]): Entry => [propertyName(k), v, false])\n })\n const entry = P.alt(...known, ...indexed)\n const separator = separatorOf(grammar, ctx)\n const entries = separator === undefined ? P.repeat(entry) : P.separated(entry, separator)\n // A missing field fails where its entry could have been, as a syntax error, so a\n // failure further in (the entry that ended the repetition early) is reported instead\n const missing = ast.propertySignatures.map((field) =>\n P.expected(P.reject, describeLiteral(`${String(field.name)}${keySeparator}`))\n )\n return P.flatMap(\n P.tryMap(entries, (es: ReadonlyArray<Entry>) => assemble(ast, es)),\n ([value, absent]) => (absent === undefined ? P.succeed(value) : missing[absent])\n )\n}\n\n/**\n * Builds the object from its entries, declared fields first, rejecting\n * duplicate keys. Also returns the index of the first required field\n * missing, if any.\n */\nconst assemble = (\n ast: SchemaAST.Objects,\n entries: ReadonlyArray<Entry>\n): Result.Result<readonly [object, number | undefined], Schema.SchemaError> => {\n const values = MutableHashMap.empty<string | symbol, unknown>()\n for (const [key, value] of entries) {\n if (MutableHashMap.has(values, key)) {\n return Result.fail(\n schemaError(new SchemaIssue.Pointer([key], new SchemaIssue.InvalidValue({ message: \"Duplicate key\" })))\n )\n }\n MutableHashMap.set(values, key, value)\n }\n const out: Array<readonly [string | symbol, unknown]> = []\n let absent: number | undefined\n ast.propertySignatures.forEach((field, i) => {\n const name = propertyName(field.name)\n const value = MutableHashMap.get(values, name)\n if (Option.isSome(value)) out.push([name, value.value])\n else if (absent === undefined && !SchemaAST.isOptional(field.type)) absent = i\n })\n for (const [key, value, isKnown] of entries) if (!isKnown) out.push([key, value])\n return Result.succeed([Record.fromEntries(out), absent])\n}\n\n// -----------------------------------------------------------------------------\n// Printers\n// -----------------------------------------------------------------------------\n\n/**\n * Writes the text of a value, already validated against the schema's type,\n * to `out`, or returns why it cannot be written.\n */\ntype Printer = (value: any, out: Array<string>) => SchemaIssue.Issue | undefined\n\n/** The issue for a value that cannot be written at the node `ctx` is at. */\nconst unwritable = <T>(ctx: Context<T>, message: string, value: unknown): SchemaIssue.Issue => {\n const issue = new SchemaIssue.InvalidValue({ message }, value, { reportInput: true })\n return Arr.isReadonlyArrayNonEmpty(ctx.path) ? new SchemaIssue.Pointer(ctx.path, issue) : issue\n}\n\nconst writing =\n (show: (value: any) => string): Printer =>\n (value, out) => {\n out.push(show(value))\n return undefined\n }\n\nconst nothing: Printer = (_, __) => undefined\n\nconst printerOf = (ast: SchemaAST.AST, ctx: Context<Printer>): Printer => {\n const { grammar, inner } = resolve(ast, ctx)\n let print: Printer\n if (grammar.print !== undefined) print = writing(grammar.print)\n else if (grammar.parser !== undefined) print = unprintable(ctx)\n else if (ast.encoding !== undefined) print = encoded(ast, ast.encoding, grammar, inner)\n else print = printerFor(ast, grammar, inner)\n const prefix = grammar.prefix\n const suffix = grammar.suffix\n if (prefix === undefined && suffix === undefined) return print\n const inside = print\n return (value, out) => {\n if (prefix !== undefined) out.push(prefix)\n const issue = inside(value, out)\n if (suffix !== undefined) out.push(suffix)\n return issue\n }\n}\n\nconst unprintable =\n (ctx: Context<Printer>): Printer =>\n (value) =>\n unwritable(ctx, \"This value has a parser in its annotation but no print, so it cannot be written\", value)\n\n/** Encodes a transformation's value and prints its encoded side. */\nconst encoded = (ast: SchemaAST.AST, links: SchemaAST.Encoding, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const to = printerOf(links[links.length - 1].to, encodedContext(grammar, ctx))\n const encode = Schema.encodeUnknownResult(Schema.make<Schema.Codec<unknown, unknown>>(linkTarget(ast, links)))\n return (value, out) => {\n const result = encode(value)\n return Result.isSuccess(result) ? to(result.success, out) : result.failure.issue\n }\n}\n\nconst printerFor = (ast: SchemaAST.AST, grammar: Grammar, ctx: Context<Printer>): Printer =>\n Match.valueTags(ast, {\n String: () => stringPrinter(ctx),\n Number: () => writing(String),\n BigInt: () => writing(String),\n Boolean: () => writing(String),\n Null: () => writing(String),\n Undefined: () => nothing,\n Void: () => nothing,\n Never: () => nothing,\n Literal: () => writing(String),\n Enum: () => writing(String),\n TemplateLiteral: () => writing(String),\n Arrays: (arrays) => arraysPrinter(arrays, grammar, ctx),\n Objects: (objects) =>\n isKeyed(objects, grammar) ? keyedPrinter(objects, grammar, ctx) : positionalPrinter(objects, grammar, ctx),\n Union: (union) => unionPrinter(union, ctx),\n Suspend: (suspend) =>\n recursive(suspend, ctx, () => {\n let print: Printer | undefined\n return (value, out) => (print ??= printerOf(suspend.thunk(), ctx))(value, out)\n }),\n Declaration: (other) => unsupported(other, ctx, \"printer\"),\n Unknown: (other) => unsupported(other, ctx, \"printer\"),\n Any: (other) => unsupported(other, ctx, \"printer\"),\n Symbol: (other) => unsupported(other, ctx, \"printer\"),\n UniqueSymbol: (other) => unsupported(other, ctx, \"printer\"),\n ObjectKeyword: (other) => unsupported(other, ctx, \"printer\")\n })\n\n/**\n * Writes a string as an unannotated string is parsed: refusing one that\n * would not read back, being empty or holding a character that ends it.\n */\nconst stringPrinter =\n (ctx: Context<Printer>): Printer =>\n (value: string, out) => {\n if (value === \"\") return unwritable(ctx, \"An empty string cannot be written here\", value)\n const stop = Arr.findFirst(Array.from(ctx.stop), (c) => value.includes(c))\n if (Option.isSome(stop)) {\n return unwritable(ctx, `A string containing ${describeLiteral(stop.value)} cannot be written here`, value)\n }\n if (ctx.whitespace && value.trim() !== value) {\n return unwritable(ctx, \"A string with whitespace around it cannot be written here\", value)\n }\n out.push(value)\n return undefined\n }\n\n/** Writes values with a separator between them, stopping at the first that cannot be written. */\nconst writeAll = (\n writes: ReadonlyArray<(out: Array<string>) => SchemaIssue.Issue | undefined>,\n separator: string,\n out: Array<string>\n): SchemaIssue.Issue | undefined => {\n for (let i = 0; i < writes.length; i++) {\n if (i > 0) out.push(separator)\n const issue = writes[i](out)\n if (issue !== undefined) return issue\n }\n return undefined\n}\n\nconst arraysPrinter = (ast: SchemaAST.Arrays, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const head = restOf(ast, ctx, \"printer\")\n const contexts = elementContexts(ast, head, grammar, ctx)\n const elements = ast.elements.map((element, i) => printerOf(element, contexts[i]))\n const rest = head === undefined ? nothing : printerOf(head, at(itemContext(grammar, ctx), elements.length))\n const separator = grammar.separator ?? \"\"\n return (value: ReadonlyArray<unknown>, out) =>\n writeAll(\n value.map((element, i) => (o: Array<string>) => (elements[i] ?? rest)(element, o)),\n separator,\n out\n )\n}\n\nconst positionalPrinter = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const contexts = fieldContexts(ast, grammar, ctx)\n const fields = ast.propertySignatures.map((field, i) => ({\n name: propertyName(field.name),\n print: printerOf(field.type, contexts[i])\n }))\n const separator = grammar.separator ?? \"\"\n return (value: Record.ReadonlyRecord<string | symbol, unknown>, out) =>\n writeAll(\n fields\n .filter((field) => Record.has(value, field.name))\n .map((field) => (o: Array<string>) => field.print(value[field.name], o)),\n separator,\n out\n )\n}\n\nconst keyedPrinter = (ast: SchemaAST.Objects, grammar: Grammar, ctx: Context<Printer>): Printer => {\n const keySeparator = keySeparatorOf(grammar, ctx)\n const valueCtx = itemContext(grammar, ctx)\n const fields = ast.propertySignatures.map((field) => {\n const name = keyName(ast, field, ctx, \"printer\")\n return { name, print: printerOf(field.type, at(valueCtx, name)) }\n })\n const names = fields.map((field) => field.name)\n const indexed = ast.indexSignatures.map((signature) => ({\n is: Schema.is(Schema.make<Schema.Top>(SchemaAST.toType(signature.parameter))),\n key: printerOf(signature.parameter, at(withStop(ctx, keySeparator), \"<key>\")),\n value: printerOf(signature.type, at(valueCtx, \"<value>\"))\n }))\n const entry =\n (key: Printer, print: Printer, k: unknown, v: unknown) =>\n (out: Array<string>): SchemaIssue.Issue | undefined =>\n key(k, out) ?? (out.push(keySeparator), print(v, out))\n return (value: Record.ReadonlyRecord<string, unknown>, out) => {\n const writes = fields\n .filter((field) => Record.has(value, field.name))\n .map((field) => entry(writing(String), field.print, field.name, value[field.name]))\n for (const key of Record.keys(value)) {\n const signature = names.includes(key) ? undefined : indexed.find((s) => s.is(key))\n if (signature !== undefined) writes.push(entry(signature.key, signature.value, key, value[key]))\n }\n return writeAll(writes, grammar.separator ?? \"\", out)\n }\n}\n\n/** Writes a union's value with the first member it belongs to that can write it. */\nconst unionPrinter = (ast: SchemaAST.Union, ctx: Context<Printer>): Printer => {\n if (plainLiterals(ast) !== undefined) return writing(String)\n const members = ast.types.map((member) => ({\n is: Schema.is(Schema.make<Schema.Top>(SchemaAST.toType(member))),\n print: printerOf(member, ctx)\n }))\n return (value, out) => {\n let issue: SchemaIssue.Issue | undefined\n for (const member of members) {\n if (!member.is(value)) continue\n const mark = out.length\n issue = member.print(value, out)\n if (issue === undefined) return undefined\n out.length = mark\n }\n return issue ?? unwritable(ctx, \"No member of the union can write this value\", value)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,MAAa,gBAAgB;AAsC7B,MAAM,cACA,YACH,UACC,OAAO,QAAQ,OAAO,KAAK,CAAC;AAEhC,MAAM,cACJ,QACA,QACA,WAEA,OAAO,OAAO,KACZ,OAAO,SACL,QACA,qBAAqB,gBAAsC;CACzD,SAAS,OAAO,iBAAiB;EAC/B,MAAM,SAAS,EAAE,MAAM,QAAQ,KAAK;EACpC,OAAO,OAAO,UAAU,MAAM,IAC1B,OAAO,QAAQ,OAAO,OAAO,IAC7B,OAAO,KAAK,IAAI,YAAY,aAAa,EAAE,SAAS,OAAO,QAAQ,QAAQ,GAAG,OAAO,YAAY,CAAC;CACxG;CACA,SAAS,OAAO,iBAAiB;EAC/B,IAAI,WAAW,KAAA,GACb,OAAO,OAAO,KAAK,IAAI,YAAY,UAAU,EAAE,SAAS,4BAA4B,GAAG,OAAO,YAAY,CAAC;EAE7G,OAAO,OAAO,WAAW,OAAO,KAAK,CAAC;CACxC;AACF,CAAC,CACH,CACF;;;;;;;;AASF,MAAa,QAAc,QAAqC,YAC9D,WACE,OAAO,SACJ,OAAgB,MACjB,SAAS,gBAAgB,KAAA,IAAY,EAAE,aAAa,QAAQ,YAAY,IAAI,KAAA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Ac,GAAG,MAAM,KAAA,GAAW,OAAO,QAAQ,MAAM;CAC3D,MAAM,UAAU,IAAI,MAAM,KAAK,YAAY;EACzC,IAAI,OAAO,GAAG,OAAO,KAAiB,UAAU,OAAO,MAAM,CAAC,CAAC;EAC/D,OAAO,UAAU,QAAQ,GAAG;CAC9B,EAAE;CACF,QAAQ,OAAO,QAAQ;EACrB,IAAI;EACJ,KAAK,MAAM,UAAU,SAAS;GAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,GAAG;GACvB,MAAM,OAAO,IAAI;GACjB,QAAQ,OAAO,MAAM,OAAO,GAAG;GAC/B,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;GAChC,IAAI,SAAS;EACf;EACA,OAAO,SAAS,WAAW,KAAK,+CAA+C,KAAK;CACtF;AACF"}
@@ -11,12 +11,78 @@ import * as Stream from "effect/Stream";
11
11
  */
12
12
  export type Chunkable = string | Uint8Array | ReadonlyArray<unknown>;
13
13
  /**
14
- * Options for {@link parseMany}.
14
+ * The default `maxBufferSize` of {@link parseMany}, {@link parseAll},
15
+ * {@link parseReadable} and {@link parseResponse}: 64 MiB, counted in tokens
16
+ * of the input (UTF-16 code units of a string, bytes of a `Uint8Array`,
17
+ * elements of an array).
18
+ *
19
+ * @since 0.6.0
20
+ * @category constants
21
+ */
22
+ export declare const defaultMaxBufferSize: number;
23
+ declare const BufferLimitError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
24
+ readonly _tag: "BufferLimitError";
25
+ } & Readonly<A>;
26
+ /**
27
+ * A stream runner would have buffered more than its `maxBufferSize`: `size`
28
+ * tokens against a limit of `limit`. It is a different failure from a
29
+ * `ParseError`: the input is too large, not malformed (an HTTP server
30
+ * answers 413 for the one and 400 for the other), and nothing of the input
31
+ * is attached to it.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { Effect, Stream } from "effect"
36
+ * import { Parser, ParserStream, Token } from "@thomasfosterau/effect-parse"
37
+ *
38
+ * const line = Parser.terminated(Token.takeTill("\n"), Token.literal("\n"))
39
+ *
40
+ * Stream.make("no newline, ", "ever").pipe(
41
+ * ParserStream.parseMany(line, { maxBufferSize: 8 }),
42
+ * Stream.runCollect,
43
+ * Effect.catchTag("BufferLimitError", (e) => Effect.succeed(`too large: ${e.size} > ${e.limit}`))
44
+ * )
45
+ * ```
46
+ *
47
+ * @since 0.6.0
48
+ * @category errors
49
+ */
50
+ export declare class BufferLimitError extends /*#__PURE__*/ BufferLimitError_base<{
51
+ /** The `maxBufferSize` in force, in tokens. */
52
+ readonly limit: number;
53
+ /** The tokens the runner held, or was about to hold (for `parseResponse`, the declared `Content-Length`). */
54
+ readonly size: number;
55
+ }> {
56
+ get message(): string;
57
+ }
58
+ /**
59
+ * The limit on buffered input that the stream runners share.
60
+ *
61
+ * @since 0.6.0
62
+ * @category models
63
+ */
64
+ export interface BufferOptions {
65
+ /**
66
+ * The most tokens a runner buffers (UTF-16 code units of a string, bytes
67
+ * of a `Uint8Array`, elements of an array) before it fails with a
68
+ * {@link BufferLimitError}. Defaults to {@link defaultMaxBufferSize}
69
+ * (64 MiB); `Infinity` turns the limit off.
70
+ *
71
+ * {@link parseMany} counts the input it has not consumed yet, which is one
72
+ * unfinished value: complete values in a chunk are parsed and emitted
73
+ * first, whatever the chunk's size. {@link parseAll},
74
+ * {@link parseReadable} and {@link parseResponse} hold the whole input, so
75
+ * they count all of it.
76
+ */
77
+ readonly maxBufferSize?: number | undefined;
78
+ }
79
+ /**
80
+ * Options for {@link parseMany} and {@link parseAll}.
15
81
  *
16
82
  * @since 0.1.0
17
83
  * @category models
18
84
  */
19
- export interface ParseManyOptions<I> {
85
+ export interface ParseManyOptions<I> extends BufferOptions {
20
86
  /** The empty input, used to initialise the buffer (inferred from the first chunk if omitted). */
21
87
  readonly empty?: Source<I> | undefined;
22
88
  }
@@ -30,15 +96,41 @@ export interface ParseManyOptions<I> {
30
96
  *
31
97
  * A parser compiled with the `Compiler` module runs compiled, with the
32
98
  * build that handles partial input (see `Parser.run`); a value that fails
33
- * or needs more input is parsed again interpreted, so errors and
34
- * `Incomplete` are the interpreter's.
99
+ * is parsed again interpreted, so errors are the interpreter's. A value
100
+ * cut short by its chunk is not: compiled code reports `Incomplete` where
101
+ * the interpreter does.
102
+ *
103
+ * **Untrusted streams.** The input not yet consumed (one unfinished value)
104
+ * is limited to `maxBufferSize` tokens, 64 MiB by default
105
+ * ({@link defaultMaxBufferSize}); past it the stream fails with a
106
+ * {@link BufferLimitError}, so a peer that never sends the delimiter cannot
107
+ * grow the buffer without bound. An unfinished value is parsed again from
108
+ * its start when more input arrives. Up to 64 KiB that happens on every
109
+ * chunk; a larger one is retried only once the buffer has grown by an
110
+ * eighth, so the work stays linear in its size. The cost: the last chunk of
111
+ * a value larger than 64 KiB may not complete it in the output until more
112
+ * input arrives or the stream ends, when everything left is parsed.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * import { Effect, Stream } from "effect"
117
+ * import { Ascii, Parser, ParserStream, Token } from "@thomasfosterau/effect-parse"
118
+ *
119
+ * const line = Parser.terminated(Ascii.decInt, Token.literal("\n"))
120
+ *
121
+ * const program = Stream.make("1\n2", "3\n", "4\n").pipe(
122
+ * ParserStream.parseMany(line, { maxBufferSize: 1024 }),
123
+ * Stream.runCollect
124
+ * )
125
+ * // Effect.runSync(program) => [1, 23, 4]
126
+ * ```
35
127
  *
36
128
  * @since 0.1.0
37
129
  * @category combinators
38
130
  */
39
131
  export declare const parseMany: {
40
- <A, E, R, I extends Chunkable>(parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): <E0, R0>(self: Stream.Stream<Source<I>, E0, R0>) => Stream.Stream<A, E0 | ParseError.ParseError<E>, R0 | R>;
41
- <I extends Chunkable, E0, R0, A, E, R>(self: Stream.Stream<Source<NoInfer<I>>, E0, R0>, parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): Stream.Stream<A, E0 | ParseError.ParseError<E>, R0 | R>;
132
+ <A, E, R, I extends Chunkable>(parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): <E0, R0>(self: Stream.Stream<Source<I>, E0, R0>) => Stream.Stream<A, E0 | ParseError.ParseError<E> | BufferLimitError, R0 | R>;
133
+ <I extends Chunkable, E0, R0, A, E, R>(self: Stream.Stream<Source<NoInfer<I>>, E0, R0>, parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): Stream.Stream<A, E0 | ParseError.ParseError<E> | BufferLimitError, R0 | R>;
42
134
  };
43
135
  /**
44
136
  * Parses an entire stream of chunks as a single complete input.
@@ -59,12 +151,17 @@ export declare const parseMany: {
59
151
  * callbacks should be pure: the elements parsed before a checkpoint are
60
152
  * not parsed again, and on failure everything is parsed again.
61
153
  *
154
+ * The whole input is held until the stream ends, so it is limited to
155
+ * `maxBufferSize` tokens (64 MiB by default, see {@link BufferOptions}):
156
+ * a stream that would exceed it fails with a {@link BufferLimitError}
157
+ * before the chunk that crosses the limit is buffered.
158
+ *
62
159
  * @since 0.1.0
63
160
  * @category combinators
64
161
  */
65
162
  export declare const parseAll: {
66
- <A, E, R, I extends Chunkable>(parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): <E0, R0>(self: Stream.Stream<Source<I>, E0, R0>) => Effect.Effect<A, E0 | ParseError.ParseError<E>, R0 | R>;
67
- <I extends Chunkable, E0, R0, A, E, R>(self: Stream.Stream<Source<NoInfer<I>>, E0, R0>, parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): Effect.Effect<A, E0 | ParseError.ParseError<E>, R0 | R>;
163
+ <A, E, R, I extends Chunkable>(parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): <E0, R0>(self: Stream.Stream<Source<I>, E0, R0>) => Effect.Effect<A, E0 | ParseError.ParseError<E> | BufferLimitError, R0 | R>;
164
+ <I extends Chunkable, E0, R0, A, E, R>(self: Stream.Stream<Source<NoInfer<I>>, E0, R0>, parser: Parser<A, E, R, I>, options?: ParseManyOptions<I>): Effect.Effect<A, E0 | ParseError.ParseError<E> | BufferLimitError, R0 | R>;
68
165
  };
69
166
  declare const ReadError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
70
167
  readonly _tag: "ReadError";
@@ -83,7 +180,10 @@ export declare class ReadError extends /*#__PURE__*/ ReadError_base<{
83
180
  * Parses a web `ReadableStream` of bytes, such as the body of a `fetch`
84
181
  * response, incrementally (see {@link parseAll}): the bytes are parsed as
85
182
  * they arrive, without waiting for the end of the stream or decoding them
86
- * first. Use a byte parser, e.g. one built from `Text.utf8`.
183
+ * first. Use a byte parser, e.g. one built from `Text.utf8`. The stream is
184
+ * limited to `maxBufferSize` bytes (64 MiB by default, see
185
+ * {@link BufferOptions}), past which it fails with a
186
+ * {@link BufferLimitError}.
87
187
  *
88
188
  * @example
89
189
  * ```ts
@@ -101,14 +201,20 @@ export declare class ReadError extends /*#__PURE__*/ ReadError_base<{
101
201
  * @category combinators
102
202
  */
103
203
  export declare const parseReadable: {
104
- <A, E, R>(parser: Parser<A, E, R, Uint8Array>): (self: ReadableStream<BinaryInput>) => Effect.Effect<A, ParseError.ParseError<E> | ReadError, R>;
105
- <A, E, R>(self: ReadableStream<BinaryInput>, parser: Parser<A, E, R, Uint8Array>): Effect.Effect<A, ParseError.ParseError<E> | ReadError, R>;
204
+ <A, E, R>(parser: Parser<A, E, R, Uint8Array>, options?: BufferOptions): (self: ReadableStream<BinaryInput>) => Effect.Effect<A, ParseError.ParseError<E> | ReadError | BufferLimitError, R>;
205
+ <A, E, R>(self: ReadableStream<BinaryInput>, parser: Parser<A, E, R, Uint8Array>, options?: BufferOptions): Effect.Effect<A, ParseError.ParseError<E> | ReadError | BufferLimitError, R>;
106
206
  };
107
207
  /**
108
208
  * Parses the body of a `fetch` `Response` incrementally, as it downloads
109
209
  * (see {@link parseReadable}). A response without a body is parsed as empty
110
210
  * input. The status is not checked.
111
211
  *
212
+ * The body is limited to `maxBufferSize` bytes (64 MiB by default, see
213
+ * {@link BufferOptions}). A response whose `Content-Length` already exceeds
214
+ * the limit fails with a {@link BufferLimitError} before any of the body is
215
+ * read; the limit is enforced on the bytes read as well, since the header
216
+ * may be absent or wrong.
217
+ *
112
218
  * @example
113
219
  * ```ts
114
220
  * import { Effect } from "effect"
@@ -117,15 +223,17 @@ export declare const parseReadable: {
117
223
  * const lines = Parser.separated(Text.utf8.tillLineEnding, Text.utf8.lineEnding)
118
224
  *
119
225
  * const response = await fetch("https://example.com/log.txt")
120
- * const value = await Effect.runPromise(ParserStream.parseResponse(response, lines))
226
+ * const value = await Effect.runPromise(
227
+ * ParserStream.parseResponse(response, lines, { maxBufferSize: 8 * 1024 * 1024 })
228
+ * )
121
229
  * ```
122
230
  *
123
231
  * @since 0.1.0
124
232
  * @category combinators
125
233
  */
126
234
  export declare const parseResponse: {
127
- <A, E, R>(parser: Parser<A, E, R, Uint8Array>): (self: Response) => Effect.Effect<A, ParseError.ParseError<E> | ReadError, R>;
128
- <A, E, R>(self: Response, parser: Parser<A, E, R, Uint8Array>): Effect.Effect<A, ParseError.ParseError<E> | ReadError, R>;
235
+ <A, E, R>(parser: Parser<A, E, R, Uint8Array>, options?: BufferOptions): (self: Response) => Effect.Effect<A, ParseError.ParseError<E> | ReadError | BufferLimitError, R>;
236
+ <A, E, R>(self: Response, parser: Parser<A, E, R, Uint8Array>, options?: BufferOptions): Effect.Effect<A, ParseError.ParseError<E> | ReadError | BufferLimitError, R>;
129
237
  };
130
238
  export {};
131
239
  //# sourceMappingURL=ParserStream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ParserStream.d.ts","names":[],"sources":["../src/ParserStream.ts"],"mappings":";;;;;;;;;;;YA+CY,qBAAqB,aAAa;;;;;;;iBAgC7B,iBAAiB;;WAEvB,QAAQ,OAAO;;;;;;;;;;;;;;;;;;qBAmBb;GACV,GAAG,GAAG,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