@thomasfosterau/effect-parse 0.3.0 → 0.4.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 (137) hide show
  1. package/dist/Ascii.d.ts +0 -2
  2. package/dist/Ascii.d.ts.map +1 -1
  3. package/dist/Ascii.js +6 -6
  4. package/dist/Ascii.js.map +1 -1
  5. package/dist/Binary.d.ts +0 -2
  6. package/dist/Binary.d.ts.map +1 -1
  7. package/dist/Binary.js +1 -2
  8. package/dist/Bits.d.ts +0 -2
  9. package/dist/Bits.d.ts.map +1 -1
  10. package/dist/Bits.js +2 -3
  11. package/dist/Bits.js.map +1 -1
  12. package/dist/Compiler.d.ts +0 -2
  13. package/dist/Compiler.d.ts.map +1 -1
  14. package/dist/Compiler.js +1 -2
  15. package/dist/Encoding.d.ts +0 -2
  16. package/dist/Encoding.d.ts.map +1 -1
  17. package/dist/Encoding.js +1 -2
  18. package/dist/Expression.d.ts +0 -2
  19. package/dist/Expression.d.ts.map +1 -1
  20. package/dist/Expression.js +44 -8
  21. package/dist/Expression.js.map +1 -1
  22. package/dist/Input.d.ts +32 -4
  23. package/dist/Input.d.ts.map +1 -1
  24. package/dist/Input.js +47 -8
  25. package/dist/Input.js.map +1 -1
  26. package/dist/Nom.d.ts +0 -2
  27. package/dist/Nom.d.ts.map +1 -1
  28. package/dist/Nom.js +1 -2
  29. package/dist/ParseError.d.ts +0 -2
  30. package/dist/ParseError.d.ts.map +1 -1
  31. package/dist/ParseError.js +6 -9
  32. package/dist/ParseError.js.map +1 -1
  33. package/dist/Parser.d.ts +2 -2
  34. package/dist/Parser.d.ts.map +1 -1
  35. package/dist/Parser.js +26 -24
  36. package/dist/Parser.js.map +1 -1
  37. package/dist/ParserSchema.d.ts +0 -2
  38. package/dist/ParserSchema.d.ts.map +1 -1
  39. package/dist/ParserSchema.js +2 -3
  40. package/dist/ParserStream.d.ts +0 -2
  41. package/dist/ParserStream.d.ts.map +1 -1
  42. package/dist/ParserStream.js +15 -9
  43. package/dist/ParserStream.js.map +1 -1
  44. package/dist/Syntax.d.ts +0 -2
  45. package/dist/Syntax.d.ts.map +1 -1
  46. package/dist/Syntax.js +13 -11
  47. package/dist/Syntax.js.map +1 -1
  48. package/dist/Text.d.ts +0 -2
  49. package/dist/Text.d.ts.map +1 -1
  50. package/dist/Text.js +1 -2
  51. package/dist/Token.d.ts +0 -2
  52. package/dist/Token.d.ts.map +1 -1
  53. package/dist/Token.js +1 -2
  54. package/dist/internal/compiler/closure.d.ts +5 -2
  55. package/dist/internal/compiler/closure.d.ts.map +1 -1
  56. package/dist/internal/compiler/closure.js +160 -92
  57. package/dist/internal/compiler/closure.js.map +1 -1
  58. package/dist/internal/compiler/entries.d.ts +0 -2
  59. package/dist/internal/compiler/entries.d.ts.map +1 -1
  60. package/dist/internal/compiler/entries.js +6 -7
  61. package/dist/internal/compiler/entries.js.map +1 -1
  62. package/dist/internal/compiler/first.d.ts +0 -2
  63. package/dist/internal/compiler/first.d.ts.map +1 -1
  64. package/dist/internal/compiler/first.js +10 -10
  65. package/dist/internal/compiler/first.js.map +1 -1
  66. package/dist/internal/compiler/jit.d.ts +0 -2
  67. package/dist/internal/compiler/jit.d.ts.map +1 -1
  68. package/dist/internal/compiler/jit.js +52 -51
  69. package/dist/internal/compiler/jit.js.map +1 -1
  70. package/dist/internal/compiler/registry.d.ts +0 -2
  71. package/dist/internal/compiler/registry.d.ts.map +1 -1
  72. package/dist/internal/compiler/registry.js +1 -2
  73. package/dist/internal/compiler/sets.d.ts +2 -2
  74. package/dist/internal/compiler/sets.d.ts.map +1 -1
  75. package/dist/internal/compiler/sets.js +8 -3
  76. package/dist/internal/compiler/sets.js.map +1 -1
  77. package/dist/internal/entries.d.ts +0 -2
  78. package/dist/internal/entries.d.ts.map +1 -1
  79. package/dist/internal/entries.js +1 -2
  80. package/dist/internal/key.d.ts +10 -0
  81. package/dist/internal/key.d.ts.map +1 -0
  82. package/dist/internal/key.js +11 -0
  83. package/dist/internal/key.js.map +1 -0
  84. package/dist/internal/node.d.ts +11 -4
  85. package/dist/internal/node.d.ts.map +1 -1
  86. package/dist/internal/node.js +15 -3
  87. package/dist/internal/node.js.map +1 -1
  88. package/dist/internal/numbers.d.ts +0 -2
  89. package/dist/internal/numbers.d.ts.map +1 -1
  90. package/dist/internal/numbers.js +1 -2
  91. package/dist/internal/resume.d.ts +5 -6
  92. package/dist/internal/resume.d.ts.map +1 -1
  93. package/dist/internal/resume.js +1 -2
  94. package/dist/internal/resume.js.map +1 -1
  95. package/dist/internal/run.d.ts +0 -2
  96. package/dist/internal/run.d.ts.map +1 -1
  97. package/dist/internal/run.js +2 -3
  98. package/dist/internal/run.js.map +1 -1
  99. package/dist/internal/stack.d.ts +0 -2
  100. package/dist/internal/stack.d.ts.map +1 -1
  101. package/dist/internal/stack.js +1 -2
  102. package/dist/internal/syntax.d.ts +30 -20
  103. package/dist/internal/syntax.d.ts.map +1 -1
  104. package/dist/internal/syntax.js +73 -66
  105. package/dist/internal/syntax.js.map +1 -1
  106. package/dist/internal/text.d.ts +5 -2
  107. package/dist/internal/text.d.ts.map +1 -1
  108. package/dist/internal/text.js +14 -5
  109. package/dist/internal/text.js.map +1 -1
  110. package/dist/internal/ties.d.ts +0 -2
  111. package/dist/internal/ties.d.ts.map +1 -1
  112. package/dist/internal/ties.js +1 -2
  113. package/dist/internal/tokens.d.ts +10 -9
  114. package/dist/internal/tokens.d.ts.map +1 -1
  115. package/dist/internal/tokens.js +4 -8
  116. package/dist/internal/tokens.js.map +1 -1
  117. package/package.json +6 -6
  118. package/src/Ascii.ts +6 -5
  119. package/src/Bits.ts +1 -1
  120. package/src/Expression.ts +7 -6
  121. package/src/Input.ts +50 -11
  122. package/src/ParseError.ts +9 -7
  123. package/src/Parser.ts +26 -23
  124. package/src/ParserStream.ts +20 -8
  125. package/src/Syntax.ts +12 -9
  126. package/src/internal/compiler/closure.ts +202 -90
  127. package/src/internal/compiler/entries.ts +14 -11
  128. package/src/internal/compiler/first.ts +9 -8
  129. package/src/internal/compiler/jit.ts +95 -74
  130. package/src/internal/compiler/sets.ts +7 -0
  131. package/src/internal/key.ts +11 -0
  132. package/src/internal/node.ts +19 -2
  133. package/src/internal/resume.ts +5 -4
  134. package/src/internal/run.ts +1 -1
  135. package/src/internal/syntax.ts +78 -87
  136. package/src/internal/text.ts +24 -4
  137. package/src/internal/tokens.ts +20 -13
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Identity keys: a parser that keeps state across parses (resume
3
+ * checkpoints, reusable syntax nodes) creates one `Key` when it is built and
4
+ * looks its state up by that key's reference.
5
+ */
6
+ /** A per-parser identity, compared by reference. */
7
+ export declare class Key {
8
+ private readonly brand;
9
+ }
10
+ //# sourceMappingURL=key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.d.ts","names":[],"sources":["../../src/internal/key.ts"],"mappings":";;;;;;qBAOa;mBAEc"}
@@ -0,0 +1,11 @@
1
+ // src/internal/key.ts
2
+ /**
3
+ * Identity keys: a parser that keeps state across parses (resume
4
+ * checkpoints, reusable syntax nodes) creates one `Key` when it is built and
5
+ * looks its state up by that key's reference.
6
+ */
7
+ /** A per-parser identity, compared by reference. */
8
+ var Key = class {};
9
+ export { Key };
10
+
11
+ //# sourceMappingURL=key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.js","names":[],"sources":["../../src/internal/key.ts"],"sourcesContent":["/**\n * Identity keys: a parser that keeps state across parses (resume\n * checkpoints, reusable syntax nodes) creates one `Key` when it is built and\n * looks its state up by that key's reference.\n */\n\n/** A per-parser identity, compared by reference. */\nexport class Key {\n // Nominal: an empty class would accept any object\n declare private readonly brand: void\n}\n"],"mappings":";;;;;;;AAOA,IAAa,MAAb,MAAiB,CAGjB"}
@@ -1,6 +1,7 @@
1
+ import * as Result from "effect/Result";
1
2
  import { ErrMode, Input, State } from "../Input.js";
3
+ import * as Option from "effect/Option";
2
4
  import { Encoding } from "../Encoding.js";
3
- //#region src/internal/node.d.ts
4
5
  /** The parts of a parser the compiler needs. */
5
6
  export interface ParserLike {
6
7
  readonly step: (state: State<any>) => unknown;
@@ -102,11 +103,11 @@ export type Node = {
102
103
  } | {
103
104
  readonly _tag: "TryMap";
104
105
  readonly self: P;
105
- readonly f: (a: any) => unknown;
106
+ readonly f: (a: any) => Result.Result<unknown, unknown>;
106
107
  } | {
107
108
  readonly _tag: "FilterMap";
108
109
  readonly self: P;
109
- readonly f: (a: any) => unknown;
110
+ readonly f: (a: any) => Option.Option<unknown>;
110
111
  } | {
111
112
  readonly _tag: "Filter";
112
113
  readonly self: P;
@@ -248,8 +249,14 @@ export declare const bounds: (range: number | {
248
249
  readonly min?: number | undefined;
249
250
  readonly max?: number | undefined;
250
251
  } | undefined) => Bounds;
252
+ /**
253
+ * Whether the compilers' one-pass float scan applies to `p`, the text
254
+ * parser of `Ascii.float` / `Text.float`: a `taken` (under any `expected`
255
+ * labels) in an encoding that `native` accepts, reading one ASCII-compatible
256
+ * unit at a time, or in no encoding at all.
257
+ */
258
+ export declare const scansFloat: (p: ParserLike, native: (enc: Encoding<any>) => boolean) => boolean;
251
259
  /** The child parsers of a node, in evaluation order. */
252
260
  export declare const children: (node: Node) => ReadonlyArray<P>;
253
- //#endregion
254
261
  export {};
255
262
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/internal/node.ts"],"mappings":";;;;iBAaiB;WACN,OAAO,OAAO;WACd;;KAGN,IAAI;KACJ,QAAQ,OAAO;;UAGV;WACC;WACA;;;;;;;KAQN,MAAM;YAEC;WAEG;WAAyB,MAAM;;WAC/B;WAA0B;;WAC1B;WAAuB;;WACvB;WAAuB,MAAM;;WAC7B;;WACA;;WACA;WAA0B,eAAe;;WAEzC;WAAsB,UAAU;;WAChC;WAA0B,SAAS;WAAgB;WAA4B,UAAU;;WACzF;WAAwB;WAAuB;WAA0B,UAAU;;WACnF;WAAuB;WAAwB,UAAU;;WACxD;WA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parsers, recorded next to their steps so that parsers can
5
5
  * be compiled (see `docs/DESIGN.md`, "Compiled parsers").
@@ -30,6 +30,19 @@ const bounds = (range) => {
30
30
  max: range.max ?? Infinity
31
31
  };
32
32
  };
33
+ /**
34
+ * Whether the compilers' one-pass float scan applies to `p`, the text
35
+ * parser of `Ascii.float` / `Text.float`: a `taken` (under any `expected`
36
+ * labels) in an encoding that `native` accepts, reading one ASCII-compatible
37
+ * unit at a time, or in no encoding at all.
38
+ */
39
+ const scansFloat = (p, native) => {
40
+ let taken = nodeOf(p);
41
+ while (Predicate.isTagged(taken, "Expected")) taken = nodeOf(taken.self);
42
+ if (!Predicate.isTagged(taken, "Taken")) return false;
43
+ const enc = taken.encoding;
44
+ return enc === void 0 || native(enc) && enc.unit === 1 && enc.asciiCompatible;
45
+ };
33
46
  /** The child parsers of a node, in evaluation order. */
34
47
  const children = (node) => {
35
48
  switch (node._tag) {
@@ -78,7 +91,6 @@ const children = (node) => {
78
91
  default: return [];
79
92
  }
80
93
  };
81
- //#endregion
82
- export { NodeId, bounds, children, nodeOf };
94
+ export { NodeId, bounds, children, nodeOf, scansFloat };
83
95
 
84
96
  //# sourceMappingURL=node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","names":[],"sources":["../../src/internal/node.ts"],"sourcesContent":["/**\n * Descriptions of parsers, recorded next to their steps so that parsers can\n * be compiled (see `docs/DESIGN.md`, \"Compiled parsers\").\n *\n * Nodes refer to their child parsers rather than to child nodes, so a\n * child's own step is always at hand for fallback, and recursion through\n * `Suspend` is just a reference.\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type { Encoding } from \"../Encoding.js\"\nimport type { ErrMode, Input, State } from \"../Input.js\"\n\n/** The parts of a parser the compiler needs. */\nexport interface ParserLike {\n readonly step: (state: State<any>) => unknown\n readonly name: string | undefined\n}\n\ntype P = ParserLike\ntype Step = (state: State<any>) => unknown\n\n/** A repetition range, normalized: `max` may be `Infinity`. */\ninterface Bounds {\n readonly min: number\n readonly max: number\n}\n\n/**\n * For token nodes: `undefined` for the `Token`/`Ascii` parsers (code points\n * of strings with lenient surrogates, bytes, or array elements), or the\n * encoding of a `Text` parser.\n */\ntype Enc = Encoding<any> | undefined\n\nexport type Node =\n // Constants\n | { readonly _tag: \"Opaque\"; readonly step: Step }\n | { readonly _tag: \"Succeed\"; readonly value: unknown }\n | { readonly _tag: \"Sync\"; readonly evaluate: () => unknown }\n | { readonly _tag: \"Fail\"; readonly mode: ErrMode }\n | { readonly _tag: \"Eof\" }\n | { readonly _tag: \"Location\" }\n | { readonly _tag: \"Suspend\"; readonly resolve: () => P }\n // Tokens\n | { readonly _tag: \"Any\"; readonly encoding: Enc }\n | { readonly _tag: \"Literal\"; readonly literal: Input; readonly caseless: boolean; readonly encoding: Enc }\n | { readonly _tag: \"OneOf\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc }\n | { readonly _tag: \"Take\"; readonly count: number; readonly encoding: Enc }\n | ({ readonly _tag: \"TakeWhile\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc } & Bounds)\n | ({ readonly _tag: \"TakeUntil\"; readonly literal: Input; readonly encoding: Enc } & Bounds)\n | { readonly _tag: \"Rest\"; readonly encoding: Enc }\n | { readonly _tag: \"RestLen\" }\n | { readonly _tag: \"TillLineEnding\"; readonly encoding: Enc }\n | { readonly _tag: \"Identifier\"; readonly encoding: Enc }\n | { readonly _tag: \"Bom\"; readonly encoding: Enc }\n | {\n readonly _tag: \"Escaped\"\n readonly normal: P\n /** The control character, as a code point (or a byte / unit for `Ascii`). */\n readonly control: number\n readonly escape: P\n /** `takeEscaped`: return the raw slice instead of the unescaped text. */\n readonly raw: boolean\n readonly encoding: Enc\n }\n // Mapping\n | { readonly _tag: \"Map\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"As\"; readonly self: P; readonly value: unknown }\n | { readonly _tag: \"Tap\"; readonly self: P; readonly f: (a: any) => void }\n | { readonly _tag: \"TryMap\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"FilterMap\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"Filter\"; readonly self: P; readonly predicate: (a: any) => boolean }\n | { readonly _tag: \"FlatMap\"; readonly self: P; readonly f: (a: any) => P }\n // Consumed input\n | { readonly _tag: \"Taken\"; readonly self: P; readonly encoding: Enc }\n | { readonly _tag: \"WithTaken\"; readonly self: P }\n | { readonly _tag: \"Span\"; readonly self: P }\n | { readonly _tag: \"WithSpan\"; readonly self: P }\n // Errors\n | { readonly _tag: \"Mode\"; readonly self: P; readonly from: ErrMode; readonly to: ErrMode }\n | { readonly _tag: \"Context\"; readonly self: P; readonly label: string }\n | { readonly _tag: \"Expected\"; readonly self: P; readonly description: string }\n | { readonly _tag: \"MapError\"; readonly self: P }\n | { readonly _tag: \"OrFail\"; readonly self: P }\n // Control\n | { readonly _tag: \"Opt\"; readonly self: P }\n | { readonly _tag: \"OrElseSucceed\"; readonly self: P; readonly value: () => unknown }\n | { readonly _tag: \"Peek\"; readonly self: P }\n | { readonly _tag: \"Not\"; readonly self: P }\n // Sequencing\n | {\n readonly _tag: \"Seq\"\n readonly parsers: ReadonlyArray<P>\n /** Which outputs are kept: all (a tuple), one index, or a pair of indices. */\n readonly output: \"tuple\" | number | readonly [number, number]\n }\n | { readonly _tag: \"Struct\"; readonly keys: ReadonlyArray<string>; readonly parsers: ReadonlyArray<P> }\n | { readonly _tag: \"ZipWith\"; readonly self: P; readonly that: P; readonly f: (a: any, b: any) => unknown }\n // Choice\n | { readonly _tag: \"Alt\"; readonly parsers: ReadonlyArray<P> }\n | {\n readonly _tag: \"Dispatch\"\n readonly selector: P\n /** A record of cases, when `dispatch` was given one. */\n readonly cases: Readonly<Record<PropertyKey, P>> | undefined\n readonly otherwise: P | undefined\n readonly choose: (key: any) => P | undefined\n }\n // Repetition\n | ({ readonly _tag: \"Repeat\"; readonly self: P } & Bounds)\n | ({\n readonly _tag: \"Fold\"\n readonly self: P\n readonly init: () => unknown\n readonly f: (acc: any, a: any) => unknown\n /** Stops the repetition once false of the accumulator (after `min` elements). */\n readonly while: ((acc: any) => boolean) | undefined\n readonly name: string\n } & Bounds)\n | ({ readonly _tag: \"RepeatTill\"; readonly self: P; readonly end: P } & Bounds)\n | ({ readonly _tag: \"Separated\"; readonly self: P; readonly separator: P } & Bounds)\n | {\n readonly _tag: \"SeparatedFold\"\n readonly self: P\n readonly separator: P\n readonly op: (l: any, s: any, r: any) => unknown\n readonly right: boolean\n }\n // Services, recovery, debugging\n | { readonly _tag: \"Service\" }\n | { readonly _tag: \"Provide\"; readonly self: P }\n | { readonly _tag: \"ResumeAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"RetryAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"Trace\"; readonly self: P; readonly name: string }\n /** `Syntax.node`, `Syntax.token` and `Syntax.field`: identities outside `Syntax` parses. */\n | {\n readonly _tag: \"Syntax\"\n readonly self: P\n /** The node kind, or `undefined` for a field. */\n readonly kind: string | undefined\n readonly named: boolean\n }\n\nexport type Tag = Node[\"_tag\"]\n\nexport type NodeOf<T extends Tag> = Extract<Node, { readonly _tag: T }>\n\n/** Where a parser's description is stored. */\nexport const NodeId: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Parser/node\")\n\n/** The description of a parser: `Opaque` when it has none. */\nexport const nodeOf = (p: ParserLike): Node => (p as any)[NodeId] ?? { _tag: \"Opaque\", step: p.step }\n\n/** Normalizes a range, as `repeat`, `takeWhile`, ... do. */\nexport const bounds = (\n range: number | { readonly min?: number | undefined; readonly max?: number | undefined } | undefined\n): Bounds => {\n if (range === undefined) return { min: 0, max: Infinity }\n if (Predicate.isNumber(range)) return { min: range, max: range }\n return { min: range.min ?? 0, max: range.max ?? Infinity }\n}\n\n/** The child parsers of a node, in evaluation order. */\nexport const children = (node: Node): ReadonlyArray<P> => {\n switch (node._tag) {\n case \"Escaped\":\n return [node.normal, node.escape]\n case \"Map\":\n case \"As\":\n case \"Tap\":\n case \"TryMap\":\n case \"FilterMap\":\n case \"Filter\":\n case \"FlatMap\":\n case \"Taken\":\n case \"WithTaken\":\n case \"Span\":\n case \"WithSpan\":\n case \"Mode\":\n case \"Context\":\n case \"Expected\":\n case \"MapError\":\n case \"OrFail\":\n case \"Opt\":\n case \"OrElseSucceed\":\n case \"Peek\":\n case \"Not\":\n case \"Repeat\":\n case \"Fold\":\n case \"Provide\":\n case \"Trace\":\n case \"Syntax\":\n return [node.self]\n case \"ResumeAfter\":\n case \"RetryAfter\":\n return [node.self, node.recover]\n case \"Seq\":\n case \"Struct\":\n case \"Alt\":\n return node.parsers\n case \"ZipWith\":\n return [node.self, node.that]\n case \"Dispatch\": {\n const out: Array<P> = [node.selector]\n if (node.cases !== undefined) {\n for (const key of Reflect.ownKeys(node.cases)) out.push(node.cases[key as any])\n }\n if (node.otherwise !== undefined) out.push(node.otherwise)\n return out\n }\n case \"RepeatTill\":\n return [node.self, node.end]\n case \"Separated\":\n case \"SeparatedFold\":\n return [node.self, node.separator]\n case \"Suspend\":\n return [node.resolve()]\n default:\n return []\n }\n}\n"],"mappings":";;;;;;;;;;;AAoJA,MAAa,SAAsC,qBAAO,IAAI,0BAA0B;;AAGxF,MAAa,UAAU,MAAyB,EAAU,WAAW;CAAE,MAAM;CAAU,MAAM,EAAE;AAAK;;AAGpG,MAAa,UACX,UACW;CACX,IAAI,UAAU,KAAA,GAAW,OAAO;EAAE,KAAK;EAAG,KAAK;CAAS;CACxD,IAAI,UAAU,SAAS,KAAK,GAAG,OAAO;EAAE,KAAK;EAAO,KAAK;CAAM;CAC/D,OAAO;EAAE,KAAK,MAAM,OAAO;EAAG,KAAK,MAAM,OAAO;CAAS;AAC3D;;AAGA,MAAa,YAAY,SAAiC;CACxD,QAAQ,KAAK,MAAb;EACE,KAAK,WACH,OAAO,CAAC,KAAK,QAAQ,KAAK,MAAM;EAClC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO,CAAC,KAAK,IAAI;EACnB,KAAK;EACL,KAAK,cACH,OAAO,CAAC,KAAK,MAAM,KAAK,OAAO;EACjC,KAAK;EACL,KAAK;EACL,KAAK,OACH,OAAO,KAAK;EACd,KAAK,WACH,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI;EAC9B,KAAK,YAAY;GACf,MAAM,MAAgB,CAAC,KAAK,QAAQ;GACpC,IAAI,KAAK,UAAU,KAAA,GACjB,KAAK,MAAM,OAAO,QAAQ,QAAQ,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,MAAM,IAAW;GAEhF,IAAI,KAAK,cAAc,KAAA,GAAW,IAAI,KAAK,KAAK,SAAS;GACzD,OAAO;EACT;EACA,KAAK,cACH,OAAO,CAAC,KAAK,MAAM,KAAK,GAAG;EAC7B,KAAK;EACL,KAAK,iBACH,OAAO,CAAC,KAAK,MAAM,KAAK,SAAS;EACnC,KAAK,WACH,OAAO,CAAC,KAAK,QAAQ,CAAC;EACxB,SACE,OAAO,CAAC;CACZ;AACF"}
1
+ {"version":3,"file":"node.js","names":[],"sources":["../../src/internal/node.ts"],"sourcesContent":["/**\n * Descriptions of parsers, recorded next to their steps so that parsers can\n * be compiled (see `docs/DESIGN.md`, \"Compiled parsers\").\n *\n * Nodes refer to their child parsers rather than to child nodes, so a\n * child's own step is always at hand for fallback, and recursion through\n * `Suspend` is just a reference.\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type * as Option from \"effect/Option\"\nimport type * as Result from \"effect/Result\"\nimport type { Encoding } from \"../Encoding.js\"\nimport type { ErrMode, Input, State } from \"../Input.js\"\n\n/** The parts of a parser the compiler needs. */\nexport interface ParserLike {\n readonly step: (state: State<any>) => unknown\n readonly name: string | undefined\n}\n\ntype P = ParserLike\ntype Step = (state: State<any>) => unknown\n\n/** A repetition range, normalized: `max` may be `Infinity`. */\ninterface Bounds {\n readonly min: number\n readonly max: number\n}\n\n/**\n * For token nodes: `undefined` for the `Token`/`Ascii` parsers (code points\n * of strings with lenient surrogates, bytes, or array elements), or the\n * encoding of a `Text` parser.\n */\ntype Enc = Encoding<any> | undefined\n\nexport type Node =\n // Constants\n | { readonly _tag: \"Opaque\"; readonly step: Step }\n | { readonly _tag: \"Succeed\"; readonly value: unknown }\n | { readonly _tag: \"Sync\"; readonly evaluate: () => unknown }\n | { readonly _tag: \"Fail\"; readonly mode: ErrMode }\n | { readonly _tag: \"Eof\" }\n | { readonly _tag: \"Location\" }\n | { readonly _tag: \"Suspend\"; readonly resolve: () => P }\n // Tokens\n | { readonly _tag: \"Any\"; readonly encoding: Enc }\n | { readonly _tag: \"Literal\"; readonly literal: Input; readonly caseless: boolean; readonly encoding: Enc }\n | { readonly _tag: \"OneOf\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc }\n | { readonly _tag: \"Take\"; readonly count: number; readonly encoding: Enc }\n | ({ readonly _tag: \"TakeWhile\"; readonly set: unknown; readonly negate: boolean; readonly encoding: Enc } & Bounds)\n | ({ readonly _tag: \"TakeUntil\"; readonly literal: Input; readonly encoding: Enc } & Bounds)\n | { readonly _tag: \"Rest\"; readonly encoding: Enc }\n | { readonly _tag: \"RestLen\" }\n | { readonly _tag: \"TillLineEnding\"; readonly encoding: Enc }\n | { readonly _tag: \"Identifier\"; readonly encoding: Enc }\n | { readonly _tag: \"Bom\"; readonly encoding: Enc }\n | {\n readonly _tag: \"Escaped\"\n readonly normal: P\n /** The control character, as a code point (or a byte / unit for `Ascii`). */\n readonly control: number\n readonly escape: P\n /** `takeEscaped`: return the raw slice instead of the unescaped text. */\n readonly raw: boolean\n readonly encoding: Enc\n }\n // Mapping\n | { readonly _tag: \"Map\"; readonly self: P; readonly f: (a: any) => unknown }\n | { readonly _tag: \"As\"; readonly self: P; readonly value: unknown }\n | { readonly _tag: \"Tap\"; readonly self: P; readonly f: (a: any) => void }\n | { readonly _tag: \"TryMap\"; readonly self: P; readonly f: (a: any) => Result.Result<unknown, unknown> }\n | { readonly _tag: \"FilterMap\"; readonly self: P; readonly f: (a: any) => Option.Option<unknown> }\n | { readonly _tag: \"Filter\"; readonly self: P; readonly predicate: (a: any) => boolean }\n | { readonly _tag: \"FlatMap\"; readonly self: P; readonly f: (a: any) => P }\n // Consumed input\n | { readonly _tag: \"Taken\"; readonly self: P; readonly encoding: Enc }\n | { readonly _tag: \"WithTaken\"; readonly self: P }\n | { readonly _tag: \"Span\"; readonly self: P }\n | { readonly _tag: \"WithSpan\"; readonly self: P }\n // Errors\n | { readonly _tag: \"Mode\"; readonly self: P; readonly from: ErrMode; readonly to: ErrMode }\n | { readonly _tag: \"Context\"; readonly self: P; readonly label: string }\n | { readonly _tag: \"Expected\"; readonly self: P; readonly description: string }\n | { readonly _tag: \"MapError\"; readonly self: P }\n | { readonly _tag: \"OrFail\"; readonly self: P }\n // Control\n | { readonly _tag: \"Opt\"; readonly self: P }\n | { readonly _tag: \"OrElseSucceed\"; readonly self: P; readonly value: () => unknown }\n | { readonly _tag: \"Peek\"; readonly self: P }\n | { readonly _tag: \"Not\"; readonly self: P }\n // Sequencing\n | {\n readonly _tag: \"Seq\"\n readonly parsers: ReadonlyArray<P>\n /** Which outputs are kept: all (a tuple), one index, or a pair of indices. */\n readonly output: \"tuple\" | number | readonly [number, number]\n }\n | { readonly _tag: \"Struct\"; readonly keys: ReadonlyArray<string>; readonly parsers: ReadonlyArray<P> }\n | { readonly _tag: \"ZipWith\"; readonly self: P; readonly that: P; readonly f: (a: any, b: any) => unknown }\n // Choice\n | { readonly _tag: \"Alt\"; readonly parsers: ReadonlyArray<P> }\n | {\n readonly _tag: \"Dispatch\"\n readonly selector: P\n /** A record of cases, when `dispatch` was given one. */\n readonly cases: Readonly<Record<PropertyKey, P>> | undefined\n readonly otherwise: P | undefined\n readonly choose: (key: any) => P | undefined\n }\n // Repetition\n | ({ readonly _tag: \"Repeat\"; readonly self: P } & Bounds)\n | ({\n readonly _tag: \"Fold\"\n readonly self: P\n readonly init: () => unknown\n readonly f: (acc: any, a: any) => unknown\n /** Stops the repetition once false of the accumulator (after `min` elements). */\n readonly while: ((acc: any) => boolean) | undefined\n readonly name: string\n } & Bounds)\n | ({ readonly _tag: \"RepeatTill\"; readonly self: P; readonly end: P } & Bounds)\n | ({ readonly _tag: \"Separated\"; readonly self: P; readonly separator: P } & Bounds)\n | {\n readonly _tag: \"SeparatedFold\"\n readonly self: P\n readonly separator: P\n readonly op: (l: any, s: any, r: any) => unknown\n readonly right: boolean\n }\n // Services, recovery, debugging\n | { readonly _tag: \"Service\" }\n | { readonly _tag: \"Provide\"; readonly self: P }\n | { readonly _tag: \"ResumeAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"RetryAfter\"; readonly self: P; readonly recover: P }\n | { readonly _tag: \"Trace\"; readonly self: P; readonly name: string }\n /** `Syntax.node`, `Syntax.token` and `Syntax.field`: identities outside `Syntax` parses. */\n | {\n readonly _tag: \"Syntax\"\n readonly self: P\n /** The node kind, or `undefined` for a field. */\n readonly kind: string | undefined\n readonly named: boolean\n }\n\nexport type Tag = Node[\"_tag\"]\n\nexport type NodeOf<T extends Tag> = Extract<Node, { readonly _tag: T }>\n\n/** Where a parser's description is stored. */\nexport const NodeId: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Parser/node\")\n\n/** The description of a parser: `Opaque` when it has none. */\nexport const nodeOf = (p: ParserLike): Node => (p as any)[NodeId] ?? { _tag: \"Opaque\", step: p.step }\n\n/** Normalizes a range, as `repeat`, `takeWhile`, ... do. */\nexport const bounds = (\n range: number | { readonly min?: number | undefined; readonly max?: number | undefined } | undefined\n): Bounds => {\n if (range === undefined) return { min: 0, max: Infinity }\n if (Predicate.isNumber(range)) return { min: range, max: range }\n return { min: range.min ?? 0, max: range.max ?? Infinity }\n}\n\n/**\n * Whether the compilers' one-pass float scan applies to `p`, the text\n * parser of `Ascii.float` / `Text.float`: a `taken` (under any `expected`\n * labels) in an encoding that `native` accepts, reading one ASCII-compatible\n * unit at a time, or in no encoding at all.\n */\nexport const scansFloat = (p: ParserLike, native: (enc: Encoding<any>) => boolean): boolean => {\n let taken = nodeOf(p)\n while (Predicate.isTagged(taken, \"Expected\")) taken = nodeOf(taken.self)\n if (!Predicate.isTagged(taken, \"Taken\")) return false\n const enc = taken.encoding\n // Decimal notation is ASCII, which these encodings read unit by unit\n return enc === undefined || (native(enc) && enc.unit === 1 && enc.asciiCompatible)\n}\n\n/** The child parsers of a node, in evaluation order. */\nexport const children = (node: Node): ReadonlyArray<P> => {\n switch (node._tag) {\n case \"Escaped\":\n return [node.normal, node.escape]\n case \"Map\":\n case \"As\":\n case \"Tap\":\n case \"TryMap\":\n case \"FilterMap\":\n case \"Filter\":\n case \"FlatMap\":\n case \"Taken\":\n case \"WithTaken\":\n case \"Span\":\n case \"WithSpan\":\n case \"Mode\":\n case \"Context\":\n case \"Expected\":\n case \"MapError\":\n case \"OrFail\":\n case \"Opt\":\n case \"OrElseSucceed\":\n case \"Peek\":\n case \"Not\":\n case \"Repeat\":\n case \"Fold\":\n case \"Provide\":\n case \"Trace\":\n case \"Syntax\":\n return [node.self]\n case \"ResumeAfter\":\n case \"RetryAfter\":\n return [node.self, node.recover]\n case \"Seq\":\n case \"Struct\":\n case \"Alt\":\n return node.parsers\n case \"ZipWith\":\n return [node.self, node.that]\n case \"Dispatch\": {\n const out: Array<P> = [node.selector]\n if (node.cases !== undefined) {\n for (const key of Reflect.ownKeys(node.cases)) out.push(node.cases[key as any])\n }\n if (node.otherwise !== undefined) out.push(node.otherwise)\n return out\n }\n case \"RepeatTill\":\n return [node.self, node.end]\n case \"Separated\":\n case \"SeparatedFold\":\n return [node.self, node.separator]\n case \"Suspend\":\n return [node.resolve()]\n default:\n return []\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,MAAM,KAAK,IAAI;EAC9B,KAAK,YAAY;GACf,MAAM,MAAgB,CAAC,KAAK,QAAQ;GACpC,IAAI,KAAK,UAAU,KAAA,GACjB,KAAK,MAAM,OAAO,QAAQ,QAAQ,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,MAAM,IAAW;GAEhF,IAAI,KAAK,cAAc,KAAA,GAAW,IAAI,KAAK,KAAK,SAAS;GACzD,OAAO;EACT;EACA,KAAK,cACH,OAAO,CAAC,KAAK,MAAM,KAAK,GAAG;EAC7B,KAAK;EACL,KAAK,iBACH,OAAO,CAAC,KAAK,MAAM,KAAK,SAAS;EACnC,KAAK,WACH,OAAO,CAAC,KAAK,QAAQ,CAAC;EACxB,SACE,OAAO,CAAC;CACZ;AACF"}
@@ -1,5 +1,4 @@
1
1
  import { Fail, Input } from "../Input.js";
2
- //#region src/internal/numbers.d.ts
3
2
  /** The text of an input slice: as is for a string, Latin-1 for bytes, joined for tokens. */
4
3
  export declare const toText: (s: Input) => string;
5
4
  /** The value of the text matched by `Ascii.float` and `Text.float`. */
@@ -36,5 +35,4 @@ export declare const floatScan: {
36
35
  export declare const scanFloatString: (s: string, i: number, end: number) => number | Fail | undefined;
37
36
  /** {@link scanFloatString} on bytes, or the units of an ASCII compatible encoding. */
38
37
  export declare const scanFloatBytes: (b: Uint8Array, i: number, end: number) => number | Fail | undefined;
39
- //#endregion
40
38
  //# sourceMappingURL=numbers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"numbers.d.ts","names":[],"sources":["../../src/internal/numbers.ts"],"mappings":";;;qBAUa,SAAU,GAAG;;qBAIb,UAAW,GAAG;;;;;;qBAmBd,YAAU;;qBAGV,YAAa,kBAAkB,GAAG,MAAI;;;;;;qBAatC;;;;;;;;;;;;;;;;qBAiFA,kBAAmB,WAAW,WAAW,yBAAuB;;qBAmFhE,iBAAkB,GAAG,YAAY,WAAW,yBAAuB"}
1
+ {"version":3,"file":"numbers.d.ts","names":[],"sources":["../../src/internal/numbers.ts"],"mappings":";;qBAUa,SAAU,GAAG;;qBAIb,UAAW,GAAG;;;;;;qBAmBd,YAAU;;qBAGV,YAAa,kBAAkB,GAAG,MAAI;;;;;;qBAatC;;;;;;;;;;;;;;;;qBAiFA,kBAAmB,WAAW,WAAW,yBAAuB;;qBAmFhE,iBAAkB,GAAG,YAAY,WAAW,yBAAuB"}
@@ -1,7 +1,7 @@
1
1
  import * as Predicate from "effect/Predicate";
2
2
  import { Fail } from "../Input.js";
3
3
  import { latin1 } from "./text.js";
4
- //#region src/internal/numbers.ts
4
+ // src/internal/numbers.ts
5
5
  /**
6
6
  * Number conversions shared by the `Ascii` and `Text` parsers and the
7
7
  * compilers.
@@ -266,7 +266,6 @@ const scanFloatBytes = (b, i, end) => {
266
266
  };
267
267
  /** The text of ASCII bytes. */
268
268
  const asciiText = (b, start, end) => String.fromCharCode.apply(null, b.subarray(start, end));
269
- //#endregion
270
269
  export { floatScan, floatText, floatTexts, scanFloatBytes, scanFloatString, toFloat, toText };
271
270
 
272
271
  //# sourceMappingURL=numbers.js.map
@@ -1,9 +1,9 @@
1
1
  import { State } from "../Input.js";
2
- //#region src/internal/resume.d.ts
2
+ import { Key } from "./key.js";
3
3
  /** The checkpoints of a resumable parse. */
4
- export type Checkpoints = Map<object, Map<number, unknown>>;
4
+ export type Checkpoints = Map<Key, Map<number, unknown>>;
5
5
  /** Takes (and removes) the checkpoint of `key` entered at `offset`, if any. */
6
- export declare const take: (state: State<any>, key: object, offset: number) => unknown;
6
+ export declare const take: (state: State<any>, key: Key, offset: number) => unknown;
7
7
  /** The result of a repetition that completed, and where it ended. */
8
8
  export declare class Done {
9
9
  readonly value: unknown;
@@ -14,8 +14,7 @@ export declare class Done {
14
14
  * Returns `value`, the result of a repetition entered at `entry`; when the
15
15
  * repetition was resumed from a checkpoint, records it as {@link Done}.
16
16
  */
17
- export declare const done: <A>(state: State<any>, key: object, entry: number, resumed: boolean, value: A) => A;
17
+ export declare const done: <A>(state: State<any>, key: Key, entry: number, resumed: boolean, value: A) => A;
18
18
  /** Records the checkpoint of `key` entered at `offset`. */
19
- export declare const save: (state: State<any>, key: object, offset: number, checkpoint: unknown) => void;
20
- //#endregion
19
+ export declare const save: (state: State<any>, key: Key, offset: number, checkpoint: unknown) => void;
21
20
  //# sourceMappingURL=resume.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resume.d.ts","names":[],"sources":["../../src/internal/resume.ts"],"mappings":";;;YAuBY,cAAc,YAAY;;qBAGzB,OAAQ,OAAO,YAAY,aAAa;;qBASxC;WAEA;WACA;EADA,YAAA,gBACA;;;;;;qBAQA,OAAQ,GAAG,OAAO,YAAY,aAAa,eAAe,kBAAkB,OAAO,MAAI;;qBAMvF,OAAQ,OAAO,YAAY,aAAa,gBAAgB"}
1
+ {"version":3,"file":"resume.d.ts","names":[],"sources":["../../src/internal/resume.ts"],"mappings":";;;YAwBY,cAAc,IAAI,KAAK;;qBAGtB,OAAQ,OAAO,YAAY,KAAK,KAAK;;qBASrC;WAEA;WACA;EADA,YAAA,gBACA;;;;;;qBAQA,OAAQ,GAAG,OAAO,YAAY,KAAK,KAAK,eAAe,kBAAkB,OAAO,MAAI;;qBAMpF,OAAQ,OAAO,YAAY,KAAK,KAAK,gBAAgB"}
@@ -1,4 +1,4 @@
1
- //#region src/internal/resume.ts
1
+ // src/internal/resume.ts
2
2
  /** Takes (and removes) the checkpoint of `key` entered at `offset`, if any. */
3
3
  const take = (state, key, offset) => {
4
4
  const byKey = state.resume?.get(key);
@@ -32,7 +32,6 @@ const save = (state, key, offset, checkpoint) => {
32
32
  if (byKey === void 0) resume.set(key, byKey = /* @__PURE__ */ new Map());
33
33
  byKey.set(offset, checkpoint);
34
34
  };
35
- //#endregion
36
35
  export { Done, done, save, take };
37
36
 
38
37
  //# sourceMappingURL=resume.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resume.js","names":[],"sources":["../../src/internal/resume.ts"],"sourcesContent":["/**\n * Checkpoints for resumable (streaming) parses.\n *\n * In partial mode a parser only succeeds on what it has seen, so a value\n * parsed from a prefix of the input stays the same when more input\n * arrives. A repetition that runs out of input mid-way can therefore record\n * how far it got (its accumulator and position) before the failure\n * propagates. When the parse is attempted again with more input, the same\n * repetition, entered at the same offset, takes its checkpoint and carries\n * on from there instead of re-parsing every element.\n *\n * Checkpoints are keyed by a per-parser key and the offset the repetition\n * started at. Taking a checkpoint removes it, so its accumulator has a\n * single owner; the repetition saves a new one if it runs out again.\n *\n * A resumed repetition that then completes leaves a {@link Done}\n * checkpoint with its result, since the input may still run out after it\n * (in trailing whitespace, say) and the next attempt would otherwise parse\n * it all again. `Done` checkpoints stay in place when taken.\n */\nimport type { State } from \"../Input.js\"\n\n/** The checkpoints of a resumable parse. */\nexport type Checkpoints = Map<object, Map<number, unknown>>\n\n/** Takes (and removes) the checkpoint of `key` entered at `offset`, if any. */\nexport const take = (state: State<any>, key: object, offset: number): unknown => {\n const byKey = state.resume?.get(key)\n if (byKey === undefined) return undefined\n const checkpoint = byKey.get(offset)\n if (checkpoint !== undefined && !(checkpoint instanceof Done)) byKey.delete(offset)\n return checkpoint\n}\n\n/** The result of a repetition that completed, and where it ended. */\nexport class Done {\n constructor(\n readonly value: unknown,\n readonly pos: number\n ) {}\n}\n\n/**\n * Returns `value`, the result of a repetition entered at `entry`; when the\n * repetition was resumed from a checkpoint, records it as {@link Done}.\n */\nexport const done = <A>(state: State<any>, key: object, entry: number, resumed: boolean, value: A): A => {\n if (resumed && state.resume !== undefined) save(state, key, entry, new Done(value, state.pos))\n return value\n}\n\n/** Records the checkpoint of `key` entered at `offset`. */\nexport const save = (state: State<any>, key: object, offset: number, checkpoint: unknown): void => {\n const resume = state.resume\n if (resume === undefined) return\n let byKey = resume.get(key)\n if (byKey === undefined) resume.set(key, (byKey = new Map()))\n byKey.set(offset, checkpoint)\n}\n"],"mappings":";;AA0BA,MAAa,QAAQ,OAAmB,KAAa,WAA4B;CAC/E,MAAM,QAAQ,MAAM,QAAQ,IAAI,GAAG;CACnC,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,MAAM,aAAa,MAAM,IAAI,MAAM;CACnC,IAAI,eAAe,KAAA,KAAa,EAAE,sBAAsB,OAAO,MAAM,OAAO,MAAM;CAClF,OAAO;AACT;;AAGA,IAAa,OAAb,MAAkB;CAEL;CACA;CAFX,YACE,OACA,KACA;EAFS,KAAA,QAAA;EACA,KAAA,MAAA;CACR;AACL;;;;;AAMA,MAAa,QAAW,OAAmB,KAAa,OAAe,SAAkB,UAAgB;CACvG,IAAI,WAAW,MAAM,WAAW,KAAA,GAAW,KAAK,OAAO,KAAK,OAAO,IAAI,KAAK,OAAO,MAAM,GAAG,CAAC;CAC7F,OAAO;AACT;;AAGA,MAAa,QAAQ,OAAmB,KAAa,QAAgB,eAA8B;CACjG,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,KAAA,GAAW;CAC1B,IAAI,QAAQ,OAAO,IAAI,GAAG;CAC1B,IAAI,UAAU,KAAA,GAAW,OAAO,IAAI,KAAM,wBAAQ,IAAI,IAAI,CAAE;CAC5D,MAAM,IAAI,QAAQ,UAAU;AAC9B"}
1
+ {"version":3,"file":"resume.js","names":[],"sources":["../../src/internal/resume.ts"],"sourcesContent":["/**\n * Checkpoints for resumable (streaming) parses.\n *\n * In partial mode a parser only succeeds on what it has seen, so a value\n * parsed from a prefix of the input stays the same when more input\n * arrives. A repetition that runs out of input mid-way can therefore record\n * how far it got (its accumulator and position) before the failure\n * propagates. When the parse is attempted again with more input, the same\n * repetition, entered at the same offset, takes its checkpoint and carries\n * on from there instead of re-parsing every element.\n *\n * Checkpoints are keyed by a per-parser key and the offset the repetition\n * started at. Taking a checkpoint removes it, so its accumulator has a\n * single owner; the repetition saves a new one if it runs out again.\n *\n * A resumed repetition that then completes leaves a {@link Done}\n * checkpoint with its result, since the input may still run out after it\n * (in trailing whitespace, say) and the next attempt would otherwise parse\n * it all again. `Done` checkpoints stay in place when taken.\n */\nimport type { State } from \"../Input.js\"\nimport type { Key } from \"./key.js\"\n\n/** The checkpoints of a resumable parse. */\nexport type Checkpoints = Map<Key, Map<number, unknown>>\n\n/** Takes (and removes) the checkpoint of `key` entered at `offset`, if any. */\nexport const take = (state: State<any>, key: Key, offset: number): unknown => {\n const byKey = state.resume?.get(key)\n if (byKey === undefined) return undefined\n const checkpoint = byKey.get(offset)\n if (checkpoint !== undefined && !(checkpoint instanceof Done)) byKey.delete(offset)\n return checkpoint\n}\n\n/** The result of a repetition that completed, and where it ended. */\nexport class Done {\n constructor(\n readonly value: unknown,\n readonly pos: number\n ) {}\n}\n\n/**\n * Returns `value`, the result of a repetition entered at `entry`; when the\n * repetition was resumed from a checkpoint, records it as {@link Done}.\n */\nexport const done = <A>(state: State<any>, key: Key, entry: number, resumed: boolean, value: A): A => {\n if (resumed && state.resume !== undefined) save(state, key, entry, new Done(value, state.pos))\n return value\n}\n\n/** Records the checkpoint of `key` entered at `offset`. */\nexport const save = (state: State<any>, key: Key, offset: number, checkpoint: unknown): void => {\n const resume = state.resume\n if (resume === undefined) return\n let byKey = resume.get(key)\n if (byKey === undefined) resume.set(key, (byKey = new Map()))\n byKey.set(offset, checkpoint)\n}\n"],"mappings":";;AA2BA,MAAa,QAAQ,OAAmB,KAAU,WAA4B;CAC5E,MAAM,QAAQ,MAAM,QAAQ,IAAI,GAAG;CACnC,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,MAAM,aAAa,MAAM,IAAI,MAAM;CACnC,IAAI,eAAe,KAAA,KAAa,EAAE,sBAAsB,OAAO,MAAM,OAAO,MAAM;CAClF,OAAO;AACT;;AAGA,IAAa,OAAb,MAAkB;CAEL;CACA;CAFX,YACE,OACA,KACA;EAFS,KAAA,QAAA;EACA,KAAA,MAAA;CACR;AACL;;;;;AAMA,MAAa,QAAW,OAAmB,KAAU,OAAe,SAAkB,UAAgB;CACpG,IAAI,WAAW,MAAM,WAAW,KAAA,GAAW,KAAK,OAAO,KAAK,OAAO,IAAI,KAAK,OAAO,MAAM,GAAG,CAAC;CAC7F,OAAO;AACT;;AAGA,MAAa,QAAQ,OAAmB,KAAU,QAAgB,eAA8B;CAC9F,MAAM,SAAS,MAAM;CACrB,IAAI,WAAW,KAAA,GAAW;CAC1B,IAAI,QAAQ,OAAO,IAAI,GAAG;CAC1B,IAAI,UAAU,KAAA,GAAW,OAAO,IAAI,KAAM,wBAAQ,IAAI,IAAI,CAAE;CAC5D,MAAM,IAAI,QAAQ,UAAU;AAC9B"}
@@ -1,6 +1,5 @@
1
1
  import { Fail, State } from "../Input.js";
2
2
  import { ParserLike } from "./node.js";
3
- //#region src/internal/run.d.ts
4
3
  /**
5
4
  * Runs `p` on `state` from `state.pos`: its compiled form when it has one
6
5
  * and the state allows it, else its step. A compiled run that fails is
@@ -11,5 +10,4 @@ import { ParserLike } from "./node.js";
11
10
  * with streaming checkpoints) use the resumable build.
12
11
  */
13
12
  export declare const runOn: <A>(p: ParserLike, step: (state: State<any>) => A | Fail, state: State<any>, diagnostics?: boolean) => A | Fail;
14
- //#endregion
15
13
  //# sourceMappingURL=run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","names":[],"sources":["../../src/internal/run.ts"],"mappings":";;;;;;;;;;;;qBAoBa,QAAS,GACpB,GAAG,YACH,OAAO,OAAO,eAAe,IAAI,MACjC,OAAO,YACP,0BACC,IAAI"}
1
+ {"version":3,"file":"run.d.ts","names":[],"sources":["../../src/internal/run.ts"],"mappings":";;;;;;;;;;;qBAoBa,QAAS,GACpB,GAAG,YACH,OAAO,OAAO,eAAe,IAAI,MACjC,OAAO,YACP,0BACC,IAAI"}
@@ -1,7 +1,7 @@
1
1
  import { Fail } from "../Input.js";
2
2
  import * as Registry from "./compiler/registry.js";
3
3
  import * as Stack from "./stack.js";
4
- //#region src/internal/run.ts
4
+ // src/internal/run.ts
5
5
  /**
6
6
  * Running a parser on a caller-owned `State`, compiled when possible.
7
7
  *
@@ -24,13 +24,12 @@ const runOn = (p, step, state, diagnostics = true) => {
24
24
  const start = state.pos;
25
25
  const a = Stack.run(compiled, state);
26
26
  if (a !== Fail) return a;
27
- state.pos = start;
27
+ state.rewind(start);
28
28
  if (!diagnostics) return Fail;
29
29
  }
30
30
  }
31
31
  return Stack.run(step, state);
32
32
  };
33
- //#endregion
34
33
  export { runOn };
35
34
 
36
35
  //# sourceMappingURL=run.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","names":[],"sources":["../../src/internal/run.ts"],"sourcesContent":["/**\n * Running a parser on a caller-owned `State`, compiled when possible.\n *\n * Shared by `Parser.run` and `ParserStream.parseMany`, which keep one\n * state across many small runs.\n */\nimport { Fail, type State } from \"../Input.js\"\nimport * as Registry from \"./compiler/registry.js\"\nimport type { ParserLike } from \"./node.js\"\nimport * as Stack from \"./stack.js\"\n\n/**\n * Runs `p` on `state` from `state.pos`: its compiled form when it has one\n * and the state allows it, else its step. A compiled run that fails is\n * thrown away and the step runs again from the same position, so a\n * failure leaves the state exactly as the interpreter would; with\n * `diagnostics` false it is not, and the state keeps the compiled run's\n * `mode`, with the cursor back at the start. Partial states (and states\n * with streaming checkpoints) use the resumable build.\n */\nexport const runOn = <A>(\n p: ParserLike,\n step: (state: State<any>) => A | Fail,\n state: State<any>,\n diagnostics: boolean = true\n): A | Fail => {\n if (state.tracer === undefined && state.recovered === undefined && state.syntax === undefined) {\n const compiled = Registry.stepFor(p, state, state.partial || state.resume !== undefined)\n if (compiled !== undefined) {\n const start = state.pos\n const a = Stack.run(compiled, state)\n if (a !== Fail) {\n // SAFETY: the compiled step returns what the parser's step returns\n return a as A\n }\n state.pos = start\n if (!diagnostics) return Fail\n }\n }\n return Stack.run(step, state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,SACX,GACA,MACA,OACA,cAAuB,SACV;CACb,IAAI,MAAM,WAAW,KAAA,KAAa,MAAM,cAAc,KAAA,KAAa,MAAM,WAAW,KAAA,GAAW;EAC7F,MAAM,WAAW,SAAS,QAAQ,GAAG,OAAO,MAAM,WAAW,MAAM,WAAW,KAAA,CAAS;EACvF,IAAI,aAAa,KAAA,GAAW;GAC1B,MAAM,QAAQ,MAAM;GACpB,MAAM,IAAI,MAAM,IAAI,UAAU,KAAK;GACnC,IAAI,MAAM,MAER,OAAO;GAET,MAAM,MAAM;GACZ,IAAI,CAAC,aAAa,OAAO;EAC3B;CACF;CACA,OAAO,MAAM,IAAI,MAAM,KAAK;AAC9B"}
1
+ {"version":3,"file":"run.js","names":[],"sources":["../../src/internal/run.ts"],"sourcesContent":["/**\n * Running a parser on a caller-owned `State`, compiled when possible.\n *\n * Shared by `Parser.run` and `ParserStream.parseMany`, which keep one\n * state across many small runs.\n */\nimport { Fail, type State } from \"../Input.js\"\nimport * as Registry from \"./compiler/registry.js\"\nimport type { ParserLike } from \"./node.js\"\nimport * as Stack from \"./stack.js\"\n\n/**\n * Runs `p` on `state` from `state.pos`: its compiled form when it has one\n * and the state allows it, else its step. A compiled run that fails is\n * thrown away and the step runs again from the same position, so a\n * failure leaves the state exactly as the interpreter would; with\n * `diagnostics` false it is not, and the state keeps the compiled run's\n * `mode`, with the cursor back at the start. Partial states (and states\n * with streaming checkpoints) use the resumable build.\n */\nexport const runOn = <A>(\n p: ParserLike,\n step: (state: State<any>) => A | Fail,\n state: State<any>,\n diagnostics: boolean = true\n): A | Fail => {\n if (state.tracer === undefined && state.recovered === undefined && state.syntax === undefined) {\n const compiled = Registry.stepFor(p, state, state.partial || state.resume !== undefined)\n if (compiled !== undefined) {\n const start = state.pos\n const a = Stack.run(compiled, state)\n if (a !== Fail) {\n // SAFETY: the compiled step returns what the parser's step returns\n return a as A\n }\n state.rewind(start)\n if (!diagnostics) return Fail\n }\n }\n return Stack.run(step, state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,SACX,GACA,MACA,OACA,cAAuB,SACV;CACb,IAAI,MAAM,WAAW,KAAA,KAAa,MAAM,cAAc,KAAA,KAAa,MAAM,WAAW,KAAA,GAAW;EAC7F,MAAM,WAAW,SAAS,QAAQ,GAAG,OAAO,MAAM,WAAW,MAAM,WAAW,KAAA,CAAS;EACvF,IAAI,aAAa,KAAA,GAAW;GAC1B,MAAM,QAAQ,MAAM;GACpB,MAAM,IAAI,MAAM,IAAI,UAAU,KAAK;GACnC,IAAI,MAAM,MAER,OAAO;GAET,MAAM,OAAO,KAAK;GAClB,IAAI,CAAC,aAAa,OAAO;EAC3B;CACF;CACA,OAAO,MAAM,IAAI,MAAM,KAAK;AAC9B"}
@@ -1,5 +1,4 @@
1
1
  import { Fail, State } from "../Input.js";
2
- //#region src/internal/stack.d.ts
3
2
  /**
4
3
  * Whether `e` is the engine's call-stack overflow: a `RangeError` in V8
5
4
  * and JavaScriptCore, an `InternalError` ("too much recursion") in
@@ -12,5 +11,4 @@ export declare const isStackOverflow: (e: unknown) => boolean;
12
11
  * propagate.
13
12
  */
14
13
  export declare const run: <S extends State<any>, A>(step: (state: S) => A, state: S) => A | Fail;
15
- //#endregion
16
14
  //# sourceMappingURL=stack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stack.d.ts","names":[],"sources":["../../src/internal/stack.ts"],"mappings":";;;;;;;qBAoBa,kBAAmB;;;;;;qBAanB,MAAO,UAAU,YAAY,GAAG,OAAO,OAAO,MAAM,GAAG,OAAO,MAAI,IAAI"}
1
+ {"version":3,"file":"stack.d.ts","names":[],"sources":["../../src/internal/stack.ts"],"mappings":";;;;;;qBAoBa,kBAAmB;;;;;;qBAanB,MAAO,UAAU,YAAY,GAAG,OAAO,OAAO,MAAM,GAAG,OAAO,MAAI,IAAI"}
@@ -1,5 +1,5 @@
1
1
  import * as Predicate from "effect/Predicate";
2
- //#region src/internal/stack.ts
2
+ // src/internal/stack.ts
3
3
  /**
4
4
  * Call-stack overflows.
5
5
  *
@@ -30,7 +30,6 @@ const run = (step, state) => {
30
30
  return state.failMessage("Cut", "TooDeep", tooDeepMessage);
31
31
  }
32
32
  };
33
- //#endregion
34
33
  export { isStackOverflow, run };
35
34
 
36
35
  //# sourceMappingURL=stack.js.map
@@ -1,7 +1,6 @@
1
- import { ErrMode, Fail, Failure, Input, Source, State } from "../Input.js";
2
- import * as Context from "effect/Context";
1
+ import { ErrMode, Failure, Input, State } from "../Input.js";
2
+ import { Key } from "./key.js";
3
3
  import { Encoding } from "../Encoding.js";
4
- //#region src/internal/syntax.d.ts
5
4
  /** What a failure inside an `ERROR` node was. Offsets are relative to the node. */
6
5
  export interface ErrorInfo {
7
6
  readonly failure: Failure;
@@ -12,7 +11,7 @@ export declare class Green {
12
11
  readonly kind: string;
13
12
  readonly named: boolean;
14
13
  /** The `Syntax.node` that built it; `undefined` for roots and errors, which are never reused alone. */
15
- readonly key: object | undefined;
14
+ readonly key: Key | undefined;
16
15
  readonly width: number;
17
16
  /** How far its parse looked, relative to its start (at least `width`). */
18
17
  readonly lookahead: number;
@@ -30,7 +29,7 @@ export declare class Green {
30
29
  readonly diagnostics: Diagnostics | undefined;
31
30
  constructor(kind: string, named: boolean,
32
31
  /** The `Syntax.node` that built it; `undefined` for roots and errors, which are never reused alone. */
33
- key: object | undefined, width: number,
32
+ key: Key | undefined, width: number,
34
33
  /** How far its parse looked, relative to its start (at least `width`). */
35
34
  lookahead: number, children: ReadonlyArray<Green>,
36
35
  /** The children's starts, relative to this node's start. */
@@ -91,7 +90,7 @@ export interface Previous {
91
90
  }
92
91
  /** The hooks that `Syntax` combinators and `Parser.resumeAfter`/`retryAfter` call. */
93
92
  export interface Builder {
94
- node(state: State<any>, step: (state: State<any>) => unknown, key: object, kind: string, named: boolean): unknown;
93
+ node(state: State<any>, step: (state: State<any>) => unknown, key: Key, kind: string, named: boolean): unknown;
95
94
  field(state: State<any>, step: (state: State<any>) => unknown, name: string): unknown;
96
95
  /** After error recovery: `[start, pos)` was skipped after `failure`. */
97
96
  skipped(start: number, failure: Failure, mode: ErrMode): void;
@@ -100,27 +99,39 @@ export interface Builder {
100
99
  * where they leave the cursor or record a failure.
101
100
  */
102
101
  read(end: number): void;
102
+ /** A failure or hint was recorded at `offset`. */
103
+ reach(offset: number): void;
104
+ /** The cursor moved back from `from` to `to` (see `State.rewind`). */
105
+ rewound(from: number, to: number): void;
103
106
  }
104
- /** The parse state of a `Syntax` parse. */
105
- export declare class SyntaxState<I extends Input = Input> extends State<I> implements Builder {
106
- cursor: number;
107
- /** The furthest position the cursor reached, or failure recorded, since the innermost open node started. */
107
+ /**
108
+ * The tree builder of a `Syntax` parse, reached through `state.syntax`. It
109
+ * is not a `State` subclass: one class of state keeps every parser's cursor
110
+ * and failure accesses monomorphic, whether or not the program also builds
111
+ * syntax trees. `State` calls {@link reach} and {@link rewound} itself.
112
+ */
113
+ export declare class SyntaxBuilder implements Builder {
114
+ readonly state: State<any>;
115
+ readonly previous: Previous | undefined;
116
+ /**
117
+ * The furthest position the cursor reached before a rewind, or failure
118
+ * recorded, since the innermost open node started; {@link looked} adds
119
+ * where the cursor is now.
120
+ */
108
121
  highWater: number;
109
122
  /** Completed nodes waiting for their parent, in input order. */
110
- stack: Array<Child>;
111
- previous: Previous | undefined;
123
+ readonly stack: Array<Child>;
112
124
  /** How many nodes were reused from the previous tree. */
113
125
  reused: number;
114
126
  /** Where {@link find} found the last node it found. */
115
127
  lastParent: Green | undefined;
116
128
  lastParentStart: number;
117
- constructor(source: I | Source<I>, options: {
118
- readonly context?: Context.Context<never> | undefined;
119
- }, previous: Previous | undefined);
120
- failWith(mode: ErrMode, failure: Failure): Fail;
121
- failTies(head: Failure, tie1: Failure, tie2: Failure | undefined): Fail;
122
- setHint(offset: number, expected: ReadonlyArray<string>): void;
123
- node(state: State<any>, step: (state: State<any>) => unknown, key: object, kind: string, named: boolean): unknown;
129
+ constructor(state: State<any>, previous: Previous | undefined);
130
+ reach(offset: number): void;
131
+ rewound(from: number, to: number): void;
132
+ /** How far the parse looked: {@link highWater}, or the cursor if it is further. */
133
+ private looked;
134
+ node(state: State<any>, step: (state: State<any>) => unknown, key: Key, kind: string, named: boolean): unknown;
124
135
  read(end: number): void;
125
136
  /** Records `failure` as the furthest failure if it is, as `failWith` does. */
126
137
  private deepen;
@@ -142,6 +153,5 @@ export declare class SyntaxState<I extends Input = Input> extends State<I> imple
142
153
  /** The node of the previous tree built by `key` at `pos` (in the new input), if it can be reused. */
143
154
  private reusable;
144
155
  }
145
- //#endregion
146
156
  export {};
147
157
  //# sourceMappingURL=syntax.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"syntax.d.ts","names":[],"sources":["../../src/internal/syntax.ts"],"mappings":";;;;;iBAmCiB;WACN,SAAS;WACT,MAAM;;;qBAIJ;WAEA;WACA;;WAEA;WACA;;WAEA;WACA,UAAU,cAAc;;WAExB,SAAS;;WAET,QAAQ;WACR;;WAEA,OAAO;;WAEP;;WAEA,aAAa;EAlBb,YAAA,cACA;;EAEA,yBACA;;EAEA,mBACA,UAAU,cAAc;;EAExB,SAAS;;EAET,QAAQ,+CACR;;EAEA,OAAO;;EAEP;;EAEA,aAAa;;;;;;;iBAST;;WAEN,SAAS;;WAET;;WAEA;WACA,cAAc;;;cAInB;WAEO,OAAO;WACP;WACA;EACF;EAHE,YAAA,OAAO,OACP,eACA,aACF;;qBAIE;;qBAMA,WAAY,GAAG,SAAS,kBAAgB;;;;;iBAuCpC;WACN;WACA;WACA;;;iBAIM;WACN,MAAM;WACN;WACA;WACA,UAAU,cAAc;WACxB,OAAO;;WAEP;WACA,UAAU;;;iBAIJ;EACf,KAAK,OAAO,YAAY,OAAO,OAAO,wBAAwB,aAAa,cAAc;EACzF,MAAM,OAAO,YAAY,OAAO,OAAO,wBAAwB;;EAE/D,QAAQ,eAAe,SAAS,SAAS,MAAM;;;;;EAK/C,KAAK;;;qBAIM,YAAY,UAAU,QAAQ,eAAe,MAAM,cAAc;EAGpE;;EAEA;;EAEA,OAAO,MAAM;EACb,UAAU;;EAEV;;EAEA,YAAY;EACZ;EAsBN,YAAA,QAAQ,IAAI,OAAO,IACnB;aACW,UAAU,QAAQ;KAE7B,UAAU;EAcH,SAAS,MAAM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