@thomasfosterau/effect-parse 0.2.0 → 0.3.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.
package/README.md CHANGED
@@ -54,6 +54,7 @@ The package was developed as `effect-nom`. Releases and the changelog are manage
54
54
  - [Errors](#errors)
55
55
  - [Streaming and partial input](#streaming-and-partial-input)
56
56
  - [Services](#services)
57
+ - [Parsers from schemas](#parsers-from-schemas)
57
58
  - [Unicode text and encodings](#unicode-text-and-encodings)
58
59
  - [Syntax trees and incremental parsing](#syntax-trees-and-incremental-parsing)
59
60
  - [Modules](#modules)
@@ -212,6 +213,7 @@ Repetition ranges follow winnow: `Parser.repeat(p)` matches zero or more times,
212
213
  | `Parser.parseRecoverable(p, input)` | `{ value: Option<A>, errors }` with error recovery enabled |
213
214
  | `ParserStream.parseMany(p)` | `Stream<I> => Stream<A>` (see [Streaming](#streaming-and-partial-input)) |
214
215
  | `ParserSchema.make(p)` | a `Schema` decoding strings with the parser |
216
+ | `ParserSchema.fromSchema(s)` | a `Schema` decoding strings with the parser derived from `s`, and encoding with the derived printer (see [Parsers from schemas](#parsers-from-schemas)) |
215
217
  | `Syntax.parse(p, input)` | a `Syntax.Tree`: a syntax tree, the value and the errors (see [Syntax trees](#syntax-trees-and-incremental-parsing)) |
216
218
 
217
219
  Every `Parser` runner takes an `offset` option, to start parsing part-way into the input. The result is that of parsing `input.slice(offset)`, without the copy, and offsets (`Done`'s `offset`, spans, `ParseError` offsets, lines and columns) are positions in the whole input. A lexer can read one token at a time from a buffer, compiled parsers included:
@@ -378,6 +380,47 @@ Parser.parse(Parser.provideService(number, Radix, 16), "ff") // 255
378
380
  Parser.parseEffect(number, "777").pipe(Effect.provideService(Radix, 8)) // Effect<511>
379
381
  ```
380
382
 
383
+ ## Parsers from schemas
384
+
385
+ `ParserSchema.toParser` derives a parser from an Effect `Schema`, and `ParserSchema.toPrinter` the printer that writes the same text, so a text format can be declared once, as the schema of the values it holds. Annotations, set with `ParserSchema.annotate` (under the key `ParserSchema.annotationKey`), say how each part is written: a `prefix` and `suffix`, the `separator` between fields, elements or entries, the `keySeparator` of `key=value` entries, whether `whitespace` may surround that text, or a `parser` and `print` that replace the derived ones.
386
+
387
+ ```ts
388
+ import { Schema } from "effect"
389
+
390
+ const Point = Schema.Struct({ x: Schema.Int, y: Schema.Int }).pipe(
391
+ ParserSchema.annotate({ prefix: "(", separator: ",", suffix: ")", whitespace: true })
392
+ )
393
+
394
+ const Config = Schema.Struct({
395
+ name: Schema.String,
396
+ origin: Point,
397
+ color: Schema.optionalKey(
398
+ Schema.Int.pipe(ParserSchema.annotate({ parser: Ascii.hexUint, print: (n) => n.toString(16), prefix: "#" }))
399
+ )
400
+ }).pipe(ParserSchema.annotate({ separator: ";", keySeparator: "=" }))
401
+
402
+ const config = ParserSchema.toParser(Config)
403
+ Parser.parse(config, "origin=( 1, -2 );name=main;color=#ff")
404
+ // Result.succeed({ name: "main", origin: { x: 1, y: -2 }, color: 255 })
405
+
406
+ Parser.parse(config, "name=main;origin=(1,x)")
407
+ // Result.fail(ParseError):
408
+ // Parse error at line 1, column 21:
409
+ // 1 | name=main;origin=(1,x)
410
+ // | ^
411
+ // expected one of "+-" or digit, found "x"
412
+
413
+ const print = ParserSchema.toPrinter(Config)
414
+ print({ name: "main", origin: { x: 1, y: -2 }, color: 255 })
415
+ // Result.succeed("name=main;origin=(1,-2);color=#ff")
416
+ ```
417
+
418
+ Without annotations, a struct or tuple is its fields in order, an array its elements, a union its first member that parses, and a `suspend`ed schema recursion. A string runs to the next separator or suffix; a number is decimal, and an integer when the schema checks `isInt`. A record, or a struct with a `keySeparator`, is `key=value` entries in any order. A schema's checks and transformations (a `Class`, `NumberFromString`, a brand) run as `Schema.decode` runs them, and their failures are parse errors whose `cause` is the `SchemaError`. The doc comment of `toParser` lists every rule.
419
+
420
+ A printer writes the text its parser reads, without optional whitespace, and fails with a `SchemaError` on a value it cannot write so that it reads back: a string holding the separator that would end it, or a part with a `parser` but no `print`.
421
+
422
+ A derived parser is an ordinary parser: it composes with the combinators, and the [compilers](#compiled-parsers) compile it. `ParserSchema.fromSchema(schema)` wraps the parser and the printer as a `Schema` from `string`. Encoding parses the printed text back, and fails if that gives a different value, so decoding what it encoded always gives the value back, even where the grammar is ambiguous.
423
+
381
424
  ## Unicode text and encodings
382
425
 
383
426
  `Token` reads strings by code point, but the `Ascii` character classes and numbers only cover ASCII, and they treat bytes as ASCII. The `Text` module adds Unicode parsers that work with any encoding. `Text.make(encoding)` builds a set of parsers (`Text.TextParsers<I>`), and sets are provided for the common encodings:
@@ -480,7 +523,7 @@ On a 0.58 M-character JSON document (`vp run bench:syntax`), building the tree t
480
523
  | `Compiler` | `jit`, `closure`: [compiled parsers](#compiled-parsers) | — |
481
524
  | `ParseError` | the error type, `lineColumn`, `formatExpected` | `error` |
482
525
  | `ParserStream` | `parseMany`, `parseAll` over Effect `Stream`s | `Partial` / `streaming` |
483
- | `ParserSchema` | `make`: a `Schema` from a parser | — |
526
+ | `ParserSchema` | `make`: a `Schema` from a parser; `toParser`, `toPrinter`, `fromSchema`, `annotate`: a parser and printer from an annotated `Schema` | — |
484
527
  | `Syntax` | syntax trees: `node`, `token`, `field`, `parse`, incremental `reparse` and `replace`, `Tree`, `SyntaxNode`, `TreeCursor` | — (Tree-sitter) |
485
528
  | `Nom` | nom names and argument orders (`tag`, `many0`, `separatedList1`, `mapRes`, …) | nom |
486
529
  | `Input` | input types and the `State` cursor for `Parser.make` | `stream` |
@@ -1,5 +1,6 @@
1
- import { Fail, mergeFailures } from "./Input.js";
1
+ import { Fail } from "./Input.js";
2
2
  import { make as make$1 } from "./Parser.js";
3
+ import { TiedFailures } from "./internal/ties.js";
3
4
  //#region src/Expression.ts
4
5
  /**
5
6
  * A prefix operator, e.g. unary minus.
@@ -70,7 +71,7 @@ const make = (options) => {
70
71
  const postfixes = options.operators.filter((o) => o._tag === "Postfix");
71
72
  const infixes = options.operators.filter((o) => o._tag === "Infix");
72
73
  let matched;
73
- let failure;
74
+ const failures = new TiedFailures();
74
75
  const tryOps = (state, ops, mustConsume) => {
75
76
  const start = state.pos;
76
77
  for (let i = 0; i < ops.length; i++) {
@@ -84,14 +85,14 @@ const make = (options) => {
84
85
  return i;
85
86
  }
86
87
  if (state.mode !== "Backtrack") return -2;
87
- failure = failure === void 0 ? state.failure : mergeFailures(failure, state.failure);
88
88
  state.pos = start;
89
+ failures.add(state);
89
90
  }
90
91
  return -1;
91
92
  };
92
93
  const expr = (state, minPower) => {
93
94
  let lhs;
94
- failure = void 0;
95
+ failures.clear();
95
96
  const p = tryOps(state, prefixes, true);
96
97
  if (p === -2) return Fail;
97
98
  if (p >= 0) {
@@ -101,16 +102,24 @@ const make = (options) => {
101
102
  if (operandValue === Fail) return Fail;
102
103
  lhs = op.fold(opOut, operandValue);
103
104
  } else {
104
- const prefixFailure = failure;
105
+ const prefixFailure = failures.failure;
106
+ const prefixTie1 = failures.tie1;
107
+ const prefixTie2 = failures.tie2;
105
108
  lhs = operand(state);
106
109
  if (lhs === Fail) {
107
- if (prefixFailure !== void 0 && state.mode === "Backtrack") state.failWith("Backtrack", mergeFailures(prefixFailure, state.failure));
110
+ if (prefixFailure !== void 0 && state.mode === "Backtrack") {
111
+ failures.failure = prefixFailure;
112
+ failures.tie1 = prefixTie1;
113
+ failures.tie2 = prefixTie2;
114
+ failures.add(state);
115
+ failures.fail(state);
116
+ }
108
117
  return Fail;
109
118
  }
110
119
  }
111
120
  while (true) {
112
121
  const start = state.pos;
113
- failure = void 0;
122
+ failures.clear();
114
123
  const q = tryOps(state, postfixes, true);
115
124
  if (q === -2) return Fail;
116
125
  if (q >= 0) {
@@ -122,12 +131,10 @@ const make = (options) => {
122
131
  lhs = op.fold(lhs, matched);
123
132
  continue;
124
133
  }
125
- const postfixFailure = failure;
126
134
  const i = tryOps(state, infixes, false);
127
135
  if (i === -2) return Fail;
128
136
  if (i < 0) {
129
- const f = postfixFailure === void 0 ? failure : failure === void 0 ? postfixFailure : mergeFailures(postfixFailure, failure);
130
- if (f !== void 0 && f.offset === state.pos) state.setHint(f.offset, f.expected);
137
+ failures.hint(state);
131
138
  break;
132
139
  }
133
140
  const op = infixes[i];
@@ -1 +1 @@
1
- {"version":3,"file":"Expression.js","names":["makeParser"],"sources":["../src/Expression.ts"],"sourcesContent":["/**\n * Operator-precedence expression parsing with a Pratt parser (from\n * `nom-language`'s `precedence`, and winnow's expression parser).\n *\n * Describe the operand parser and a table of prefix, postfix and infix\n * operators with their precedence (higher binds tighter) and associativity.\n * Each operator carries a function that folds its operands into a result.\n *\n * @example\n * ```ts\n * import { Ascii, Expression, Parser, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const op = (s: string) => Parser.delimited(Ascii.space0, Token.literal(s), Ascii.space0)\n *\n * const arithmetic: Parser.Parser<number, string> = Expression.make({\n * operand: Parser.alt(\n * Ascii.decInt,\n * Parser.delimited(op(\"(\"), Parser.suspend(() => arithmetic), op(\")\"))\n * ),\n * operators: [\n * Expression.prefix(op(\"-\"), 4, (_, x) => -x),\n * Expression.postfix(op(\"!\"), 5, (x) => factorial(x)),\n * Expression.infixRight(op(\"^\"), 3, (l, _, r) => l ** r),\n * Expression.infixLeft(op(\"*\"), 2, (l, _, r) => l * r),\n * Expression.infixLeft(op(\"/\"), 2, (l, _, r) => l / r),\n * Expression.infixLeft(op(\"+\"), 1, (l, _, r) => l + r),\n * Expression.infixLeft(op(\"-\"), 1, (l, _, r) => l - r)\n * ]\n * })\n *\n * declare const factorial: (n: number) => number\n * Parser.parse(arithmetic, \"1 + 2 * 3 ^ 2\") // Result.succeed(19)\n * ```\n *\n * @since 0.1.0\n */\nimport type { Input, State } from \"./Input.js\"\nimport { Fail, mergeFailures } from \"./Input.js\"\nimport type { Failure } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { make as makeParser } from \"./Parser.js\"\n\n/**\n * An operator in an expression grammar.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Operator<A, E = never, R = never, I extends Input = string> =\n | Prefix<A, E, R, I>\n | Postfix<A, E, R, I>\n | Infix<A, E, R, I>\n\ninterface OperatorBase<E, R, I extends Input> {\n readonly parser: Parser<unknown, E, R, I>\n readonly precedence: number\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Prefix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Prefix\"\n readonly fold: (op: any, operand: A) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Postfix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Postfix\"\n readonly fold: (operand: A, op: any) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Infix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Infix\"\n readonly associativity: \"left\" | \"right\"\n readonly fold: (left: A, op: any, right: A) => A\n}\n\n/**\n * A prefix operator, e.g. unary minus.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const prefix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (op: O, operand: A) => A\n): Prefix<A, E, R, I> => ({ _tag: \"Prefix\", parser, precedence, fold })\n\n/**\n * A postfix operator, e.g. factorial or a function call suffix.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const postfix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (operand: A, op: O) => A\n): Postfix<A, E, R, I> => ({ _tag: \"Postfix\", parser, precedence, fold })\n\n/**\n * A left-associative infix operator: `a - b - c` is `(a - b) - c`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixLeft = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"left\", parser, precedence, fold })\n\n/**\n * A right-associative infix operator: `a ^ b ^ c` is `a ^ (b ^ c)`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixRight = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"right\", parser, precedence, fold })\n\ntype OpError<Op> = Op extends OperatorBase<infer E, infer _R, infer _I> ? E : never\ntype OpServices<Op> = Op extends OperatorBase<infer _E, infer R, infer _I> ? R : never\ntype OpInput<Op> = [Op] extends [never] ? Input : [Op] extends [OperatorBase<infer _E, infer _R, infer I>] ? I : never\n\n/**\n * Builds an expression parser from an operand parser and an operator table.\n *\n * Precedences are compared numerically: higher binds tighter. A prefix\n * operator applies to everything that binds tighter than it, so with `-`\n * at precedence 4 and `^` at 3, `-2 ^ 2` parses as `(-2) ^ 2`.\n *\n * When several operators of the same kind match, the first one in the\n * table wins, so list longer operators (`<=`) before their prefixes (`<`).\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const make = <A, E, R, I extends Input, const Ops extends ReadonlyArray<Operator<A, any, any, any>>>(options: {\n readonly operand: Parser<A, E, R, I>\n readonly operators: Ops\n}): Parser<A, E | OpError<Ops[number]>, R | OpServices<Ops[number]>, I & OpInput<Ops[number]>> => {\n const operand = options.operand.step\n const prefixes = options.operators.filter((o): o is Prefix<A, any, any, any> => o._tag === \"Prefix\")\n const postfixes = options.operators.filter((o): o is Postfix<A, any, any, any> => o._tag === \"Postfix\")\n const infixes = options.operators.filter((o): o is Infix<A, any, any, any> => o._tag === \"Infix\")\n\n // Attempts each operator in turn. Returns the index of the first match\n // (with its output in `matched`), -1 if none matched, or -2 on a fatal\n // failure. Expectations of failed attempts are accumulated in `failure`.\n let matched: unknown\n let failure: Failure | undefined\n const tryOps = (state: State<any>, ops: ReadonlyArray<OperatorBase<any, any, any>>, mustConsume: boolean): number => {\n const start = state.pos\n for (let i = 0; i < ops.length; i++) {\n const out = ops[i].parser.step(state)\n if (out !== Fail) {\n // A prefix or postfix operator matching nothing would apply forever\n if (mustConsume && state.pos === start) {\n state.failMessage(\"Cut\", \"Assert\", \"prefix and postfix operators must always consume\")\n return -2\n }\n matched = out\n return i\n }\n if (state.mode !== \"Backtrack\") return -2\n failure = failure === undefined ? state.failure : mergeFailures(failure, state.failure)\n state.pos = start\n }\n return -1\n }\n\n const expr = (state: State<any>, minPower: number): A | Fail => {\n let lhs: A | Fail\n failure = undefined\n const p = tryOps(state, prefixes, true)\n if (p === -2) return Fail\n if (p >= 0) {\n const op = prefixes[p]\n const opOut = matched\n const operandValue = expr(state, op.precedence * 2)\n if (operandValue === Fail) return Fail\n lhs = op.fold(opOut, operandValue)\n } else {\n const prefixFailure = failure\n lhs = operand(state)\n if (lhs === Fail) {\n if (prefixFailure !== undefined && state.mode === \"Backtrack\") {\n state.failWith(\"Backtrack\", mergeFailures(prefixFailure, state.failure))\n }\n return Fail\n }\n }\n\n while (true) {\n const start = state.pos\n failure = undefined\n const q = tryOps(state, postfixes, true)\n if (q === -2) return Fail\n if (q >= 0) {\n const op = postfixes[q]\n if (op.precedence * 2 < minPower) {\n state.pos = start\n break\n }\n lhs = op.fold(lhs, matched)\n continue\n }\n const postfixFailure = failure\n const i = tryOps(state, infixes, false)\n if (i === -2) return Fail\n if (i < 0) {\n const f =\n postfixFailure === undefined\n ? failure\n : failure === undefined\n ? postfixFailure\n : mergeFailures(postfixFailure, failure)\n if (f !== undefined && f.offset === state.pos) state.setHint(f.offset, f.expected)\n break\n }\n const op = infixes[i]\n const leftPower = op.precedence * 2\n if (leftPower < minPower) {\n state.pos = start\n break\n }\n const opOut = matched\n const rhs = expr(state, op.associativity === \"left\" ? leftPower + 1 : leftPower)\n if (rhs === Fail) return Fail\n lhs = op.fold(lhs, opOut, rhs)\n }\n return lhs\n }\n\n return makeParser((state: State<any>) => expr(state, 0), \"expression\")\n}\n"],"mappings":";;;;;;;;;AA4FA,MAAa,UACX,QACA,YACA,UACwB;CAAE,MAAM;CAAU;CAAQ;CAAY;AAAK;;;;;;;AAQrE,MA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vE"}
1
+ {"version":3,"file":"Expression.js","names":["makeParser"],"sources":["../src/Expression.ts"],"sourcesContent":["/**\n * Operator-precedence expression parsing with a Pratt parser (from\n * `nom-language`'s `precedence`, and winnow's expression parser).\n *\n * Describe the operand parser and a table of prefix, postfix and infix\n * operators with their precedence (higher binds tighter) and associativity.\n * Each operator carries a function that folds its operands into a result.\n *\n * @example\n * ```ts\n * import { Ascii, Expression, Parser, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const op = (s: string) => Parser.delimited(Ascii.space0, Token.literal(s), Ascii.space0)\n *\n * const arithmetic: Parser.Parser<number, string> = Expression.make({\n * operand: Parser.alt(\n * Ascii.decInt,\n * Parser.delimited(op(\"(\"), Parser.suspend(() => arithmetic), op(\")\"))\n * ),\n * operators: [\n * Expression.prefix(op(\"-\"), 4, (_, x) => -x),\n * Expression.postfix(op(\"!\"), 5, (x) => factorial(x)),\n * Expression.infixRight(op(\"^\"), 3, (l, _, r) => l ** r),\n * Expression.infixLeft(op(\"*\"), 2, (l, _, r) => l * r),\n * Expression.infixLeft(op(\"/\"), 2, (l, _, r) => l / r),\n * Expression.infixLeft(op(\"+\"), 1, (l, _, r) => l + r),\n * Expression.infixLeft(op(\"-\"), 1, (l, _, r) => l - r)\n * ]\n * })\n *\n * declare const factorial: (n: number) => number\n * Parser.parse(arithmetic, \"1 + 2 * 3 ^ 2\") // Result.succeed(19)\n * ```\n *\n * @since 0.1.0\n */\nimport type { Input, State } from \"./Input.js\"\nimport { Fail } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { make as makeParser } from \"./Parser.js\"\nimport { TiedFailures } from \"./internal/ties.js\"\n\n/**\n * An operator in an expression grammar.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Operator<A, E = never, R = never, I extends Input = string> =\n | Prefix<A, E, R, I>\n | Postfix<A, E, R, I>\n | Infix<A, E, R, I>\n\ninterface OperatorBase<E, R, I extends Input> {\n readonly parser: Parser<unknown, E, R, I>\n readonly precedence: number\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Prefix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Prefix\"\n readonly fold: (op: any, operand: A) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Postfix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Postfix\"\n readonly fold: (operand: A, op: any) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Infix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Infix\"\n readonly associativity: \"left\" | \"right\"\n readonly fold: (left: A, op: any, right: A) => A\n}\n\n/**\n * A prefix operator, e.g. unary minus.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const prefix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (op: O, operand: A) => A\n): Prefix<A, E, R, I> => ({ _tag: \"Prefix\", parser, precedence, fold })\n\n/**\n * A postfix operator, e.g. factorial or a function call suffix.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const postfix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (operand: A, op: O) => A\n): Postfix<A, E, R, I> => ({ _tag: \"Postfix\", parser, precedence, fold })\n\n/**\n * A left-associative infix operator: `a - b - c` is `(a - b) - c`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixLeft = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"left\", parser, precedence, fold })\n\n/**\n * A right-associative infix operator: `a ^ b ^ c` is `a ^ (b ^ c)`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixRight = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"right\", parser, precedence, fold })\n\ntype OpError<Op> = Op extends OperatorBase<infer E, infer _R, infer _I> ? E : never\ntype OpServices<Op> = Op extends OperatorBase<infer _E, infer R, infer _I> ? R : never\ntype OpInput<Op> = [Op] extends [never] ? Input : [Op] extends [OperatorBase<infer _E, infer _R, infer I>] ? I : never\n\n/**\n * Builds an expression parser from an operand parser and an operator table.\n *\n * Precedences are compared numerically: higher binds tighter. A prefix\n * operator applies to everything that binds tighter than it, so with `-`\n * at precedence 4 and `^` at 3, `-2 ^ 2` parses as `(-2) ^ 2`.\n *\n * When several operators of the same kind match, the first one in the\n * table wins, so list longer operators (`<=`) before their prefixes (`<`).\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const make = <A, E, R, I extends Input, const Ops extends ReadonlyArray<Operator<A, any, any, any>>>(options: {\n readonly operand: Parser<A, E, R, I>\n readonly operators: Ops\n}): Parser<A, E | OpError<Ops[number]>, R | OpServices<Ops[number]>, I & OpInput<Ops[number]>> => {\n const operand = options.operand.step\n const prefixes = options.operators.filter((o): o is Prefix<A, any, any, any> => o._tag === \"Prefix\")\n const postfixes = options.operators.filter((o): o is Postfix<A, any, any, any> => o._tag === \"Postfix\")\n const infixes = options.operators.filter((o): o is Infix<A, any, any, any> => o._tag === \"Infix\")\n\n // Attempts each operator in turn. Returns the index of the first match\n // (with its output in `matched`), -1 if none matched, or -2 on a fatal\n // failure. Failed attempts are folded into `failures`, merged only when\n // read (#44): a round in which an operator matches discards them unmerged.\n // Like `matched`, it is shared by nested expressions, which clear it.\n let matched: unknown\n const failures = new TiedFailures()\n const tryOps = (state: State<any>, ops: ReadonlyArray<OperatorBase<any, any, any>>, mustConsume: boolean): number => {\n const start = state.pos\n for (let i = 0; i < ops.length; i++) {\n const out = ops[i].parser.step(state)\n if (out !== Fail) {\n // A prefix or postfix operator matching nothing would apply forever\n if (mustConsume && state.pos === start) {\n state.failMessage(\"Cut\", \"Assert\", \"prefix and postfix operators must always consume\")\n return -2\n }\n matched = out\n return i\n }\n if (state.mode !== \"Backtrack\") return -2\n state.pos = start\n failures.add(state)\n }\n return -1\n }\n\n const expr = (state: State<any>, minPower: number): A | Fail => {\n let lhs: A | Fail\n failures.clear()\n const p = tryOps(state, prefixes, true)\n if (p === -2) return Fail\n if (p >= 0) {\n const op = prefixes[p]\n const opOut = matched\n const operandValue = expr(state, op.precedence * 2)\n if (operandValue === Fail) return Fail\n lhs = op.fold(opOut, operandValue)\n } else {\n const prefixFailure = failures.failure\n const prefixTie1 = failures.tie1\n const prefixTie2 = failures.tie2\n lhs = operand(state)\n if (lhs === Fail) {\n if (prefixFailure !== undefined && state.mode === \"Backtrack\") {\n // The operand may have parsed nested expressions, which reuse `failures`\n failures.failure = prefixFailure\n failures.tie1 = prefixTie1\n failures.tie2 = prefixTie2\n failures.add(state)\n failures.fail(state)\n }\n return Fail\n }\n }\n\n while (true) {\n const start = state.pos\n failures.clear()\n const q = tryOps(state, postfixes, true)\n if (q === -2) return Fail\n if (q >= 0) {\n const op = postfixes[q]\n if (op.precedence * 2 < minPower) {\n state.pos = start\n break\n }\n lhs = op.fold(lhs, matched)\n continue\n }\n // The infix attempts are folded on top of the postfix ones\n const i = tryOps(state, infixes, false)\n if (i === -2) return Fail\n if (i < 0) {\n failures.hint(state)\n break\n }\n const op = infixes[i]\n const leftPower = op.precedence * 2\n if (leftPower < minPower) {\n state.pos = start\n break\n }\n const opOut = matched\n const rhs = expr(state, op.associativity === \"left\" ? leftPower + 1 : leftPower)\n if (rhs === Fail) return Fail\n lhs = op.fold(lhs, opOut, rhs)\n }\n return lhs\n }\n\n return makeParser((state: State<any>) => expr(state, 0), \"expression\")\n}\n"],"mappings":";;;;;;;;;;AA4FA,MAAa,UACX,QACA,YACA,UACwB;CAAE,MAAM;CAAU;CAAQ;CAAY;AAAK;;;;;;;AAQrE,MAAa,WACX,QACA,YACA,UACyB;CAAE,MAAM;CAAW;CAAQ;CAAY;AAAK;;;;;;;AAQvE,MAAa,aACX,QAC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gB,SAAS;GAC/B,MAAM,aAAa,SAAS;GAC5B,MAAM,aAAa,SAAS;GAC5B,MAAM,QAAQ,KAAK;GACnB,IAAI,QAAQ,MAAM;IAChB,IAAI,kBAAkB,KAAA,KAAa,MAAM,SAAS,aAAa;KAE7D,SAAS,UAAU;KACnB,SAAS,OAAO;KAChB,SAAS,OAAO;KAChB,SAAS,IAAI,KAAK;KAClB,SAAS,KAAK,KAAK;IACrB;IACA,OAAO;GACT;EACF;EAEA,OAAO,MAAM;GACX,MAAM,QAAQ,MAAM;GACpB,SAAS,MAAM;GACf,MAAM,IAAI,OAAO,OAAO,WAAW,IAAI;GACvC,IAAI,MAAM,IAAI,OAAO;GACrB,IAAI,KAAK,GAAG;IACV,MAAM,KAAK,UAAU;IACrB,IAAI,GAAG,aAAa,IAAI,UAAU;KAChC,MAAM,MAAM;KACZ;IACF;IACA,MAAM,GAAG,KAAK,KAAK,OAAO;IAC1B;GACF;GAEA,MAAM,IAAI,OAAO,OAAO,SAAS,KAAK;GACtC,IAAI,MAAM,IAAI,OAAO;GACrB,IAAI,IAAI,GAAG;IACT,SAAS,KAAK,KAAK;IACnB;GACF;GACA,MAAM,KAAK,QAAQ;GACnB,MAAM,YAAY,GAAG,aAAa;GAClC,IAAI,YAAY,UAAU;IACxB,MAAM,MAAM;IACZ;GACF;GACA,MAAM,QAAQ;GACd,MAAM,MAAM,KAAK,OAAO,GAAG,kBAAkB,SAAS,YAAY,IAAI,SAAS;GAC/E,IAAI,QAAQ,MAAM,OAAO;GACzB,MAAM,GAAG,KAAK,KAAK,OAAO,GAAG;EAC/B;EACA,OAAO;CACT;CAEA,OAAOA,QAAY,UAAsB,KAAK,OAAO,CAAC,GAAG,YAAY;AACvE"}
package/dist/Input.d.ts CHANGED
@@ -173,8 +173,31 @@ export declare class State<I extends Input = Input> {
173
173
  context: Context.Context<never>;
174
174
  /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */
175
175
  mode: ErrMode;
176
- /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */
177
- failure: Failure;
176
+ /**
177
+ * The latest failure, kept unmerged: the failure is `failureHead` merged
178
+ * (as `mergeFailures` does) with `failureTie1` and then `failureTie2`, all
179
+ * at the same offset. `Parser.alt` records its tied branch failures here
180
+ * with {@link failTies} instead of merging them, so that an enclosing `alt`
181
+ * whose next branch succeeds never pays for the merge. Reading
182
+ * {@link failure} performs the merge, once.
183
+ *
184
+ * @internal
185
+ */
186
+ failureHead: Failure;
187
+ /** @internal */
188
+ failureTie1: Failure | undefined;
189
+ /** @internal */
190
+ failureTie2: Failure | undefined;
191
+ /** Backs {@link deepest}. @internal */
192
+ deepestFailure: Failure | undefined;
193
+ /**
194
+ * Whether the furthest failure is the latest failure, still unmerged, so
195
+ * that {@link deepest} is that failure once merged. Only set while
196
+ * `failureTie1` is.
197
+ *
198
+ * @internal
199
+ */
200
+ deepestIsLatest: boolean;
178
201
  /**
179
202
  * The offset of a recoverable failure that occurred without consuming
180
203
  * input (for example the last attempt of a `repeat`). Its
@@ -193,7 +216,8 @@ export declare class State<I extends Input = Input> {
193
216
  * recorded inside it when it commits, and `Parser.peek` and `Parser.not`
194
217
  * forget the failures of a lookahead that succeeded.
195
218
  */
196
- deepest: Failure | undefined;
219
+ get deepest(): Failure | undefined;
220
+ set deepest(failure: Failure | undefined);
197
221
  /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */
198
222
  recovered: Array<Failure> | undefined;
199
223
  /** When defined, `Parser.trace` reports events here. */
@@ -223,6 +247,11 @@ export declare class State<I extends Input = Input> {
223
247
  readonly context?: Context.Context<never> | undefined;
224
248
  readonly offset?: number | undefined;
225
249
  });
250
+ /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */
251
+ get failure(): Failure;
252
+ set failure(failure: Failure);
253
+ /** Merges the latest failure's ties into it (see {@link failureHead}). */
254
+ private settleFailure;
226
255
  /**
227
256
  * Prepares the state for another run over the same input, starting at
228
257
  * `offset`: afterwards it behaves exactly like
@@ -297,6 +326,14 @@ export declare class State<I extends Input = Input> {
297
326
  * Records the given failure and returns {@link Fail}.
298
327
  */
299
328
  failWith(mode: ErrMode, failure: Failure): Fail;
329
+ /**
330
+ * Records a recoverable failure made of tied failures, merged only when
331
+ * read: `failWith("Backtrack", f)` where `f` merges `head` with `tie1`
332
+ * and then `tie2` (all at the same offset), as `mergeFailures` would.
333
+ *
334
+ * @internal
335
+ */
336
+ failTies(head: Failure, tie1: Failure, tie2: Failure | undefined): Fail;
300
337
  /**
301
338
  * Replaces the details of the current failure (for example to add context),
302
339
  * keeping the record of the furthest failure consistent.
@@ -326,5 +363,13 @@ export declare const mergeExpected: (a: ReadonlyArray<string>, b: ReadonlyArray<
326
363
  * @internal
327
364
  */
328
365
  export declare const mergeFailures: (a: Failure, b: Failure) => Failure;
366
+ /**
367
+ * {@link mergeFailures} for two failures at the same offset, given their
368
+ * merged expectations (`mergeExpected(a.expected, b.expected)`, possibly
369
+ * memoised by the caller).
370
+ *
371
+ * @internal
372
+ */
373
+ export declare const mergeTiedFailures: (a: Failure, b: Failure, expected: ReadonlyArray<string>) => Failure;
329
374
  //#endregion
330
375
  //# sourceMappingURL=Input.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Input.d.ts","names":["SyntaxBuilder"],"sources":["../src/Input.ts"],"mappings":";;;;;;;;;;;;;;;;YAgCY,iBAAiB,aAAa;;;;;;;;;;;;;YAc9B,cAAc,kBAAkB;;;;;;;;YAShC,OAAO,KAAK,MAAM,YAAY,cAAc;;;;;;;;;;;;;;;qBAgB3C;GACV,QAAQ,cAAc;GACtB,UAAU,OAAO,QAAQ,OAAO,KAAK;;;;;;;;YAkB5B,MAAM,KAAK,4BAEnB,UAAU,sBAER,UAAU,oBAAoB,KAC5B;;;;;;;YASI,MAAM,KAAK,4BAEnB,UAAU,aACR,aACA,UAAU,oBAAoB,KAC5B,cAAc;;;;;;;;qBAUT;;;;;YAMD,cAAc;;;;;;;;;;;YAYd;;;;;;;qBAQC;;WAGA;;W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;;UAQb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6CR,MACE,iBACA;aACW;aACA,UAAU,QAAQ;;;;;EA0B/B;;;;EAOA;;;;EAOA,MAAM,eAAe,cAAc,MAAM;;;;EAezC,UAAU,MAAM,WAAW,WAAU,uBAA+B,kBAA4B;;;;EAOhG,IAAI,MAAM,WAAW,WAAU,uBAA+B,kBAA4B;;;;;EAQ1F,WAAW,gBAAgB,WAAU,wBAAgC;;;;;EAWrE,IAAI,MAAM,WAAW,UAAU,uBAAuB,iBAAiB;;;;EAOvE,UAAU,MAAM,SAAS,MAAM,WAAW,gBAAgB,kBAA4B;;;;EAOtF,YAAY,MAAM,SAAS,MAAM,WAAW,iBAAiB,kBAA4B;;;;EAOzF,SAAS,MAAM,SAAS,SAAS,UAAU;;;;;;;;EAuB3C,SAAS,MAAM,SAAS,MAAM,SAAS,MAAM,sBAAsB;;;;;EAcnE,eAAe,SAAS;;;;;;EAUxB,mBAAmB;;;;;;EAuBnB,QAAQ,gBAAgB,UAAU;;EAUlC,YAAY,gBAAgB,MAAM,WAAW,UAAU,wBAAwB;;;qBASpE,gBAAiB,GAAG,uBAAuB,GAAG,0BAAwB;;;;;;;qBAgBtE,gBAAiB,GAAG,SAAS,GAAG,YAAU;;;;;;;;qBAa1C,oBAAqB,GAAG,SAAS,GAAG,SAAS,UAAU,0BAAwB"}
package/dist/Input.js CHANGED
@@ -95,8 +95,31 @@ var State = class {
95
95
  context;
96
96
  /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */
97
97
  mode = "Backtrack";
98
- /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */
99
- failure;
98
+ /**
99
+ * The latest failure, kept unmerged: the failure is `failureHead` merged
100
+ * (as `mergeFailures` does) with `failureTie1` and then `failureTie2`, all
101
+ * at the same offset. `Parser.alt` records its tied branch failures here
102
+ * with {@link failTies} instead of merging them, so that an enclosing `alt`
103
+ * whose next branch succeeds never pays for the merge. Reading
104
+ * {@link failure} performs the merge, once.
105
+ *
106
+ * @internal
107
+ */
108
+ failureHead;
109
+ /** @internal */
110
+ failureTie1 = void 0;
111
+ /** @internal */
112
+ failureTie2 = void 0;
113
+ /** Backs {@link deepest}. @internal */
114
+ deepestFailure = void 0;
115
+ /**
116
+ * Whether the furthest failure is the latest failure, still unmerged, so
117
+ * that {@link deepest} is that failure once merged. Only set while
118
+ * `failureTie1` is.
119
+ *
120
+ * @internal
121
+ */
122
+ deepestIsLatest = false;
100
123
  /**
101
124
  * The offset of a recoverable failure that occurred without consuming
102
125
  * input (for example the last attempt of a `repeat`). Its
@@ -115,7 +138,14 @@ var State = class {
115
138
  * recorded inside it when it commits, and `Parser.peek` and `Parser.not`
116
139
  * forget the failures of a lookahead that succeeded.
117
140
  */
118
- deepest = void 0;
141
+ get deepest() {
142
+ if (this.deepestIsLatest) this.settleFailure();
143
+ return this.deepestFailure;
144
+ }
145
+ set deepest(failure) {
146
+ this.deepestIsLatest = false;
147
+ this.deepestFailure = failure;
148
+ }
119
149
  /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */
120
150
  recovered = void 0;
121
151
  /** When defined, `Parser.trace` reports events here. */
@@ -148,7 +178,35 @@ var State = class {
148
178
  this.partial = options?.partial ?? false;
149
179
  this.context = options?.context ?? Context.empty();
150
180
  this.inputKind = Predicate.isString(input) ? 0 : input instanceof Uint8Array ? 1 : 2;
151
- this.failure = initialFailure;
181
+ this.failureHead = initialFailure;
182
+ }
183
+ /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */
184
+ get failure() {
185
+ if (this.failureTie1 !== void 0) this.settleFailure();
186
+ return this.failureHead;
187
+ }
188
+ set failure(failure) {
189
+ if (this.deepestIsLatest) this.settleFailure();
190
+ this.failureHead = failure;
191
+ this.failureTie1 = void 0;
192
+ this.failureTie2 = void 0;
193
+ }
194
+ /** Merges the latest failure's ties into it (see {@link failureHead}). */
195
+ settleFailure() {
196
+ let failure = this.failureHead;
197
+ const tie1 = this.failureTie1;
198
+ if (tie1 !== void 0) {
199
+ failure = mergeTiedFailures(failure, tie1, mergeExpected(failure.expected, tie1.expected));
200
+ const tie2 = this.failureTie2;
201
+ if (tie2 !== void 0) failure = mergeTiedFailures(failure, tie2, mergeExpected(failure.expected, tie2.expected));
202
+ this.failureHead = failure;
203
+ this.failureTie1 = void 0;
204
+ this.failureTie2 = void 0;
205
+ }
206
+ if (this.deepestIsLatest) {
207
+ this.deepestFailure = failure;
208
+ this.deepestIsLatest = false;
209
+ }
152
210
  }
153
211
  /**
154
212
  * Prepares the state for another run over the same input, starting at
@@ -184,10 +242,13 @@ var State = class {
184
242
  this.partial = options?.partial ?? false;
185
243
  this.context = options?.context ?? Context.empty();
186
244
  this.mode = "Backtrack";
187
- this.failure = initialFailure;
245
+ this.failureHead = initialFailure;
246
+ this.failureTie1 = void 0;
247
+ this.failureTie2 = void 0;
188
248
  this.hintOffset = -1;
189
249
  this.hintExpected = empty;
190
- this.deepest = void 0;
250
+ this.deepestFailure = void 0;
251
+ this.deepestIsLatest = false;
191
252
  this.recovered = void 0;
192
253
  this.tracer = void 0;
193
254
  this.depth = 0;
@@ -261,8 +322,30 @@ var State = class {
261
322
  */
262
323
  failWith(mode, failure) {
263
324
  this.mode = mode;
264
- this.failure = failure;
265
- if (mode === "Backtrack" && (this.deepest === void 0 || failure.offset >= this.deepest.offset)) this.deepest = failure;
325
+ if (this.deepestIsLatest) {
326
+ if (mode === "Backtrack" && failure.offset >= this.failureHead.offset) this.deepestIsLatest = false;
327
+ else this.settleFailure();
328
+ }
329
+ this.failureHead = failure;
330
+ this.failureTie1 = void 0;
331
+ this.failureTie2 = void 0;
332
+ if (mode === "Backtrack" && (this.deepestFailure === void 0 || failure.offset >= this.deepestFailure.offset)) this.deepestFailure = failure;
333
+ return Fail;
334
+ }
335
+ /**
336
+ * Records a recoverable failure made of tied failures, merged only when
337
+ * read: `failWith("Backtrack", f)` where `f` merges `head` with `tie1`
338
+ * and then `tie2` (all at the same offset), as `mergeFailures` would.
339
+ *
340
+ * @internal
341
+ */
342
+ failTies(head, tie1, tie2) {
343
+ this.mode = "Backtrack";
344
+ if (this.deepestIsLatest && head.offset < this.failureHead.offset) this.settleFailure();
345
+ this.failureHead = head;
346
+ this.failureTie1 = tie1;
347
+ this.failureTie2 = tie2;
348
+ this.deepestIsLatest = this.deepestFailure === void 0 || head.offset >= this.deepestFailure.offset;
266
349
  return Fail;
267
350
  }
268
351
  /**
@@ -320,11 +403,20 @@ const mergeExpected = (a, b) => {
320
403
  const mergeFailures = (a, b) => {
321
404
  if (a.offset > b.offset) return a;
322
405
  if (b.offset > a.offset) return b;
323
- const expected = mergeExpected(a.expected, b.expected);
406
+ return mergeTiedFailures(a, b, mergeExpected(a.expected, b.expected));
407
+ };
408
+ /**
409
+ * {@link mergeFailures} for two failures at the same offset, given their
410
+ * merged expectations (`mergeExpected(a.expected, b.expected)`, possibly
411
+ * memoised by the caller).
412
+ *
413
+ * @internal
414
+ */
415
+ const mergeTiedFailures = (a, b, expected) => {
324
416
  if (expected === b.expected) return b;
325
417
  return new Failure(b.offset, b.kind, expected, b.context.length > 0 ? b.context : a.context, b.hasCause || a.hasCause, b.hasCause ? b.cause : a.cause, b.message ?? a.message, b.needed);
326
418
  };
327
419
  //#endregion
328
- export { Fail, Failure, State, emptyStrings, fromSource, mergeExpected, mergeFailures };
420
+ export { Fail, Failure, State, emptyStrings, fromSource, mergeExpected, mergeFailures, mergeTiedFailures };
329
421
 
330
422
  //# sourceMappingURL=Input.js.map
package/dist/Input.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","names":[],"sources":["../src/Input.ts"],"sourcesContent":["/**\n * Input types and the mutable parse {@link State} cursor.\n *\n * Like winnow, effect-parse parsers advance a mutable cursor rather than\n * returning the remaining input. A {@link State} wraps the original input\n * together with the current offset, the streaming (partial) flag, the\n * services available to the parser, and the details of the most recent\n * failure.\n *\n * Most users never touch `State` directly. It is exposed for writing custom\n * low-level parsers with `Parser.make`, and for drivers that run a parser's\n * `step` many times over one input, reusing a state with {@link State.reset}.\n *\n * @since 0.1.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport * as Context from \"effect/Context\"\nimport type { Encoding } from \"./Encoding.js\"\nimport type { ErrorKind } from \"./ParseError.js\"\nimport type { Builder as SyntaxBuilder } from \"./internal/syntax.js\"\n\n/**\n * The kinds of input a parser can consume.\n *\n * - `string`: tokens are Unicode code points (returned as strings), offsets\n * are UTF-16 code-unit indices.\n * - `Uint8Array`: tokens are bytes (numbers), slices are `subarray` views.\n * - `ReadonlyArray<T>`: tokens are elements, e.g. the output of a lexer.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Input = string | Uint8Array | ReadonlyArray<unknown>\n\n/**\n * Binary data that can be passed wherever a `Uint8Array` input is expected:\n * an `ArrayBuffer`, a `SharedArrayBuffer`, a `DataView` or any typed array.\n *\n * It is viewed, not copied, as a `Uint8Array` of its bytes. A typed array\n * with wider elements is viewed in the platform's byte order, which is\n * little endian on all common platforms, so a `Uint16Array` of UTF-16 code\n * units can be parsed with `Text.utf16le`.\n *\n * @since 0.1.0\n * @category models\n */\nexport type BinaryInput = ArrayBufferLike | ArrayBufferView\n\n/**\n * What the runners accept for a parser over `I`: the input itself, or, for\n * byte parsers, any {@link BinaryInput}.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never)\n\n/**\n * Converts a {@link Source} to the input parsers read: binary data becomes a\n * `Uint8Array` view of the same memory, everything else is returned as is.\n *\n * @example\n * ```ts\n * import { Input } from \"@thomasfosterau/effect-parse\"\n *\n * Input.fromSource(new Uint16Array([0x41]).buffer) // Uint8Array [0x41, 0x00]\n * ```\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const fromSource: {\n (source: BinaryInput): Uint8Array\n <I extends Input>(source: Source<I>): I\n} = (source: Input | BinaryInput): any => {\n if (Predicate.isString(source) || source instanceof Uint8Array || Array.isArray(source)) return source\n if (ArrayBuffer.isView(source)) return new Uint8Array(source.buffer, source.byteOffset, source.byteLength)\n // An explicit length fixes the view's size even for a resizable buffer\n if (isArrayBufferLike(source)) return new Uint8Array(source, 0, source.byteLength)\n return source\n}\n\nconst isArrayBufferLike = (u: unknown): u is ArrayBufferLike =>\n u instanceof ArrayBuffer || (globalThis.SharedArrayBuffer !== undefined && u instanceof SharedArrayBuffer)\n\n/**\n * The type of a single token of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Token<I> = I extends string\n ? string\n : I extends Uint8Array\n ? number\n : I extends ReadonlyArray<infer T>\n ? T\n : never\n\n/**\n * The type of a contiguous slice of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Slice<I> = I extends string\n ? string\n : I extends Uint8Array\n ? Uint8Array\n : I extends ReadonlyArray<infer T>\n ? ReadonlyArray<T>\n : never\n\n/**\n * Sentinel returned by a parser step to signal failure. The failure details\n * are stored on the {@link State}.\n *\n * @since 0.1.0\n * @category failure\n */\nexport const Fail: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Fail\")\n\n/**\n * @since 0.1.0\n * @category failure\n */\nexport type Fail = typeof Fail\n\n/**\n * How a failure propagates (winnow's `ErrMode`, nom's `Err`).\n *\n * - `Backtrack`: recoverable; `alt`, `opt`, `repeat`, ... try something else.\n * - `Cut`: unrecoverable; alternatives are not attempted.\n * - `Incomplete`: a partial (streaming) input ran out; more data is needed.\n *\n * @since 0.1.0\n * @category failure\n */\nexport type ErrMode = \"Backtrack\" | \"Cut\" | \"Incomplete\"\n\n/**\n * The details of a parse failure.\n *\n * @since 0.1.0\n * @category failure\n */\nexport class Failure {\n constructor(\n /** Offset into the input where the failure occurred. */\n readonly offset: number,\n /** The kind of parser that failed. */\n readonly kind: ErrorKind,\n /** Rendered descriptions of what was expected at `offset`. */\n readonly expected: ReadonlyArray<string>,\n /** Context labels added by `Parser.context`, innermost first. */\n readonly context: ReadonlyArray<string>,\n /** Whether a user supplied cause is present. */\n readonly hasCause: boolean,\n /** A user supplied (typed) cause. */\n readonly cause: unknown,\n /** An optional free-form message. */\n readonly message: string | undefined,\n /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */\n readonly needed: number\n ) {}\n}\n\nconst empty: ReadonlyArray<string> = []\n\n/** The failure a {@link State} starts with, before any step has failed. */\nconst initialFailure = /*#__PURE__*/ new Failure(0, \"Fail\", empty, empty, false, undefined, undefined, 0)\n\n/** @internal */\nexport const emptyStrings = empty\n\n/**\n * A tracing event emitted by `Parser.trace`.\n *\n * @since 0.1.0\n * @category tracing\n */\nexport interface TraceEvent {\n readonly _tag: \"Enter\" | \"Exit\"\n readonly name: string\n readonly depth: number\n readonly offset: number\n /** For `Exit` events: the outcome. */\n readonly result?: \"Ok\" | ErrMode\n /** For `Exit` events: the offset reached. */\n readonly endOffset?: number\n readonly state: State\n}\n\n/**\n * The mutable parsing cursor.\n *\n * @since 0.1.0\n * @category models\n */\nexport class State<I extends Input = Input> {\n /** The full input being parsed. */\n readonly input: I\n /** The current offset. Advanced by parsers, rewound on backtracking. */\n // Declared, not defined, so that a subclass can make it an accessor\n declare pos: number\n /** The end offset (the input's length; in bits inside `Bits.bits`). */\n end: number\n /** 0 = string, 1 = Uint8Array, 2 = array. */\n readonly inputKind: 0 | 1 | 2\n /** Whether the input is partial (streaming): running out yields `Incomplete`. */\n partial: boolean\n /** Services available to `Parser.service`. */\n context: Context.Context<never>\n /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */\n mode: ErrMode = \"Backtrack\"\n /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */\n failure: Failure\n /**\n * The offset of a recoverable failure that occurred without consuming\n * input (for example the last attempt of a `repeat`). Its\n * expectations are merged into new failures at the same offset, producing\n * messages like `expected digit or \")\"`.\n */\n hintOffset = -1\n /** The expectations of the hint at {@link hintOffset}. */\n hintExpected: ReadonlyArray<string> = empty\n /**\n * The furthest recoverable failure seen so far, including failures that\n * were later swallowed by backtracking (for example a trailing separator\n * followed by an invalid element). It is reported instead of the final\n * failure when it lies further into the input. This is the classic PEG\n * \"farthest failure\" heuristic. `Parser.cut` keeps only the failures\n * recorded inside it when it commits, and `Parser.peek` and `Parser.not`\n * forget the failures of a lookahead that succeeded.\n */\n deepest: Failure | undefined = undefined\n /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */\n recovered: Array<Failure> | undefined = undefined\n /** When defined, `Parser.trace` reports events here. */\n tracer: ((event: TraceEvent) => void) | undefined = undefined\n /** Current tracing depth. */\n depth = 0\n /**\n * The text encoding of a byte input, recorded by `Text` parsers when they\n * fail so that errors can show the input as text.\n */\n encoding: Encoding<any> | undefined = undefined\n /**\n * The checkpoints of a resumable streaming parse (see\n * `ParserStream.parseAll`); `undefined` otherwise.\n *\n * @internal\n */\n resume: Map<object, Map<number, unknown>> | undefined = undefined\n /**\n * The tree builder of a `Syntax` parse; `undefined` otherwise.\n *\n * @internal\n */\n syntax: SyntaxBuilder | undefined = undefined\n\n constructor(\n source: I | Source<I>,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n readonly offset?: number | undefined\n }\n ) {\n const input = fromSource(source as Input) as I\n this.input = input\n this.end = input.length\n this.pos = options?.offset ?? 0\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.inputKind = Predicate.isString(input) ? 0 : input instanceof Uint8Array ? 1 : 2\n this.failure = initialFailure\n }\n\n /**\n * Prepares the state for another run over the same input, starting at\n * `offset`: afterwards it behaves exactly like\n * `new State(state.input, { ...options, offset })`, without allocating a\n * new state.\n *\n * Every per-run field is reset: the cursor and end, the latest failure,\n * hints and furthest failure, recorded recoveries, the tracer and tracing\n * depth, the recorded encoding and streaming checkpoints. Like the\n * constructor, `partial` defaults to `false` and `context` to the empty\n * context, so pass them again on every reset.\n *\n * Use it to run many small parses over one buffer, for example one per\n * token, with `parser.step`. A state can be reused after any run,\n * including one that failed, returned `Incomplete` or threw.\n *\n * @example\n * ```ts\n * import { Ascii, Input } from \"@thomasfosterau/effect-parse\"\n *\n * const state = new Input.State(\"12 34\")\n * Ascii.decUint.step(state) // 12\n * state.reset(3)\n * Ascii.decUint.step(state) // 34\n * ```\n *\n * @since 0.2.0\n */\n reset(\n offset: number = 0,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n }\n ): this {\n this.pos = offset\n this.end = this.input.length\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.mode = \"Backtrack\"\n this.failure = initialFailure\n this.hintOffset = -1\n this.hintExpected = empty\n this.deepest = undefined\n this.recovered = undefined\n this.tracer = undefined\n this.depth = 0\n this.encoding = undefined\n this.resume = undefined\n return this\n }\n\n /**\n * The number of input units (code units, bytes or elements) remaining.\n */\n remaining(): number {\n return this.end - this.pos\n }\n\n /**\n * Whether the cursor is at the end of the input.\n */\n atEnd(): boolean {\n return this.pos >= this.end\n }\n\n /**\n * Extracts the slice `[start, end)` of the input.\n */\n slice(start: number, end: number): Slice<I> {\n const input = this.input as any\n switch (this.inputKind) {\n case 0:\n return input.slice(start, end)\n case 1:\n return input.subarray(start, end)\n default:\n return input.slice(start, end)\n }\n }\n\n /**\n * Records a recoverable failure at the current offset and returns {@link Fail}.\n */\n backtrack(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Backtrack\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an unrecoverable failure at the current offset and returns {@link Fail}.\n */\n cut(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Cut\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an `Incomplete` failure (only meaningful for partial input) and\n * returns {@link Fail}.\n */\n incomplete(needed: number, expected: ReadonlyArray<string> = empty): Fail {\n return this.failWith(\n \"Incomplete\",\n new Failure(this.pos, \"Incomplete\", expected, empty, false, undefined, undefined, needed)\n )\n }\n\n /**\n * Fails because the input ended: `Incomplete` for partial input, otherwise\n * a `Backtrack` failure of the given kind.\n */\n eoi(kind: ErrorKind, expected: ReadonlyArray<string>, needed: number): Fail {\n return this.partial ? this.incomplete(needed, expected) : this.backtrack(kind, expected)\n }\n\n /**\n * Records a failure carrying a user supplied cause.\n */\n failCause(mode: ErrMode, kind: ErrorKind, cause: unknown, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, true, cause, undefined, 0))\n }\n\n /**\n * Records a failure carrying a message.\n */\n failMessage(mode: ErrMode, kind: ErrorKind, message: string, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, false, undefined, message, 0))\n }\n\n /**\n * Records the given failure and returns {@link Fail}.\n */\n failWith(mode: ErrMode, failure: Failure): Fail {\n this.mode = mode\n this.failure = failure\n if (mode === \"Backtrack\" && (this.deepest === undefined || failure.offset >= this.deepest.offset)) {\n this.deepest = failure\n }\n return Fail\n }\n\n /**\n * Replaces the details of the current failure (for example to add context),\n * keeping the record of the furthest failure consistent.\n */\n replaceFailure(failure: Failure): void {\n if (this.deepest === this.failure) this.deepest = failure\n this.failure = failure\n }\n\n /**\n * The failure to report to the user: the current failure, or the furthest\n * failure if it lies beyond the current one and the current failure is a\n * plain syntax error (no user cause or message).\n */\n reportedFailure(): Failure {\n const f = this.failure\n const d = this.deepest\n if (\n d === undefined ||\n d === f ||\n d.offset <= f.offset ||\n this.mode === \"Incomplete\" ||\n f.hasCause ||\n f.message !== undefined\n ) {\n return f\n }\n const context =\n d.context.length === 0 ? f.context : [...d.context, ...f.context.filter((l) => !d.context.includes(l))]\n return new Failure(d.offset, d.kind, d.expected, context, d.hasCause, d.cause, d.message, d.needed)\n }\n\n /**\n * Records that, at `offset`, any of `expected` could also have been\n * accepted. Used by parsers that stop without failing, such as `opt`,\n * `repeat` and `Ascii.digit1`.\n */\n setHint(offset: number, expected: ReadonlyArray<string>): void {\n if (this.hintOffset === offset) {\n this.hintExpected = mergeExpected(this.hintExpected, expected)\n } else {\n this.hintOffset = offset\n this.hintExpected = expected\n }\n }\n\n /** @internal */\n makeFailure(offset: number, kind: ErrorKind, expected: ReadonlyArray<string>): Failure {\n if (this.hintOffset === offset && this.hintExpected.length > 0) {\n expected = mergeExpected(this.hintExpected, expected)\n }\n return new Failure(offset, kind, expected, empty, false, undefined, undefined, 0)\n }\n}\n\n/** @internal */\nexport const mergeExpected = (a: ReadonlyArray<string>, b: ReadonlyArray<string>): ReadonlyArray<string> => {\n if (a.length === 0) return b\n if (b.length === 0) return a\n const out = a.slice()\n for (const e of b) {\n if (!out.includes(e)) out.push(e)\n }\n return out\n}\n\n/**\n * Combines the failures of two alternatives: the furthest failure wins, and\n * failures at the same offset have their expectations merged.\n *\n * @internal\n */\nexport const mergeFailures = (a: Failure, b: Failure): Failure => {\n if (a.offset > b.offset) return a\n if (b.offset > a.offset) return b\n const expected = mergeExpected(a.expected, b.expected)\n if (expected === b.expected) return b\n return new Failure(\n b.offset,\n b.kind,\n expected,\n b.context.length > 0 ? b.context : a.context,\n b.hasCause || a.hasCause,\n b.hasCause ? b.cause : a.cause,\n b.message ?? a.message,\n b.needed\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAa,cAGR,WAAqC;CACxC,IAAI,UAAU,SAAS,MAAM,KAAK,kBAAkB,cAAc,MAAM,QAAQ,MAAM,GAAG,OAAO;CAChG,IAAI,YAAY,OAAO,MAAM,GAAG,OAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;CAEzG,IAAI,kBAAkB,MAAM,GAAG,OAAO,IAAI,WAAW,QAAQ,GAAG,OAAO,UAAU;CACjF,OAAO;AACT;AAEA,MAAM,qBAAqB,MACzB,aAAa,eAAgB,WAAW,sBAAsB,KAAA,KAAa,aAAa;;;;;;;;AAqC1F,MAAa,OAAoC,qBAAO,IAAI,mBAAmB;;;;;;;AA0B/E,IAAa,UAAb,MAAqB;CAGR;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAhBX,YAEE,QAEA,MAEA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IAAI,EAAE,WAAW,GAAG,OAAO;CAC3B,IAAI,EAAE,WAAW,GAAG,OAAO;CAC3B,MAAM,MAAM,EAAE,MAAM;CACpB,KAAK,MAAM,KAAK,GACd,IAAI,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,KAAK,CAAC;CAElC,OAAO;AACT;;;;;;;AAQA,MAAa,iBAAiB,GAAY,MAAwB;CAChE,IAAI,EAAE,SAAS,EAAE,QAAQ,OAAO;CAChC,IAAI,EAAE,SAAS,EAAE,QAAQ,OAAO;CAChC,MAAM,WAAW,cAAc,EAAE,UAAU,EAAE,QAAQ;CACrD,IAAI,aAAa,EAAE,UAAU,OAAO;CACpC,OAAO,IAAI,QACT,EAAE,QACF,EAAE,MACF,UACA,EAAE,QAAQ,SAAS,IAAI,EAAE,UAAU,EAAE,SACrC,EAAE,YAAY,EAAE,UAChB,EAAE,WAAW,EAAE,QAAQ,EAAE,OACzB,EAAE,WAAW,EAAE,SACf,EAAE,MACJ;AACF"}
1
+ {"version":3,"file":"Input.js","names":[],"sources":["../src/Input.ts"],"sourcesContent":["/**\n * Input types and the mutable parse {@link State} cursor.\n *\n * Like winnow, effect-parse parsers advance a mutable cursor rather than\n * returning the remaining input. A {@link State} wraps the original input\n * together with the current offset, the streaming (partial) flag, the\n * services available to the parser, and the details of the most recent\n * failure.\n *\n * Most users never touch `State` directly. It is exposed for writing custom\n * low-level parsers with `Parser.make`, and for drivers that run a parser's\n * `step` many times over one input, reusing a state with {@link State.reset}.\n *\n * @since 0.1.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport * as Context from \"effect/Context\"\nimport type { Encoding } from \"./Encoding.js\"\nimport type { ErrorKind } from \"./ParseError.js\"\nimport type { Builder as SyntaxBuilder } from \"./internal/syntax.js\"\n\n/**\n * The kinds of input a parser can consume.\n *\n * - `string`: tokens are Unicode code points (returned as strings), offsets\n * are UTF-16 code-unit indices.\n * - `Uint8Array`: tokens are bytes (numbers), slices are `subarray` views.\n * - `ReadonlyArray<T>`: tokens are elements, e.g. the output of a lexer.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Input = string | Uint8Array | ReadonlyArray<unknown>\n\n/**\n * Binary data that can be passed wherever a `Uint8Array` input is expected:\n * an `ArrayBuffer`, a `SharedArrayBuffer`, a `DataView` or any typed array.\n *\n * It is viewed, not copied, as a `Uint8Array` of its bytes. A typed array\n * with wider elements is viewed in the platform's byte order, which is\n * little endian on all common platforms, so a `Uint16Array` of UTF-16 code\n * units can be parsed with `Text.utf16le`.\n *\n * @since 0.1.0\n * @category models\n */\nexport type BinaryInput = ArrayBufferLike | ArrayBufferView\n\n/**\n * What the runners accept for a parser over `I`: the input itself, or, for\n * byte parsers, any {@link BinaryInput}.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never)\n\n/**\n * Converts a {@link Source} to the input parsers read: binary data becomes a\n * `Uint8Array` view of the same memory, everything else is returned as is.\n *\n * @example\n * ```ts\n * import { Input } from \"@thomasfosterau/effect-parse\"\n *\n * Input.fromSource(new Uint16Array([0x41]).buffer) // Uint8Array [0x41, 0x00]\n * ```\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const fromSource: {\n (source: BinaryInput): Uint8Array\n <I extends Input>(source: Source<I>): I\n} = (source: Input | BinaryInput): any => {\n if (Predicate.isString(source) || source instanceof Uint8Array || Array.isArray(source)) return source\n if (ArrayBuffer.isView(source)) return new Uint8Array(source.buffer, source.byteOffset, source.byteLength)\n // An explicit length fixes the view's size even for a resizable buffer\n if (isArrayBufferLike(source)) return new Uint8Array(source, 0, source.byteLength)\n return source\n}\n\nconst isArrayBufferLike = (u: unknown): u is ArrayBufferLike =>\n u instanceof ArrayBuffer || (globalThis.SharedArrayBuffer !== undefined && u instanceof SharedArrayBuffer)\n\n/**\n * The type of a single token of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Token<I> = I extends string\n ? string\n : I extends Uint8Array\n ? number\n : I extends ReadonlyArray<infer T>\n ? T\n : never\n\n/**\n * The type of a contiguous slice of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Slice<I> = I extends string\n ? string\n : I extends Uint8Array\n ? Uint8Array\n : I extends ReadonlyArray<infer T>\n ? ReadonlyArray<T>\n : never\n\n/**\n * Sentinel returned by a parser step to signal failure. The failure details\n * are stored on the {@link State}.\n *\n * @since 0.1.0\n * @category failure\n */\nexport const Fail: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Fail\")\n\n/**\n * @since 0.1.0\n * @category failure\n */\nexport type Fail = typeof Fail\n\n/**\n * How a failure propagates (winnow's `ErrMode`, nom's `Err`).\n *\n * - `Backtrack`: recoverable; `alt`, `opt`, `repeat`, ... try something else.\n * - `Cut`: unrecoverable; alternatives are not attempted.\n * - `Incomplete`: a partial (streaming) input ran out; more data is needed.\n *\n * @since 0.1.0\n * @category failure\n */\nexport type ErrMode = \"Backtrack\" | \"Cut\" | \"Incomplete\"\n\n/**\n * The details of a parse failure.\n *\n * @since 0.1.0\n * @category failure\n */\nexport class Failure {\n constructor(\n /** Offset into the input where the failure occurred. */\n readonly offset: number,\n /** The kind of parser that failed. */\n readonly kind: ErrorKind,\n /** Rendered descriptions of what was expected at `offset`. */\n readonly expected: ReadonlyArray<string>,\n /** Context labels added by `Parser.context`, innermost first. */\n readonly context: ReadonlyArray<string>,\n /** Whether a user supplied cause is present. */\n readonly hasCause: boolean,\n /** A user supplied (typed) cause. */\n readonly cause: unknown,\n /** An optional free-form message. */\n readonly message: string | undefined,\n /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */\n readonly needed: number\n ) {}\n}\n\nconst empty: ReadonlyArray<string> = []\n\n/** The failure a {@link State} starts with, before any step has failed. */\nconst initialFailure = /*#__PURE__*/ new Failure(0, \"Fail\", empty, empty, false, undefined, undefined, 0)\n\n/** @internal */\nexport const emptyStrings = empty\n\n/**\n * A tracing event emitted by `Parser.trace`.\n *\n * @since 0.1.0\n * @category tracing\n */\nexport interface TraceEvent {\n readonly _tag: \"Enter\" | \"Exit\"\n readonly name: string\n readonly depth: number\n readonly offset: number\n /** For `Exit` events: the outcome. */\n readonly result?: \"Ok\" | ErrMode\n /** For `Exit` events: the offset reached. */\n readonly endOffset?: number\n readonly state: State\n}\n\n/**\n * The mutable parsing cursor.\n *\n * @since 0.1.0\n * @category models\n */\nexport class State<I extends Input = Input> {\n /** The full input being parsed. */\n readonly input: I\n /** The current offset. Advanced by parsers, rewound on backtracking. */\n // Declared, not defined, so that a subclass can make it an accessor\n declare pos: number\n /** The end offset (the input's length; in bits inside `Bits.bits`). */\n end: number\n /** 0 = string, 1 = Uint8Array, 2 = array. */\n readonly inputKind: 0 | 1 | 2\n /** Whether the input is partial (streaming): running out yields `Incomplete`. */\n partial: boolean\n /** Services available to `Parser.service`. */\n context: Context.Context<never>\n /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */\n mode: ErrMode = \"Backtrack\"\n /**\n * The latest failure, kept unmerged: the failure is `failureHead` merged\n * (as `mergeFailures` does) with `failureTie1` and then `failureTie2`, all\n * at the same offset. `Parser.alt` records its tied branch failures here\n * with {@link failTies} instead of merging them, so that an enclosing `alt`\n * whose next branch succeeds never pays for the merge. Reading\n * {@link failure} performs the merge, once.\n *\n * @internal\n */\n failureHead: Failure\n /** @internal */\n failureTie1: Failure | undefined = undefined\n /** @internal */\n failureTie2: Failure | undefined = undefined\n /** Backs {@link deepest}. @internal */\n deepestFailure: Failure | undefined = undefined\n /**\n * Whether the furthest failure is the latest failure, still unmerged, so\n * that {@link deepest} is that failure once merged. Only set while\n * `failureTie1` is.\n *\n * @internal\n */\n deepestIsLatest = false\n /**\n * The offset of a recoverable failure that occurred without consuming\n * input (for example the last attempt of a `repeat`). Its\n * expectations are merged into new failures at the same offset, producing\n * messages like `expected digit or \")\"`.\n */\n hintOffset = -1\n /** The expectations of the hint at {@link hintOffset}. */\n hintExpected: ReadonlyArray<string> = empty\n /**\n * The furthest recoverable failure seen so far, including failures that\n * were later swallowed by backtracking (for example a trailing separator\n * followed by an invalid element). It is reported instead of the final\n * failure when it lies further into the input. This is the classic PEG\n * \"farthest failure\" heuristic. `Parser.cut` keeps only the failures\n * recorded inside it when it commits, and `Parser.peek` and `Parser.not`\n * forget the failures of a lookahead that succeeded.\n */\n get deepest(): Failure | undefined {\n if (this.deepestIsLatest) this.settleFailure()\n return this.deepestFailure\n }\n set deepest(failure: Failure | undefined) {\n this.deepestIsLatest = false\n this.deepestFailure = failure\n }\n /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */\n recovered: Array<Failure> | undefined = undefined\n /** When defined, `Parser.trace` reports events here. */\n tracer: ((event: TraceEvent) => void) | undefined = undefined\n /** Current tracing depth. */\n depth = 0\n /**\n * The text encoding of a byte input, recorded by `Text` parsers when they\n * fail so that errors can show the input as text.\n */\n encoding: Encoding<any> | undefined = undefined\n /**\n * The checkpoints of a resumable streaming parse (see\n * `ParserStream.parseAll`); `undefined` otherwise.\n *\n * @internal\n */\n resume: Map<object, Map<number, unknown>> | undefined = undefined\n /**\n * The tree builder of a `Syntax` parse; `undefined` otherwise.\n *\n * @internal\n */\n syntax: SyntaxBuilder | undefined = undefined\n\n constructor(\n source: I | Source<I>,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n readonly offset?: number | undefined\n }\n ) {\n const input = fromSource(source as Input) as I\n this.input = input\n this.end = input.length\n this.pos = options?.offset ?? 0\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.inputKind = Predicate.isString(input) ? 0 : input instanceof Uint8Array ? 1 : 2\n this.failureHead = initialFailure\n }\n\n /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */\n get failure(): Failure {\n if (this.failureTie1 !== undefined) this.settleFailure()\n return this.failureHead\n }\n set failure(failure: Failure) {\n if (this.deepestIsLatest) this.settleFailure()\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n\n /** Merges the latest failure's ties into it (see {@link failureHead}). */\n private settleFailure(): void {\n let failure = this.failureHead\n const tie1 = this.failureTie1\n if (tie1 !== undefined) {\n failure = mergeTiedFailures(failure, tie1, mergeExpected(failure.expected, tie1.expected))\n const tie2 = this.failureTie2\n if (tie2 !== undefined) failure = mergeTiedFailures(failure, tie2, mergeExpected(failure.expected, tie2.expected))\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n if (this.deepestIsLatest) {\n this.deepestFailure = failure\n this.deepestIsLatest = false\n }\n }\n\n /**\n * Prepares the state for another run over the same input, starting at\n * `offset`: afterwards it behaves exactly like\n * `new State(state.input, { ...options, offset })`, without allocating a\n * new state.\n *\n * Every per-run field is reset: the cursor and end, the latest failure,\n * hints and furthest failure, recorded recoveries, the tracer and tracing\n * depth, the recorded encoding and streaming checkpoints. Like the\n * constructor, `partial` defaults to `false` and `context` to the empty\n * context, so pass them again on every reset.\n *\n * Use it to run many small parses over one buffer, for example one per\n * token, with `parser.step`. A state can be reused after any run,\n * including one that failed, returned `Incomplete` or threw.\n *\n * @example\n * ```ts\n * import { Ascii, Input } from \"@thomasfosterau/effect-parse\"\n *\n * const state = new Input.State(\"12 34\")\n * Ascii.decUint.step(state) // 12\n * state.reset(3)\n * Ascii.decUint.step(state) // 34\n * ```\n *\n * @since 0.2.0\n */\n reset(\n offset: number = 0,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n }\n ): this {\n this.pos = offset\n this.end = this.input.length\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.mode = \"Backtrack\"\n this.failureHead = initialFailure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n this.hintOffset = -1\n this.hintExpected = empty\n this.deepestFailure = undefined\n this.deepestIsLatest = false\n this.recovered = undefined\n this.tracer = undefined\n this.depth = 0\n this.encoding = undefined\n this.resume = undefined\n return this\n }\n\n /**\n * The number of input units (code units, bytes or elements) remaining.\n */\n remaining(): number {\n return this.end - this.pos\n }\n\n /**\n * Whether the cursor is at the end of the input.\n */\n atEnd(): boolean {\n return this.pos >= this.end\n }\n\n /**\n * Extracts the slice `[start, end)` of the input.\n */\n slice(start: number, end: number): Slice<I> {\n const input = this.input as any\n switch (this.inputKind) {\n case 0:\n return input.slice(start, end)\n case 1:\n return input.subarray(start, end)\n default:\n return input.slice(start, end)\n }\n }\n\n /**\n * Records a recoverable failure at the current offset and returns {@link Fail}.\n */\n backtrack(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Backtrack\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an unrecoverable failure at the current offset and returns {@link Fail}.\n */\n cut(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Cut\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an `Incomplete` failure (only meaningful for partial input) and\n * returns {@link Fail}.\n */\n incomplete(needed: number, expected: ReadonlyArray<string> = empty): Fail {\n return this.failWith(\n \"Incomplete\",\n new Failure(this.pos, \"Incomplete\", expected, empty, false, undefined, undefined, needed)\n )\n }\n\n /**\n * Fails because the input ended: `Incomplete` for partial input, otherwise\n * a `Backtrack` failure of the given kind.\n */\n eoi(kind: ErrorKind, expected: ReadonlyArray<string>, needed: number): Fail {\n return this.partial ? this.incomplete(needed, expected) : this.backtrack(kind, expected)\n }\n\n /**\n * Records a failure carrying a user supplied cause.\n */\n failCause(mode: ErrMode, kind: ErrorKind, cause: unknown, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, true, cause, undefined, 0))\n }\n\n /**\n * Records a failure carrying a message.\n */\n failMessage(mode: ErrMode, kind: ErrorKind, message: string, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, false, undefined, message, 0))\n }\n\n /**\n * Records the given failure and returns {@link Fail}.\n */\n failWith(mode: ErrMode, failure: Failure): Fail {\n this.mode = mode\n if (this.deepestIsLatest) {\n // The furthest failure is the latest one: it is replaced below, unmerged, if `failure` is as far\n if (mode === \"Backtrack\" && failure.offset >= this.failureHead.offset) this.deepestIsLatest = false\n else this.settleFailure()\n }\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n if (mode === \"Backtrack\" && (this.deepestFailure === undefined || failure.offset >= this.deepestFailure.offset)) {\n this.deepestFailure = failure\n }\n return Fail\n }\n\n /**\n * Records a recoverable failure made of tied failures, merged only when\n * read: `failWith(\"Backtrack\", f)` where `f` merges `head` with `tie1`\n * and then `tie2` (all at the same offset), as `mergeFailures` would.\n *\n * @internal\n */\n failTies(head: Failure, tie1: Failure, tie2: Failure | undefined): Fail {\n this.mode = \"Backtrack\"\n if (this.deepestIsLatest && head.offset < this.failureHead.offset) this.settleFailure()\n this.failureHead = head\n this.failureTie1 = tie1\n this.failureTie2 = tie2\n this.deepestIsLatest = this.deepestFailure === undefined || head.offset >= this.deepestFailure.offset\n return Fail\n }\n\n /**\n * Replaces the details of the current failure (for example to add context),\n * keeping the record of the furthest failure consistent.\n */\n replaceFailure(failure: Failure): void {\n if (this.deepest === this.failure) this.deepest = failure\n this.failure = failure\n }\n\n /**\n * The failure to report to the user: the current failure, or the furthest\n * failure if it lies beyond the current one and the current failure is a\n * plain syntax error (no user cause or message).\n */\n reportedFailure(): Failure {\n const f = this.failure\n const d = this.deepest\n if (\n d === undefined ||\n d === f ||\n d.offset <= f.offset ||\n this.mode === \"Incomplete\" ||\n f.hasCause ||\n f.message !== undefined\n ) {\n return f\n }\n const context =\n d.context.length === 0 ? f.context : [...d.context, ...f.context.filter((l) => !d.context.includes(l))]\n return new Failure(d.offset, d.kind, d.expected, context, d.hasCause, d.cause, d.message, d.needed)\n }\n\n /**\n * Records that, at `offset`, any of `expected` could also have been\n * accepted. Used by parsers that stop without failing, such as `opt`,\n * `repeat` and `Ascii.digit1`.\n */\n setHint(offset: number, expected: ReadonlyArray<string>): void {\n if (this.hintOffset === offset) {\n this.hintExpected = mergeExpected(this.hintExpected, expected)\n } else {\n this.hintOffset = offset\n this.hintExpected = expected\n }\n }\n\n /** @internal */\n makeFailure(offset: number, kind: ErrorKind, expected: ReadonlyArray<string>): Failure {\n if (this.hintOffset === offset && this.hintExpected.length > 0) {\n expected = mergeExpected(this.hintExpected, expected)\n }\n return new Failure(offset, kind, expected, empty, false, undefined, undefined, 0)\n }\n}\n\n/** @internal */\nexport const mergeExpected = (a: ReadonlyArray<string>, b: ReadonlyArray<string>): ReadonlyArray<string> => {\n if (a.length === 0) return b\n if (b.length === 0) return a\n const out = a.slice()\n for (const e of b) {\n if (!out.includes(e)) out.push(e)\n }\n return out\n}\n\n/**\n * Combines the failures of two alternatives: the furthest failure wins, and\n * failures at the same offset have their expectations merged.\n *\n * @internal\n */\nexport const mergeFailures = (a: Failure, b: Failure): Failure => {\n if (a.offset > b.offset) return a\n if (b.offset > a.offset) return b\n return mergeTiedFailures(a, b, mergeExpected(a.expected, b.expected))\n}\n\n/**\n * {@link mergeFailures} for two failures at the same offset, given their\n * merged expectations (`mergeExpected(a.expected, b.expected)`, possibly\n * memoised by the caller).\n *\n * @internal\n */\nexport const mergeTiedFailures = (a: Failure, b: Failure, expected: ReadonlyArray<string>): Failure => {\n if (expected === b.expected) return b\n return new Failure(\n b.offset,\n b.kind,\n expected,\n b.context.length > 0 ? b.context : a.context,\n b.hasCause || a.hasCause,\n b.hasCause ? b.cause : a.cause,\n b.message ?? a.message,\n b.needed\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAa,cAGR,WAAqC;CACxC,IAAI,UAAU,SAAS,MAAM,KAAK,kBAAkB,cAAc,MAAM,QAAQ,MAAM,GAAG,OAAO;CAChG,IAAI,YAAY,OAAO,MAAM,GAAG,OAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;CAEzG,IAAI,kBAAkB,MAAM,GAAG,OAAO,IAAI,WAAW,QAAQ,GAAG,OAAO,UAAU;CACjF,OAAO;AACT;AAE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;CAOA,QAAQ,QAAgB,UAAuC;EAC7D,IAAI,KAAK,eAAe,QACtB,KAAK,eAAe,cAAc,KAAK,cAAc,QAAQ;OACxD;GACL,KAAK,aAAa;GAClB,KAAK,eAAe;EACtB;CACF;;CAGA,YAAY,QAAgB,MAAiB,UAA0C;EACrF,IAAI,KAAK,eAAe,UAAU,KAAK,aAAa,SAAS,GAC3D,WAAW,cAAc,KAAK,cAAc,QAAQ;EAEtD,OAAO,IAAI,QAAQ,QAAQ,MAAM,UAAU,OAAO,OAAO,KAAA,GAAW,KAAA,GAAW,CAAC;CAClF;AACF;;AAGA,MAAa,iBAAiB,GAA0B,MAAoD;CAC1G,IAAI,EAAE,WAAW,GAAG,OAAO;CAC3B,IAAI,EAAE,WAAW,GAAG,OAAO;CAC3B,MAAM,MAAM,EAAE,MAAM;CACpB,KAAK,MAAM,KAAK,GACd,IAAI,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,KAAK,CAAC;CAElC,OAAO;AACT;;;;;;;AAQA,MAAa,iBAAiB,GAAY,MAAwB;CAChE,IAAI,EAAE,SAAS,EAAE,QAAQ,OAAO;CAChC,IAAI,EAAE,SAAS,EAAE,QAAQ,OAAO;CAChC,OAAO,kBAAkB,GAAG,GAAG,cAAc,EAAE,UAAU,EAAE,QAAQ,CAAC;AACtE;;;;;;;;AASA,MAAa,qBAAqB,GAAY,GAAY,aAA6C;CACrG,IAAI,aAAa,EAAE,UAAU,OAAO;CACpC,OAAO,IAAI,QACT,EAAE,QACF,EAAE,MACF,UACA,EAAE,QAAQ,SAAS,IAAI,EAAE,UAAU,EAAE,SACrC,EAAE,YAAY,EAAE,UAChB,EAAE,WAAW,EAAE,QAAQ,EAAE,OACzB,EAAE,WAAW,EAAE,SACf,EAAE,MACJ;AACF"}
package/dist/Nom.d.ts CHANGED
@@ -151,7 +151,7 @@ export declare const multispace0: Parser<string, never, never, string>;
151
151
  /** @since 0.1.0 @category character */
152
152
  export declare const multispace1: Parser<string, never, never, string>;
153
153
  /** @since 0.1.0 @category character */
154
- export declare const lineEnding: Parser<"\n" | "\r\n", never, never, string>;
154
+ export declare const lineEnding: Parser<"\r\n" | "\n", never, never, string>;
155
155
  /** @since 0.1.0 @category character */
156
156
  export declare const newline: Parser<"\n", never, never, string>;
157
157
  /** @since 0.1.0 @category character */
package/dist/Nom.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Nom.d.ts","names":["TokenOf"],"sources":["../src/Nom.ts"],"mappings":";;;;;;;;;;;;;qBA2Da;;;;;;;;;;;qBAQA;;;;;;;;;;qBAQA,aAAc,kBAAkB,GAAG,MAAI,OAAO;;;;;;;qBAQ9C,SAAS;;;;;qBAMT,QAAK,UAAA,gBAAA,KAAA,SAAA,OAAA,OAAAA,MAAA,QAAA,mBAAA,QAAA;;;;;qBAML,SAAM,UAAA,gBAAA,KAAA,SAAA,OAAA,OAAAA,MAAA,QAAA,mBAAA,QAAA;;;;;qBAMN,UAAO,UAAA,gBAAA,YAAA,OAAAA,MAAA,mBAAA,OAAAA,MAAA,QAAA,mBAAA,QAAA;;;;;;;qBAQP,MAAO,UAAU,gBAAgB,KAAK,SAAS,OAAK,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;qBASpG,QAAS,UAAU,gBAC9B,KAAK,SAAS,OACb,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;qBAMtC,OAAI,UAAA,gBAAA,kBAAA,OAAA,MAAA,QAAA,mBAAA,QAAA;;;;;qBAMJ,YAAa,UAAU,gBAClC,YAAY,OAAOA,MAAQ,mBAC1B,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;qBAMtC,aAAc,UAAU,gBACnC,YAAY,OAAOA,MAAQ,mBAC1B,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;qBAMtC,cAAe,UAAU,gBACpC,WACA,WACA,YAAY,OAAOA,MAAQ,mBAC1B,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;qBAMtC,WAAY,UA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AA,UAAA,OAAA,MAAA,OAAA,GAAA,GAAA,GAAA,OAAA,aAAA,GAAA,GAAA;;qBAEH,KAAG,2BAAA;;qBAEH,eAAY,GAAA,GAAA,GAAA,UAAA,OAAA,MAAA,OAAA,GAAA,GAAA,GAAA,OAAA,OAAA,GAAA,GAAA,GAAA;;qBAEZ,WAAQ,GAAA,GAAA,GAAA,UAAA,OAAA,MAAA,OAAA,GAAA,GAAA,GAAA,OAAA,OAAA,GAAA,GAAA,GAAA;;qBAER,MAAG,GAAA,GAAA,GAAA,UAAA,OAAA,MAAA,OAAA,GAAA,GAAA,GAAA,OAAA,OAAA,GAAA,GAAA,GAAA;;qBAEH,UAAO,GAAA,OAAA,MAAA,OAAA,iBAAA;;;;;;;qBAOP,MAAI,4BAAA;;qBAEJ,MAAI;;qBAEJ,SAAO,6BAAA;;;;;;;qBAQP,UAAW,GAAG,GAAG,GAAG,UAAU,OAAO,eAAe,QAAQ,OAAO,GAAG,GAAG,GAAG,OAAK,OAAO,GAAG,GAAG,GAAG"}
@@ -184,7 +184,6 @@ const inspectToken = (u) => {
184
184
  const causeMessage = (cause) => {
185
185
  if (cause === void 0) return void 0;
186
186
  if (Predicate.isString(cause)) return cause;
187
- if (cause instanceof Error) return cause.message;
188
187
  if (Predicate.isObjectOrArray(cause) && "message" in cause && Predicate.isString(cause.message)) return cause.message;
189
188
  return inspectToken(cause);
190
189
  };