@thomasfosterau/effect-parse 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +202 -0
- package/README.md +19 -1
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +5 -3
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts +5 -2
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +20 -3
- package/dist/Binary.js.map +1 -1
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +4 -0
- package/dist/Bits.js.map +1 -1
- package/dist/Input.d.ts +21 -3
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +31 -4
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts.map +1 -1
- package/dist/ParseError.d.ts +69 -11
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +129 -28
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +10 -4
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +10 -24
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +1 -2
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +119 -12
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +282 -55
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.js +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +13 -7
- package/dist/Text.js.map +1 -1
- package/dist/Token.d.ts +10 -1
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +14 -5
- package/dist/Token.js.map +1 -1
- package/dist/internal/compiler/closure.d.ts +1 -1
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +7 -17
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +2 -1
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/graph.d.ts +23 -1
- package/dist/internal/compiler/graph.d.ts.map +1 -1
- package/dist/internal/compiler/graph.js +27 -5
- package/dist/internal/compiler/graph.js.map +1 -1
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +26 -13
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +1 -1
- package/dist/internal/compiler/wasm.d.ts.map +1 -1
- package/dist/internal/compiler/wasm.js +105 -34
- package/dist/internal/compiler/wasm.js.map +1 -1
- package/dist/internal/node.d.ts +19 -1
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +42 -8
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/run.d.ts +3 -1
- package/dist/internal/run.d.ts.map +1 -1
- package/dist/internal/run.js +4 -2
- package/dist/internal/run.js.map +1 -1
- package/dist/internal/stack.d.ts +8 -0
- package/dist/internal/stack.d.ts.map +1 -1
- package/dist/internal/stack.js +17 -1
- package/dist/internal/stack.js.map +1 -1
- package/dist/internal/tokens.d.ts +10 -3
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +22 -9
- package/dist/internal/tokens.js.map +1 -1
- package/dist/internal/tuple.d.ts +6 -0
- package/dist/internal/tuple.d.ts.map +1 -0
- package/dist/internal/tuple.js +170 -0
- package/dist/internal/tuple.js.map +1 -0
- package/package.json +17 -10
- package/src/Ascii.ts +5 -3
- package/src/Binary.ts +24 -3
- package/src/Bits.ts +4 -0
- package/src/Input.ts +37 -4
- package/src/ParseError.ts +206 -52
- package/src/Parser.ts +19 -29
- package/src/ParserSchema.ts +1 -2
- package/src/ParserStream.ts +336 -62
- package/src/Text.ts +16 -12
- package/src/Token.ts +14 -5
- package/src/internal/compiler/closure.ts +9 -18
- package/src/internal/compiler/first.ts +6 -0
- package/src/internal/compiler/graph.ts +32 -4
- package/src/internal/compiler/jit.ts +37 -17
- package/src/internal/compiler/wasm.ts +141 -68
- package/src/internal/node.ts +49 -3
- package/src/internal/run.ts +4 -2
- package/src/internal/stack.ts +17 -0
- package/src/internal/tokens.ts +20 -10
- package/src/internal/tuple.ts +141 -0
package/dist/Binary.js
CHANGED
|
@@ -155,6 +155,15 @@ const i128 = /*#__PURE__*/ byEndian(beI128, leI128);
|
|
|
155
155
|
const f32 = /*#__PURE__*/ byEndian(beF32, leF32);
|
|
156
156
|
/** @since 0.1.0 @category floats */
|
|
157
157
|
const f64 = /*#__PURE__*/ byEndian(beF64, leF64);
|
|
158
|
+
const MaxCount = /*#__PURE__*/ BigInt(Number.MAX_SAFE_INTEGER);
|
|
159
|
+
/**
|
|
160
|
+
* Whether a length read from the input is a count: a non-negative integer
|
|
161
|
+
* of at most `Number.MAX_SAFE_INTEGER`. A signed, fractional or `NaN`
|
|
162
|
+
* length is the input's to choose, so it fails the parse where it was read
|
|
163
|
+
* (as `Parser.filter` does) and never reaches `Token.take` or
|
|
164
|
+
* `Parser.repeat`, which throw on one.
|
|
165
|
+
*/
|
|
166
|
+
const isCount = (n) => Predicate.isBigInt(n) ? n >= 0n && n <= MaxCount : Number.isSafeInteger(n) && n >= 0;
|
|
158
167
|
const toCount = (n) => Predicate.isBigInt(n) ? Number(n) : n;
|
|
159
168
|
/** How many counts {@link byCount} keeps the parsers of. */
|
|
160
169
|
const CountCache = 256;
|
|
@@ -177,7 +186,9 @@ const byCount = (build) => {
|
|
|
177
186
|
};
|
|
178
187
|
/**
|
|
179
188
|
* Parses a length with `count`, then takes that many tokens (winnow's
|
|
180
|
-
* `length_take`, nom's `length_data`).
|
|
189
|
+
* `length_take`, nom's `length_data`). A length that is not a non-negative
|
|
190
|
+
* integer (a negative `i8`, a fractional float) fails the parse at the
|
|
191
|
+
* length.
|
|
181
192
|
*
|
|
182
193
|
* @since 0.1.0
|
|
183
194
|
* @category length-prefixed
|
|
@@ -185,19 +196,25 @@ const byCount = (build) => {
|
|
|
185
196
|
const lengthTake = (count) => {
|
|
186
197
|
const take = byCount((n) => Token$1.take(n).step);
|
|
187
198
|
return P.combinator([count], ([countStep]) => (state) => {
|
|
199
|
+
const start = state.pos;
|
|
188
200
|
const n = countStep(state);
|
|
189
201
|
if (n === Fail) return Fail;
|
|
202
|
+
if (!isCount(n)) {
|
|
203
|
+
state.rewind(start);
|
|
204
|
+
return state.backtrack("Verify");
|
|
205
|
+
}
|
|
190
206
|
return take(n)(state);
|
|
191
207
|
}, "lengthTake");
|
|
192
208
|
};
|
|
193
209
|
/**
|
|
194
210
|
* Parses a length with `count`, then applies `parser` that many times
|
|
195
|
-
* (winnow's `length_repeat`, nom's `length_count`).
|
|
211
|
+
* (winnow's `length_repeat`, nom's `length_count`). A length that is not a
|
|
212
|
+
* non-negative integer fails the parse at the length.
|
|
196
213
|
*
|
|
197
214
|
* @since 0.1.0
|
|
198
215
|
* @category length-prefixed
|
|
199
216
|
*/
|
|
200
|
-
const lengthRepeat = (count, parser) => P.flatMap(count, byCount((n) => P.repeat(parser, n)));
|
|
217
|
+
const lengthRepeat = (count, parser) => P.flatMap(P.filter(count, isCount), byCount((n) => P.repeat(parser, n)));
|
|
201
218
|
/**
|
|
202
219
|
* Parses a length with `count`, takes that many tokens, and applies
|
|
203
220
|
* `parser` to them (winnow's `length_and_then`, nom's `length_value`).
|
package/dist/Binary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Binary.js","names":["Token"],"sources":["../src/Binary.ts"],"sourcesContent":["/**\n * Parsers for binary formats: fixed-width integers and floats in either\n * byte order, and length-prefixed data (winnow's `binary` module, nom's\n * `number` and `multi::length_*` parsers).\n *\n * Integers up to 32 bits are returned as `number`, wider integers as\n * `bigint`.\n *\n * @example\n * ```ts\n * import { Binary, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // A length-prefixed (u16 big-endian) payload\n * const frame = Binary.lengthTake(Binary.beU16)\n * Parser.parse(frame, new Uint8Array([0, 2, 0xca, 0xfe])) // Uint8Array [0xca, 0xfe]\n * ```\n *\n * @since 0.1.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type { Input, Slice, State } from \"./Input.js\"\nimport { Fail } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\n\nexport {\n /**\n * Runs a bit-level parser on byte input. See the `Bits` module.\n *\n * @since 0.1.0\n * @category bits\n */\n bits\n} from \"./Bits.js\"\n\n/**\n * A byte order. `\"native\"` is the byte order of the current platform.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Endianness = \"big\" | \"little\" | \"native\"\n\nconst nativeLittle = /*#__PURE__*/ new Uint8Array(/*#__PURE__*/ new Uint16Array([1]).buffer)[0] === 1\n\n/** Reads a number at an offset of a state's bytes. */\ntype Read<A> = (bytes: Uint8Array, offset: number, state: State<Uint8Array>) => A\n\n/**\n * A `DataView` of a state's bytes, for the numbers integer arithmetic can't\n * read: created once per state (whose input never changes), as one per\n * read cost most of a number's time.\n */\nconst viewOf = (state: State<Uint8Array>): DataView => {\n const b = state.input\n return (state.view ??= new DataView(b.buffer, b.byteOffset, b.byteLength))\n}\n\n/** A {@link Read} through the state's view. */\nconst viewed =\n <A>(read: (view: DataView, offset: number) => A): Read<A> =>\n (_, o, s) =>\n read(viewOf(s), o)\n\nconst fixed = <A>(size: number, name: string, read: Read<A>): Parser<A, never, never, Uint8Array> => {\n const expected = [`${size} byte${size === 1 ? \"\" : \"s\"}`]\n return P.described(\n (state: State<Uint8Array>) => {\n const pos = state.pos\n const avail = state.end - pos\n if (avail < size) return state.eoi(\"Token\", expected, size - avail)\n state.pos = pos + size\n return read(state.input, pos, state)\n },\n name,\n { _tag: \"Fixed\", size, read }\n )\n}\n\n// Integers of up to 32 bits are read from the bytes; the rest through a view\nconst readU24 =\n (little: boolean): Read<number> =>\n (b, o) =>\n little ? b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) : (b[o] << 16) | (b[o + 1] << 8) | b[o + 2]\n\nconst readI24 = (little: boolean): Read<number> => {\n const u = readU24(little)\n return (b, o, s) => (u(b, o, s) << 8) >> 8\n}\n\nconst readU128 = (little: boolean): Read<bigint> =>\n viewed((v, o) => {\n const a = v.getBigUint64(o, little)\n const b = v.getBigUint64(o + 8, little)\n return little ? (b << 64n) | a : (a << 64n) | b\n })\n\nconst readI128 = (little: boolean): Read<bigint> => {\n const u = readU128(little)\n return (b, o, s) => BigInt.asIntN(128, u(b, o, s))\n}\n\n/**\n * An unsigned byte.\n *\n * @since 0.1.0\n * @category integers\n */\nexport const u8: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(1, \"u8\", (b, o) => b[o])\n\n/**\n * A signed byte.\n *\n * @since 0.1.0\n * @category integers\n */\nexport const i8: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(1, \"i8\", (b, o) => (b[o] << 24) >> 24)\n\n/** @since 0.1.0 @category integers */\nexport const beU16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"beU16\",\n (b, o) => (b[o] << 8) | b[o + 1]\n)\n/** @since 0.1.0 @category integers */\nexport const leU16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"leU16\",\n (b, o) => b[o] | (b[o + 1] << 8)\n)\n/** @since 0.1.0 @category integers */\nexport const beI16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"beI16\",\n (b, o) => (((b[o] << 8) | b[o + 1]) << 16) >> 16\n)\n/** @since 0.1.0 @category integers */\nexport const leI16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"leI16\",\n (b, o) => ((b[o] | (b[o + 1] << 8)) << 16) >> 16\n)\n/** @since 0.1.0 @category integers */\nexport const beU24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"beU24\",\n /*#__PURE__*/ readU24(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leU24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"leU24\",\n /*#__PURE__*/ readU24(true)\n)\n/** @since 0.1.0 @category integers */\nexport const beI24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"beI24\",\n /*#__PURE__*/ readI24(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leI24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"leI24\",\n /*#__PURE__*/ readI24(true)\n)\n/** @since 0.1.0 @category integers */\nexport const beU32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"beU32\",\n (b, o) => ((b[o] << 24) | (b[o + 1] << 16) | (b[o + 2] << 8) | b[o + 3]) >>> 0\n)\n/** @since 0.1.0 @category integers */\nexport const leU32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"leU32\",\n (b, o) => (b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24)) >>> 0\n)\n/** @since 0.1.0 @category integers */\nexport const beI32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"beI32\",\n (b, o) => (b[o] << 24) | (b[o + 1] << 16) | (b[o + 2] << 8) | b[o + 3]\n)\n/** @since 0.1.0 @category integers */\nexport const leI32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"leI32\",\n (b, o) => b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24)\n)\n/** @since 0.1.0 @category integers */\nexport const beU64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"beU64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigUint64(o, false))\n)\n/** @since 0.1.0 @category integers */\nexport const leU64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"leU64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigUint64(o, true))\n)\n/** @since 0.1.0 @category integers */\nexport const beI64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"beI64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigInt64(o, false))\n)\n/** @since 0.1.0 @category integers */\nexport const leI64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"leI64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigInt64(o, true))\n)\n/** @since 0.1.0 @category integers */\nexport const beU128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"beU128\",\n /*#__PURE__*/ readU128(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leU128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"leU128\",\n /*#__PURE__*/ readU128(true)\n)\n/** @since 0.1.0 @category integers */\nexport const beI128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"beI128\",\n /*#__PURE__*/ readI128(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leI128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"leI128\",\n /*#__PURE__*/ readI128(true)\n)\n\n/** @since 0.1.0 @category floats */\nexport const beF32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"beF32\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat32(o, false))\n)\n/** @since 0.1.0 @category floats */\nexport const leF32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"leF32\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat32(o, true))\n)\n/** @since 0.1.0 @category floats */\nexport const beF64: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"beF64\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat64(o, false))\n)\n/** @since 0.1.0 @category floats */\nexport const leF64: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"leF64\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat64(o, true))\n)\n\nconst byEndian =\n <A>(big: A, little: A) =>\n (endian: Endianness): A =>\n endian === \"big\" ? big : endian === \"little\" ? little : nativeLittle ? little : big\n\n/**\n * An unsigned 16-bit integer in the given byte order (winnow's `u16`).\n *\n * @since 0.1.0\n * @category integers\n */\nexport const u16: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU16,\n leU16\n)\n/** @since 0.1.0 @category integers */\nexport const i16: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI16,\n leI16\n)\n/** @since 0.1.0 @category integers */\nexport const u24: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU24,\n leU24\n)\n/** @since 0.1.0 @category integers */\nexport const i24: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI24,\n leI24\n)\n/** @since 0.1.0 @category integers */\nexport const u32: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU32,\n leU32\n)\n/** @since 0.1.0 @category integers */\nexport const i32: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI32,\n leI32\n)\n/** @since 0.1.0 @category integers */\nexport const u64: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU64,\n leU64\n)\n/** @since 0.1.0 @category integers */\nexport const i64: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI64,\n leI64\n)\n/** @since 0.1.0 @category integers */\nexport const u128: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU128,\n leU128\n)\n/** @since 0.1.0 @category integers */\nexport const i128: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI128,\n leI128\n)\n/** @since 0.1.0 @category floats */\nexport const f32: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beF32,\n leF32\n)\n/** @since 0.1.0 @category floats */\nexport const f64: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beF64,\n leF64\n)\n\nconst toCount = (n: number | bigint): number => (Predicate.isBigInt(n) ? Number(n) : n)\n\n/** How many counts {@link byCount} keeps the parsers of. */\nconst CountCache = 256\n\n/**\n * `build`, keeping the parsers it built for the first {@link CountCache}\n * counts seen: length-prefixed data repeats a few lengths, and building a\n * parser per value cost several times the parse.\n */\nconst byCount = <A>(build: (n: number) => A): ((n: number | bigint) => A) => {\n const built = new Map<number, A>()\n return (n) => {\n const count = toCount(n)\n let a = built.get(count)\n if (a === undefined) {\n a = build(count)\n if (built.size < CountCache) built.set(count, a)\n }\n return a\n }\n}\n\n/**\n * Parses a length with `count`, then takes that many tokens (winnow's\n * `length_take`, nom's `length_data`).\n *\n * @since 0.1.0\n * @category length-prefixed\n */\nexport const lengthTake = <E, R, I extends Input = Uint8Array>(\n count: Parser<number | bigint, E, R, I>\n): Parser<Slice<I>, E, R, I> => {\n const take = byCount((n) => Token.take<I>(n).step)\n // The count compiles with the grammar: the step is built from its (see `Parser.combinator`)\n return P.combinator(\n [count],\n ([countStep]) =>\n (state: State<I>) => {\n // SAFETY: the count parser's step, interpreted or compiled, returns its output (a number or bigint) or `Fail`\n const n = countStep(state) as number | bigint | Fail\n if (n === Fail) return Fail\n return take(n)(state)\n },\n \"lengthTake\"\n )\n}\n\n/**\n * Parses a length with `count`, then applies `parser` that many times\n * (winnow's `length_repeat`, nom's `length_count`).\n *\n * @since 0.1.0\n * @category length-prefixed\n */\nexport const lengthRepeat = <E, R, I extends Input, A, E2, R2, I2 extends Input>(\n count: Parser<number | bigint, E, R, I>,\n parser: Parser<A, E2, R2, I2>\n): Parser<Array<A>, E | E2, R | R2, I & I2> =>\n P.flatMap(\n count,\n byCount((n) => P.repeat(parser, n))\n )\n\n/**\n * Parses a length with `count`, takes that many tokens, and applies\n * `parser` to them (winnow's `length_and_then`, nom's `length_value`).\n * `parser` does not need to consume the whole slice.\n *\n * @since 0.1.0\n * @category length-prefixed\n */\nexport const lengthAndThen = <E, R, I extends Input, A, E2, R2>(\n count: Parser<number | bigint, E, R, I>,\n parser: Parser<A, E2, R2, Slice<I> & Input>\n): Parser<A, E | E2, R | R2, I> =>\n // SAFETY: a slice of an input is itself an input (a string, a `Uint8Array` or an array), so `Slice<I>` is an `Input`\n P.mapParser(lengthTake(count) as Parser<Slice<I> & Input, E, R, I>, P.complete(parser))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,8BAA6B,IAAI,0BAAyB,IAAI,YAAY,CAAC,CAAC,CAAC,EAAA,CAAE,MAAM,EAAA,CAAE,OAAO;;;;;;AAUpG,MAAM,UAAU,UAAuC;CACrD,MAAM,IAAI,MAAM;CAChB,OAAQ,MAAM,SAAS,IAAI,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU;AAC1E;;AAGA,MAAM,UACA,UACH,GAAG,GAAG,MACL,KAAK,OAAO,CAAC,GAAG,CAAC;AAErB,MAAM,SAAY,MAAc,MAAc,SAAuD;CACnG,MAAM,WAAW,CAAC,GAAG,KAAK,OAAO,SAAS,IAAI,KAAK,KAAK;CACxD,OAAO,EAAE,WACN,UAA6B;EAC5B,MAAM,MAAM,MAAM;EAClB,MAAM,QAAQ,MAAM,MAAM;EAC1B,IAAI,QAAQ,MAAM,OAAO,MAAM,IAAI,SAAS,UAAU,OAAO,KAAK;EAClE,MAAM,MAAM,MAAM;EAClB,OAAO,KAAK,MAAM,OAAO,KAAK,KAAK;CACrC,GACA,MACA;EAAE,MAAM;EAAS;EAAM;CAAK,CAC9B;AACF;AAGA,MAAM,WACH,YACA,GAAG,MACF,SAAS,EAAE,KAAM,EAAE,IAAI,MAAM,IAAM,EAAE,IAAI,MAAM,KAAO,EAAE,MAAM,KAAO,EAAE,IAAI,MAAM,IAAK,EAAE,I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;AACF;;;;;;;;AASA,MAAa,cACX,UAC8B;CAC9B,MAAM,OAAO,SAAS,MAAMA,QAAM,KAAQ,CAAC,CAAC,CAAC,IAAI;CAEjD,OAAO,EAAE,WACP,CAAC,KAAK,IACL,CAAC,gBACC,UAAoB;EAEnB,MAAM,IAAI,UAAU,KAAK;EACzB,IAAI,MAAM,MAAM,OAAO;EACvB,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK;CACtB,GACF,YACF;AACF;;;;;;;;AASA,MAAa,gBACX,OACA,WAEA,EAAE,QACA,OACA,SAAS,MAAM,EAAE,OAAO,QAAQ,CAAC,CAAC,CACpC;;;;;;;;;AAUF,MAAa,iBACX,OACA,WAGA,EAAE,UAAU,WAAW,KAAK,GAAwC,EAAE,SAAS,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"Binary.js","names":["Token"],"sources":["../src/Binary.ts"],"sourcesContent":["/**\n * Parsers for binary formats: fixed-width integers and floats in either\n * byte order, and length-prefixed data (winnow's `binary` module, nom's\n * `number` and `multi::length_*` parsers).\n *\n * Integers up to 32 bits are returned as `number`, wider integers as\n * `bigint`.\n *\n * @example\n * ```ts\n * import { Binary, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // A length-prefixed (u16 big-endian) payload\n * const frame = Binary.lengthTake(Binary.beU16)\n * Parser.parse(frame, new Uint8Array([0, 2, 0xca, 0xfe])) // Uint8Array [0xca, 0xfe]\n * ```\n *\n * @since 0.1.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type { Input, Slice, State } from \"./Input.js\"\nimport { Fail } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\n\nexport {\n /**\n * Runs a bit-level parser on byte input. See the `Bits` module.\n *\n * @since 0.1.0\n * @category bits\n */\n bits\n} from \"./Bits.js\"\n\n/**\n * A byte order. `\"native\"` is the byte order of the current platform.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Endianness = \"big\" | \"little\" | \"native\"\n\nconst nativeLittle = /*#__PURE__*/ new Uint8Array(/*#__PURE__*/ new Uint16Array([1]).buffer)[0] === 1\n\n/** Reads a number at an offset of a state's bytes. */\ntype Read<A> = (bytes: Uint8Array, offset: number, state: State<Uint8Array>) => A\n\n/**\n * A `DataView` of a state's bytes, for the numbers integer arithmetic can't\n * read: created once per state (whose input never changes), as one per\n * read cost most of a number's time.\n */\nconst viewOf = (state: State<Uint8Array>): DataView => {\n const b = state.input\n return (state.view ??= new DataView(b.buffer, b.byteOffset, b.byteLength))\n}\n\n/** A {@link Read} through the state's view. */\nconst viewed =\n <A>(read: (view: DataView, offset: number) => A): Read<A> =>\n (_, o, s) =>\n read(viewOf(s), o)\n\nconst fixed = <A>(size: number, name: string, read: Read<A>): Parser<A, never, never, Uint8Array> => {\n const expected = [`${size} byte${size === 1 ? \"\" : \"s\"}`]\n return P.described(\n (state: State<Uint8Array>) => {\n const pos = state.pos\n const avail = state.end - pos\n if (avail < size) return state.eoi(\"Token\", expected, size - avail)\n state.pos = pos + size\n return read(state.input, pos, state)\n },\n name,\n { _tag: \"Fixed\", size, read }\n )\n}\n\n// Integers of up to 32 bits are read from the bytes; the rest through a view\nconst readU24 =\n (little: boolean): Read<number> =>\n (b, o) =>\n little ? b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) : (b[o] << 16) | (b[o + 1] << 8) | b[o + 2]\n\nconst readI24 = (little: boolean): Read<number> => {\n const u = readU24(little)\n return (b, o, s) => (u(b, o, s) << 8) >> 8\n}\n\nconst readU128 = (little: boolean): Read<bigint> =>\n viewed((v, o) => {\n const a = v.getBigUint64(o, little)\n const b = v.getBigUint64(o + 8, little)\n return little ? (b << 64n) | a : (a << 64n) | b\n })\n\nconst readI128 = (little: boolean): Read<bigint> => {\n const u = readU128(little)\n return (b, o, s) => BigInt.asIntN(128, u(b, o, s))\n}\n\n/**\n * An unsigned byte.\n *\n * @since 0.1.0\n * @category integers\n */\nexport const u8: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(1, \"u8\", (b, o) => b[o])\n\n/**\n * A signed byte.\n *\n * @since 0.1.0\n * @category integers\n */\nexport const i8: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(1, \"i8\", (b, o) => (b[o] << 24) >> 24)\n\n/** @since 0.1.0 @category integers */\nexport const beU16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"beU16\",\n (b, o) => (b[o] << 8) | b[o + 1]\n)\n/** @since 0.1.0 @category integers */\nexport const leU16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"leU16\",\n (b, o) => b[o] | (b[o + 1] << 8)\n)\n/** @since 0.1.0 @category integers */\nexport const beI16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"beI16\",\n (b, o) => (((b[o] << 8) | b[o + 1]) << 16) >> 16\n)\n/** @since 0.1.0 @category integers */\nexport const leI16: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 2,\n \"leI16\",\n (b, o) => ((b[o] | (b[o + 1] << 8)) << 16) >> 16\n)\n/** @since 0.1.0 @category integers */\nexport const beU24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"beU24\",\n /*#__PURE__*/ readU24(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leU24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"leU24\",\n /*#__PURE__*/ readU24(true)\n)\n/** @since 0.1.0 @category integers */\nexport const beI24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"beI24\",\n /*#__PURE__*/ readI24(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leI24: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 3,\n \"leI24\",\n /*#__PURE__*/ readI24(true)\n)\n/** @since 0.1.0 @category integers */\nexport const beU32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"beU32\",\n (b, o) => ((b[o] << 24) | (b[o + 1] << 16) | (b[o + 2] << 8) | b[o + 3]) >>> 0\n)\n/** @since 0.1.0 @category integers */\nexport const leU32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"leU32\",\n (b, o) => (b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24)) >>> 0\n)\n/** @since 0.1.0 @category integers */\nexport const beI32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"beI32\",\n (b, o) => (b[o] << 24) | (b[o + 1] << 16) | (b[o + 2] << 8) | b[o + 3]\n)\n/** @since 0.1.0 @category integers */\nexport const leI32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"leI32\",\n (b, o) => b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24)\n)\n/** @since 0.1.0 @category integers */\nexport const beU64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"beU64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigUint64(o, false))\n)\n/** @since 0.1.0 @category integers */\nexport const leU64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"leU64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigUint64(o, true))\n)\n/** @since 0.1.0 @category integers */\nexport const beI64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"beI64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigInt64(o, false))\n)\n/** @since 0.1.0 @category integers */\nexport const leI64: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"leI64\",\n /*#__PURE__*/ viewed((v, o) => v.getBigInt64(o, true))\n)\n/** @since 0.1.0 @category integers */\nexport const beU128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"beU128\",\n /*#__PURE__*/ readU128(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leU128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"leU128\",\n /*#__PURE__*/ readU128(true)\n)\n/** @since 0.1.0 @category integers */\nexport const beI128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"beI128\",\n /*#__PURE__*/ readI128(false)\n)\n/** @since 0.1.0 @category integers */\nexport const leI128: Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 16,\n \"leI128\",\n /*#__PURE__*/ readI128(true)\n)\n\n/** @since 0.1.0 @category floats */\nexport const beF32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"beF32\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat32(o, false))\n)\n/** @since 0.1.0 @category floats */\nexport const leF32: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 4,\n \"leF32\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat32(o, true))\n)\n/** @since 0.1.0 @category floats */\nexport const beF64: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"beF64\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat64(o, false))\n)\n/** @since 0.1.0 @category floats */\nexport const leF64: Parser<number, never, never, Uint8Array> = /*#__PURE__*/ fixed(\n 8,\n \"leF64\",\n /*#__PURE__*/ viewed((v, o) => v.getFloat64(o, true))\n)\n\nconst byEndian =\n <A>(big: A, little: A) =>\n (endian: Endianness): A =>\n endian === \"big\" ? big : endian === \"little\" ? little : nativeLittle ? little : big\n\n/**\n * An unsigned 16-bit integer in the given byte order (winnow's `u16`).\n *\n * @since 0.1.0\n * @category integers\n */\nexport const u16: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU16,\n leU16\n)\n/** @since 0.1.0 @category integers */\nexport const i16: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI16,\n leI16\n)\n/** @since 0.1.0 @category integers */\nexport const u24: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU24,\n leU24\n)\n/** @since 0.1.0 @category integers */\nexport const i24: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI24,\n leI24\n)\n/** @since 0.1.0 @category integers */\nexport const u32: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU32,\n leU32\n)\n/** @since 0.1.0 @category integers */\nexport const i32: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI32,\n leI32\n)\n/** @since 0.1.0 @category integers */\nexport const u64: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU64,\n leU64\n)\n/** @since 0.1.0 @category integers */\nexport const i64: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI64,\n leI64\n)\n/** @since 0.1.0 @category integers */\nexport const u128: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beU128,\n leU128\n)\n/** @since 0.1.0 @category integers */\nexport const i128: (endian: Endianness) => Parser<bigint, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beI128,\n leI128\n)\n/** @since 0.1.0 @category floats */\nexport const f32: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beF32,\n leF32\n)\n/** @since 0.1.0 @category floats */\nexport const f64: (endian: Endianness) => Parser<number, never, never, Uint8Array> = /*#__PURE__*/ byEndian(\n beF64,\n leF64\n)\n\nconst MaxCount = /*#__PURE__*/ BigInt(Number.MAX_SAFE_INTEGER)\n\n/**\n * Whether a length read from the input is a count: a non-negative integer\n * of at most `Number.MAX_SAFE_INTEGER`. A signed, fractional or `NaN`\n * length is the input's to choose, so it fails the parse where it was read\n * (as `Parser.filter` does) and never reaches `Token.take` or\n * `Parser.repeat`, which throw on one.\n */\nconst isCount = (n: number | bigint): boolean =>\n Predicate.isBigInt(n) ? n >= 0n && n <= MaxCount : Number.isSafeInteger(n) && n >= 0\n\nconst toCount = (n: number | bigint): number => (Predicate.isBigInt(n) ? Number(n) : n)\n\n/** How many counts {@link byCount} keeps the parsers of. */\nconst CountCache = 256\n\n/**\n * `build`, keeping the parsers it built for the first {@link CountCache}\n * counts seen: length-prefixed data repeats a few lengths, and building a\n * parser per value cost several times the parse.\n */\nconst byCount = <A>(build: (n: number) => A): ((n: number | bigint) => A) => {\n const built = new Map<number, A>()\n return (n) => {\n const count = toCount(n)\n let a = built.get(count)\n if (a === undefined) {\n a = build(count)\n if (built.size < CountCache) built.set(count, a)\n }\n return a\n }\n}\n\n/**\n * Parses a length with `count`, then takes that many tokens (winnow's\n * `length_take`, nom's `length_data`). A length that is not a non-negative\n * integer (a negative `i8`, a fractional float) fails the parse at the\n * length.\n *\n * @since 0.1.0\n * @category length-prefixed\n */\nexport const lengthTake = <E, R, I extends Input = Uint8Array>(\n count: Parser<number | bigint, E, R, I>\n): Parser<Slice<I>, E, R, I> => {\n const take = byCount((n) => Token.take<I>(n).step)\n // The count compiles with the grammar: the step is built from its (see `Parser.combinator`)\n return P.combinator(\n [count],\n ([countStep]) =>\n (state: State<I>) => {\n const start = state.pos\n // SAFETY: the count parser's step, interpreted or compiled, returns its output (a number or bigint) or `Fail`\n const n = countStep(state) as number | bigint | Fail\n if (n === Fail) return Fail\n // As `Parser.filter` fails: at the length, backtracking\n if (!isCount(n)) {\n state.rewind(start)\n return state.backtrack(\"Verify\")\n }\n return take(n)(state)\n },\n \"lengthTake\"\n )\n}\n\n/**\n * Parses a length with `count`, then applies `parser` that many times\n * (winnow's `length_repeat`, nom's `length_count`). A length that is not a\n * non-negative integer fails the parse at the length.\n *\n * @since 0.1.0\n * @category length-prefixed\n */\nexport const lengthRepeat = <E, R, I extends Input, A, E2, R2, I2 extends Input>(\n count: Parser<number | bigint, E, R, I>,\n parser: Parser<A, E2, R2, I2>\n): Parser<Array<A>, E | E2, R | R2, I & I2> =>\n P.flatMap(\n P.filter(count, isCount),\n byCount((n) => P.repeat(parser, n))\n )\n\n/**\n * Parses a length with `count`, takes that many tokens, and applies\n * `parser` to them (winnow's `length_and_then`, nom's `length_value`).\n * `parser` does not need to consume the whole slice.\n *\n * @since 0.1.0\n * @category length-prefixed\n */\nexport const lengthAndThen = <E, R, I extends Input, A, E2, R2>(\n count: Parser<number | bigint, E, R, I>,\n parser: Parser<A, E2, R2, Slice<I> & Input>\n): Parser<A, E | E2, R | R2, I> =>\n // SAFETY: a slice of an input is itself an input (a string, a `Uint8Array` or an array), so `Slice<I>` is an `Input`\n P.mapParser(lengthTake(count) as Parser<Slice<I> & Input, E, R, I>, P.complete(parser))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,8BAA6B,IAAI,0BAAyB,IAAI,YAAY,CAAC,CAAC,CAAC,EAAA,CAAE,MAAM,EAAA,CAAE,OAAO;;;;;;AAUpG,MAAM,UAAU,UAAuC;CACrD,MAAM,IAAI,MAAM;CAChB,OAAQ,MAAM,SAAS,IAAI,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU;AAC1E;;AAGA,MAAM,UACA,UACH,GAAG,GAAG,MACL,KAAK,OAAO,CAAC,GAAG,CAAC;AAErB,MAAM,SAAY,MAAc,MAAc,SAAuD;CACnG,MAAM,WAAW,CAAC,GAAG,KAAK,OAAO,SAAS,IAAI,KAAK,KAAK;CACxD,OAAO,EAAE,WACN,UAA6B;EAC5B,MAAM,MAAM,MAAM;EAClB,MAAM,QAAQ,MAAM,MAAM;EAC1B,IAAI,QAAQ,MAAM,OAAO,MAAM,IAAI,SAAS,UAAU,OAAO,KAAK;EAClE,MAAM,MAAM,MAAM;EAClB,OAAO,KAAK,MAAM,OAAO,KAAK,KAAK;CACrC,GACA,MACA;EAAE,MAAM;EAAS;EAAM;CAAK,CAC9B;AACF;AAGA,MAAM,WACH,YACA,G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;AAOnB,MAAM,WAAc,UAAyD;CAC3E,MAAM,wBAAQ,IAAI,IAAe;CACjC,QAAQ,MAAM;EACZ,MAAM,QAAQ,QAAQ,CAAC;EACvB,IAAI,IAAI,MAAM,IAAI,KAAK;EACvB,IAAI,MAAM,KAAA,GAAW;GACnB,IAAI,MAAM,KAAK;GACf,IAAI,MAAM,OAAO,YAAY,MAAM,IAAI,OAAO,CAAC;EACjD;EACA,OAAO;CACT;AACF;;;;;;;;;;AAWA,MAAa,cACX,UAC8B;CAC9B,MAAM,OAAO,SAAS,MAAMA,QAAM,KAAQ,CAAC,CAAC,CAAC,IAAI;CAEjD,OAAO,EAAE,WACP,CAAC,KAAK,IACL,CAAC,gBACC,UAAoB;EACnB,MAAM,QAAQ,MAAM;EAEpB,MAAM,IAAI,UAAU,KAAK;EACzB,IAAI,MAAM,MAAM,OAAO;EAEvB,IAAI,CAAC,QAAQ,CAAC,GAAG;GACf,MAAM,OAAO,KAAK;GAClB,OAAO,MAAM,UAAU,QAAQ;EACjC;EACA,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK;CACtB,GACF,YACF;AACF;;;;;;;;;AAUA,MAAa,gBACX,OACA,WAEA,EAAE,QACA,EAAE,OAAO,OAAO,OAAO,GACvB,SAAS,MAAM,EAAE,OAAO,QAAQ,CAAC,CAAC,CACpC;;;;;;;;;AAUF,MAAa,iBACX,OACA,WAGA,EAAE,UAAU,WAAW,KAAK,GAAwC,EAAE,SAAS,MAAM,CAAC"}
|
package/dist/Bits.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bits.d.ts","names":[],"sources":["../src/Bits.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"Bits.d.ts","names":[],"sources":["../src/Bits.ts"],"mappings":";cA4Bc;;;;;;;;iBASG,iBAAiB;YACtB;;;;;;;;;qBAyDC,OAAQ,GAAG,GAAG,GAAG,MAAM,OAAO,GAAG,GAAG,GAAG,cAAY,OAAO,GAAG,GAAG,GAAG;;;;;;;;qBAYnE,QAAS,GAAG,GAAG,GAAG,MAAM,OAAO,GAAG,GAAG,GAAG,gBAAc,OAAO,GAAG,GAAG,GAAG;;;;;;;;qBA+BtE,OAAQ,kBAAgB,6BAA6B;;;;;;;qBAiBrD,UAAW,kBAAgB,6BAA6B;;;;;;;;qBAwBxD,UAAW,iBAAiB,kBAAgB,6BAA6B;;;;;;;qBAsBzE,MAAM,8BAA8B"}
|
package/dist/Bits.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Fail, Failure } from "./Input.js";
|
|
2
2
|
import { make } from "./Parser.js";
|
|
3
|
+
import { checkCount } from "./internal/node.js";
|
|
3
4
|
// src/Bits.ts
|
|
4
5
|
const scale = (f, factor) => new Failure(factor < 1 ? Math.floor(f.offset * factor) : f.offset * factor, f.kind, f.expected, f.context, f.hasCause, f.cause, f.message, factor < 1 ? Math.ceil(f.needed * factor) : f.needed * factor);
|
|
5
6
|
/**
|
|
@@ -79,6 +80,7 @@ const readBits = (state, count) => {
|
|
|
79
80
|
* @category parsers
|
|
80
81
|
*/
|
|
81
82
|
const take = (count) => {
|
|
83
|
+
checkCount(count);
|
|
82
84
|
if (count > 53) throw new RangeError("Bits.take: use Bits.takeBig for more than 53 bits");
|
|
83
85
|
const expected = [`${count} bits`];
|
|
84
86
|
return make((state) => {
|
|
@@ -94,6 +96,7 @@ const take = (count) => {
|
|
|
94
96
|
* @category parsers
|
|
95
97
|
*/
|
|
96
98
|
const takeBig = (count) => {
|
|
99
|
+
checkCount(count);
|
|
97
100
|
const expected = [`${count} bits`];
|
|
98
101
|
return make((state) => {
|
|
99
102
|
const avail = state.end - state.pos;
|
|
@@ -116,6 +119,7 @@ const takeBig = (count) => {
|
|
|
116
119
|
* @category parsers
|
|
117
120
|
*/
|
|
118
121
|
const pattern = (pattern, count) => {
|
|
122
|
+
checkCount(count);
|
|
119
123
|
const expected = [`bit pattern ${pattern.toString(2).padStart(count, "0")}`];
|
|
120
124
|
return make((state) => {
|
|
121
125
|
const start = state.pos;
|
package/dist/Bits.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bits.js","names":[],"sources":["../src/Bits.ts"],"sourcesContent":["/**\n * Bit-level parsing (winnow's `binary::bits`, nom's `bits` module).\n *\n * Bit parsers run inside {@link bits}, which switches a byte parser into\n * bit mode. Bits are read most-significant first. When `bits` finishes, any\n * remaining bits of a partly consumed byte are skipped.\n *\n * Inside `bits`, offsets count bits, so the general combinators (`alt`,\n * `repeat`, `opt`, ...) backtrack at bit granularity.\n *\n * @example\n * ```ts\n * import { Binary, Bits, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // An IPv4 header starts with a 4-bit version and a 4-bit header length\n * const versionAndLength = Bits.bits(Parser.seq(Bits.take(4), Bits.take(4)))\n *\n * Parser.parse(versionAndLength, new Uint8Array([0x45])) // Result.succeed([4, 5])\n * ```\n *\n * @since 0.1.0\n */\nimport type { State } from \"./Input.js\"\nimport { Fail, Failure } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { make } from \"./Parser.js\"\n\ndeclare const BitInputBrand: unique symbol\n\n/**\n * The input type of bit-level parsers. A `Parser<A, E, R, BitInput>` can\n * only be run inside {@link bits}.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface BitInput extends ReadonlyArray<never> {\n readonly [BitInputBrand]: true\n}\n\nconst scale = (f: Failure, factor: number): Failure =>\n new Failure(\n factor < 1 ? Math.floor(f.offset * factor) : f.offset * factor,\n f.kind,\n f.expected,\n f.context,\n f.hasCause,\n f.cause,\n f.message,\n factor < 1 ? Math.ceil(f.needed * factor) : f.needed * factor\n )\n\n/**\n * Runs `step` with offsets measured in different units (bits vs bytes),\n * converting failure offsets back to the outer units afterwards.\n */\nconst inUnits = <A>(state: State<any>, factor: number, step: (state: State<any>) => A | Fail): A | Fail => {\n const end = state.end\n const deepest = state.deepest\n state.deepest = undefined\n state.pos = factor > 1 ? state.pos * factor : Math.ceil(state.pos * factor)\n state.end = end * factor\n const a = step(state)\n state.end = end\n const inner = state.deepest\n state.deepest = deepest\n if (a === Fail) {\n state.pos = factor > 1 ? Math.floor(state.pos / factor) : state.pos / factor\n const f = state.failure\n state.failure = scale(f, 1 / factor)\n // A committed failure keeps only the failures recorded after the commit\n // (see `Parser.cut`), so none from before these units\n if (state.mode === \"Cut\") state.deepest = undefined\n if (inner !== undefined) {\n const d = inner === f ? state.failure : scale(inner, 1 / factor)\n if (state.deepest === undefined || d.offset >= state.deepest.offset) state.deepest = d\n }\n return Fail\n }\n state.pos = factor > 1 ? Math.ceil(state.pos / factor) : state.pos / factor\n if (inner !== undefined) {\n const d = scale(inner, 1 / factor)\n if (deepest === undefined || d.offset >= deepest.offset) state.deepest = d\n }\n return a\n}\n\n/**\n * Runs a bit-level parser on byte input (winnow's and nom's `bits`). After\n * success, the input advances to the next byte boundary.\n *\n * @since 0.1.0\n * @category combinators\n */\nexport const bits = <A, E, R>(self: Parser<A, E, R, BitInput>): Parser<A, E, R, Uint8Array> => {\n const step = self.step\n return make((state) => inUnits(state, 8, step), \"bits\")\n}\n\n/**\n * Runs a byte-level parser from within a bit-level parser (winnow's and\n * nom's `bytes`). The partly consumed byte, if any, is skipped first.\n *\n * @since 0.1.0\n * @category combinators\n */\nexport const bytes = <A, E, R>(self: Parser<A, E, R, Uint8Array>): Parser<A, E, R, BitInput> => {\n const step = self.step\n return make((state: State<any>) => inUnits(state, 1 / 8, step), \"bytes\")\n}\n\nconst readBits = (state: State<any>, count: number): number => {\n // SAFETY: bit-level parsers run inside `bits`, on the `Uint8Array` it was given (`BitInput` only re-indexes it in bits)\n const input = state.input as Uint8Array\n let pos = state.pos\n let value = 0\n let left = count\n // As many bits as the current byte holds at once, not one at a time\n while (left > 0) {\n const avail = 8 - (pos & 7)\n const n = left < avail ? left : avail\n // Multiplying, not shifting: the value can have up to 53 bits\n value = value * (1 << n) + ((input[pos >>> 3] >>> (avail - n)) & ((1 << n) - 1))\n pos += n\n left -= n\n }\n state.pos = pos\n return value\n}\n\n/**\n * Takes `count` bits (at most 53) as an unsigned number (winnow's and nom's\n * bit-level `take`).\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const take = (count: number): Parser<number, never, never, BitInput> => {\n if (count > 53) throw new RangeError(\"Bits.take: use Bits.takeBig for more than 53 bits\")\n const expected = [`${count} bits`]\n return make((state: State<any>) => {\n const avail = state.end - state.pos\n if (avail < count) return state.eoi(\"Bits\", expected, count - avail)\n return readBits(state, count)\n }, \"take\")\n}\n\n/**\n * Takes `count` bits as an unsigned `bigint`.\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const takeBig = (count: number): Parser<bigint, never, never, BitInput> => {\n const expected = [`${count} bits`]\n return make((state: State<any>) => {\n const avail = state.end - state.pos\n if (avail < count) return state.eoi(\"Bits\", expected, count - avail)\n let value = 0n\n let remaining = count\n while (remaining > 0) {\n const n = Math.min(remaining, 32)\n value = (value << BigInt(n)) | BigInt(readBits(state, n))\n remaining -= n\n }\n return value\n }, \"takeBig\")\n}\n\n/**\n * Matches `count` bits equal to `pattern` (winnow's `pattern`, nom's bit\n * `tag`).\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const pattern = (pattern: number, count: number): Parser<number, never, never, BitInput> => {\n const expected = [`bit pattern ${pattern.toString(2).padStart(count, \"0\")}`]\n return make((state: State<any>) => {\n const start = state.pos\n const avail = state.end - start\n if (avail < count) return state.eoi(\"Bits\", expected, count - avail)\n const value = readBits(state, count)\n if (value !== pattern) {\n state.rewind(start)\n return state.backtrack(\"Bits\", expected)\n }\n return value\n }, \"pattern\")\n}\n\n/**\n * Takes one bit as a boolean (winnow's and nom's `bool`).\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const bool: Parser<boolean, never, never, BitInput> = /*#__PURE__*/ make((state: State<any>) => {\n if (state.pos >= state.end) return state.eoi(\"Bits\", [\"1 bit\"], 1)\n return readBits(state, 1) === 1\n}, \"bool\")\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Bits.js","names":[],"sources":["../src/Bits.ts"],"sourcesContent":["/**\n * Bit-level parsing (winnow's `binary::bits`, nom's `bits` module).\n *\n * Bit parsers run inside {@link bits}, which switches a byte parser into\n * bit mode. Bits are read most-significant first. When `bits` finishes, any\n * remaining bits of a partly consumed byte are skipped.\n *\n * Inside `bits`, offsets count bits, so the general combinators (`alt`,\n * `repeat`, `opt`, ...) backtrack at bit granularity.\n *\n * @example\n * ```ts\n * import { Binary, Bits, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // An IPv4 header starts with a 4-bit version and a 4-bit header length\n * const versionAndLength = Bits.bits(Parser.seq(Bits.take(4), Bits.take(4)))\n *\n * Parser.parse(versionAndLength, new Uint8Array([0x45])) // Result.succeed([4, 5])\n * ```\n *\n * @since 0.1.0\n */\nimport type { State } from \"./Input.js\"\nimport { Fail, Failure } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { make } from \"./Parser.js\"\nimport { checkCount } from \"./internal/node.js\"\n\ndeclare const BitInputBrand: unique symbol\n\n/**\n * The input type of bit-level parsers. A `Parser<A, E, R, BitInput>` can\n * only be run inside {@link bits}.\n *\n * @since 0.1.0\n * @category models\n */\nexport interface BitInput extends ReadonlyArray<never> {\n readonly [BitInputBrand]: true\n}\n\nconst scale = (f: Failure, factor: number): Failure =>\n new Failure(\n factor < 1 ? Math.floor(f.offset * factor) : f.offset * factor,\n f.kind,\n f.expected,\n f.context,\n f.hasCause,\n f.cause,\n f.message,\n factor < 1 ? Math.ceil(f.needed * factor) : f.needed * factor\n )\n\n/**\n * Runs `step` with offsets measured in different units (bits vs bytes),\n * converting failure offsets back to the outer units afterwards.\n */\nconst inUnits = <A>(state: State<any>, factor: number, step: (state: State<any>) => A | Fail): A | Fail => {\n const end = state.end\n const deepest = state.deepest\n state.deepest = undefined\n state.pos = factor > 1 ? state.pos * factor : Math.ceil(state.pos * factor)\n state.end = end * factor\n const a = step(state)\n state.end = end\n const inner = state.deepest\n state.deepest = deepest\n if (a === Fail) {\n state.pos = factor > 1 ? Math.floor(state.pos / factor) : state.pos / factor\n const f = state.failure\n state.failure = scale(f, 1 / factor)\n // A committed failure keeps only the failures recorded after the commit\n // (see `Parser.cut`), so none from before these units\n if (state.mode === \"Cut\") state.deepest = undefined\n if (inner !== undefined) {\n const d = inner === f ? state.failure : scale(inner, 1 / factor)\n if (state.deepest === undefined || d.offset >= state.deepest.offset) state.deepest = d\n }\n return Fail\n }\n state.pos = factor > 1 ? Math.ceil(state.pos / factor) : state.pos / factor\n if (inner !== undefined) {\n const d = scale(inner, 1 / factor)\n if (deepest === undefined || d.offset >= deepest.offset) state.deepest = d\n }\n return a\n}\n\n/**\n * Runs a bit-level parser on byte input (winnow's and nom's `bits`). After\n * success, the input advances to the next byte boundary.\n *\n * @since 0.1.0\n * @category combinators\n */\nexport const bits = <A, E, R>(self: Parser<A, E, R, BitInput>): Parser<A, E, R, Uint8Array> => {\n const step = self.step\n return make((state) => inUnits(state, 8, step), \"bits\")\n}\n\n/**\n * Runs a byte-level parser from within a bit-level parser (winnow's and\n * nom's `bytes`). The partly consumed byte, if any, is skipped first.\n *\n * @since 0.1.0\n * @category combinators\n */\nexport const bytes = <A, E, R>(self: Parser<A, E, R, Uint8Array>): Parser<A, E, R, BitInput> => {\n const step = self.step\n return make((state: State<any>) => inUnits(state, 1 / 8, step), \"bytes\")\n}\n\nconst readBits = (state: State<any>, count: number): number => {\n // SAFETY: bit-level parsers run inside `bits`, on the `Uint8Array` it was given (`BitInput` only re-indexes it in bits)\n const input = state.input as Uint8Array\n let pos = state.pos\n let value = 0\n let left = count\n // As many bits as the current byte holds at once, not one at a time\n while (left > 0) {\n const avail = 8 - (pos & 7)\n const n = left < avail ? left : avail\n // Multiplying, not shifting: the value can have up to 53 bits\n value = value * (1 << n) + ((input[pos >>> 3] >>> (avail - n)) & ((1 << n) - 1))\n pos += n\n left -= n\n }\n state.pos = pos\n return value\n}\n\n/**\n * Takes `count` bits (at most 53) as an unsigned number (winnow's and nom's\n * bit-level `take`).\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const take = (count: number): Parser<number, never, never, BitInput> => {\n checkCount(count)\n if (count > 53) throw new RangeError(\"Bits.take: use Bits.takeBig for more than 53 bits\")\n const expected = [`${count} bits`]\n return make((state: State<any>) => {\n const avail = state.end - state.pos\n if (avail < count) return state.eoi(\"Bits\", expected, count - avail)\n return readBits(state, count)\n }, \"take\")\n}\n\n/**\n * Takes `count` bits as an unsigned `bigint`.\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const takeBig = (count: number): Parser<bigint, never, never, BitInput> => {\n checkCount(count)\n const expected = [`${count} bits`]\n return make((state: State<any>) => {\n const avail = state.end - state.pos\n if (avail < count) return state.eoi(\"Bits\", expected, count - avail)\n let value = 0n\n let remaining = count\n while (remaining > 0) {\n const n = Math.min(remaining, 32)\n value = (value << BigInt(n)) | BigInt(readBits(state, n))\n remaining -= n\n }\n return value\n }, \"takeBig\")\n}\n\n/**\n * Matches `count` bits equal to `pattern` (winnow's `pattern`, nom's bit\n * `tag`).\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const pattern = (pattern: number, count: number): Parser<number, never, never, BitInput> => {\n checkCount(count)\n const expected = [`bit pattern ${pattern.toString(2).padStart(count, \"0\")}`]\n return make((state: State<any>) => {\n const start = state.pos\n const avail = state.end - start\n if (avail < count) return state.eoi(\"Bits\", expected, count - avail)\n const value = readBits(state, count)\n if (value !== pattern) {\n state.rewind(start)\n return state.backtrack(\"Bits\", expected)\n }\n return value\n }, \"pattern\")\n}\n\n/**\n * Takes one bit as a boolean (winnow's and nom's `bool`).\n *\n * @since 0.1.0\n * @category parsers\n */\nexport const bool: Parser<boolean, never, never, BitInput> = /*#__PURE__*/ make((state: State<any>) => {\n if (state.pos >= state.end) return state.eoi(\"Bits\", [\"1 bit\"], 1)\n return readBits(state, 1) === 1\n}, \"bool\")\n"],"mappings":";;;;AAyCA,MAAM,SAAS,GAAY,WACzB,IAAI,QACF,SAAS,IAA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IAAK,OAAO,SAAS,OAAO,CAAC,CAAC;GACxD,aAAa;EACf;EACA,OAAO;CACT,GAAG,SAAS;AACd;;;;;;;;AASA,MAAa,WAAW,SAAiB,UAA0D;CACjG,WAAW,KAAK;CAChB,MAAM,WAAW,CAAC,eAAe,QAAQ,SAAS,CAAC,CAAC,CAAC,SAAS,OAAO,GAAG,GAAG;CAC3E,OAAO,MAAM,UAAsB;EACjC,MAAM,QAAQ,MAAM;EACpB,MAAM,QAAQ,MAAM,MAAM;EAC1B,IAAI,QAAQ,OAAO,OAAO,MAAM,IAAI,QAAQ,UAAU,QAAQ,KAAK;EACnE,MAAM,QAAQ,SAAS,OAAO,KAAK;EACnC,IAAI,UAAU,SAAS;GACrB,MAAM,OAAO,KAAK;GAClB,OAAO,MAAM,UAAU,QAAQ,QAAQ;EACzC;EACA,OAAO;CACT,GAAG,SAAS;AACd;;;;;;;AAQA,MAAa,OAA8D,oBAAM,UAAsB;CACrG,IAAI,MAAM,OAAO,MAAM,KAAK,OAAO,MAAM,IAAI,QAAQ,CAAC,OAAO,GAAG,CAAC;CACjE,OAAO,SAAS,OAAO,CAAC,MAAM;AAChC,GAAG,MAAM"}
|
package/dist/Input.d.ts
CHANGED
|
@@ -228,6 +228,18 @@ export declare class State<I extends Input = Input> {
|
|
|
228
228
|
*/
|
|
229
229
|
get deepest(): Failure | undefined;
|
|
230
230
|
set deepest(failure: Failure | undefined);
|
|
231
|
+
/**
|
|
232
|
+
* Whether compiled code is running on this state. A compiled run that fails
|
|
233
|
+
* is thrown away (the interpreter runs again to build the error) and one
|
|
234
|
+
* that succeeds records no diagnostics, so interpreted steps called from it
|
|
235
|
+
* (an opaque `Parser.make`, a leaf near the end of a partial input) record
|
|
236
|
+
* a `Backtrack` or `Cut` failure's mode only, without building its
|
|
237
|
+
* {@link Failure} (#82). `Incomplete` failures are still built: a compiled
|
|
238
|
+
* run's `Incomplete` is reported as it stands.
|
|
239
|
+
*
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
242
|
+
compiledRun: boolean;
|
|
231
243
|
/** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */
|
|
232
244
|
recovered: Array<Failure> | undefined;
|
|
233
245
|
/** When defined, `Parser.trace` reports events here. */
|
|
@@ -256,8 +268,10 @@ export declare class State<I extends Input = Input> {
|
|
|
256
268
|
/**
|
|
257
269
|
* Where the stop characters of compiled `takeTill`s next occur in this
|
|
258
270
|
* state's input, by search site; created on first use. It lives as long
|
|
259
|
-
* as the state
|
|
260
|
-
* the
|
|
271
|
+
* as the state. `reset` keeps it for string input (a string never
|
|
272
|
+
* changes, and the positions are absolute, so they hold wherever the next
|
|
273
|
+
* run starts) and drops it for bytes and arrays, which a caller may
|
|
274
|
+
* refill in place between runs.
|
|
261
275
|
*
|
|
262
276
|
* @internal
|
|
263
277
|
*/
|
|
@@ -296,7 +310,11 @@ export declare class State<I extends Input = Input> {
|
|
|
296
310
|
*
|
|
297
311
|
* Every per-run field is reset: the cursor and end, the latest failure,
|
|
298
312
|
* hints and furthest failure, recorded recoveries, the tracer and tracing
|
|
299
|
-
* depth, the recorded encoding and streaming checkpoints.
|
|
313
|
+
* depth, the recorded encoding and streaming checkpoints. For string
|
|
314
|
+
* input, what the state has learnt about the string (where the stop
|
|
315
|
+
* characters of `takeTill` and the literals of `takeUntilAny` occur) is
|
|
316
|
+
* kept, as a string cannot change; for bytes and arrays it is dropped, so
|
|
317
|
+
* a buffer refilled in place between runs is searched afresh. Like the
|
|
300
318
|
* constructor, `partial` defaults to `false` and `context` to the empty
|
|
301
319
|
* context, so pass them again on every reset.
|
|
302
320
|
*
|
package/dist/Input.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.d.ts","names":["SyntaxBuilder"],"sources":["../src/Input.ts"],"mappings":";;;;;;;;;;;;;;;;YAkCY,iBAAiB,aAAa;;;;;;;;;;;;;YAc9B,cAAc,kBAAkB;;;;;;;;YAShC,OAAO,KAAK,MAAM,YAAY,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E,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;;;;;;;;EAwB3C,SAAS,MAAM,SAAS,MAAM,SAAS,MAAM,sBAAsB;;;;;EAenE,eAAe,SAAS;;;;;;EAUxB,mBAAmB;;;;;;EAwBnB,QAAQ,gBAAgB,UAAU;;EAWlC,YAAY,gBAAgB,MAAM,WAAW,UAAU,wBAAwB;;;qBAoBpE,gBAAiB,GAAG,uBAAuB,GAAG,0BAAwB;;;;;;;qBAqBtE,gBAAiB,GAAG,SAAS,GAAG,YAAU;;;;;;;;qBAa1C,oBAAqB,GAAG,SAAS,GAAG,SAAS,UAAU,0BAAwB"}
|
package/dist/Input.js
CHANGED
|
@@ -152,6 +152,18 @@ var State = class {
|
|
|
152
152
|
this.deepestIsLatest = false;
|
|
153
153
|
this.deepestFailure = failure;
|
|
154
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether compiled code is running on this state. A compiled run that fails
|
|
157
|
+
* is thrown away (the interpreter runs again to build the error) and one
|
|
158
|
+
* that succeeds records no diagnostics, so interpreted steps called from it
|
|
159
|
+
* (an opaque `Parser.make`, a leaf near the end of a partial input) record
|
|
160
|
+
* a `Backtrack` or `Cut` failure's mode only, without building its
|
|
161
|
+
* {@link Failure} (#82). `Incomplete` failures are still built: a compiled
|
|
162
|
+
* run's `Incomplete` is reported as it stands.
|
|
163
|
+
*
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
compiledRun = false;
|
|
155
167
|
/** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */
|
|
156
168
|
recovered = void 0;
|
|
157
169
|
/** When defined, `Parser.trace` reports events here. */
|
|
@@ -180,8 +192,10 @@ var State = class {
|
|
|
180
192
|
/**
|
|
181
193
|
* Where the stop characters of compiled `takeTill`s next occur in this
|
|
182
194
|
* state's input, by search site; created on first use. It lives as long
|
|
183
|
-
* as the state
|
|
184
|
-
* the
|
|
195
|
+
* as the state. `reset` keeps it for string input (a string never
|
|
196
|
+
* changes, and the positions are absolute, so they hold wherever the next
|
|
197
|
+
* run starts) and drops it for bytes and arrays, which a caller may
|
|
198
|
+
* refill in place between runs.
|
|
185
199
|
*
|
|
186
200
|
* @internal
|
|
187
201
|
*/
|
|
@@ -248,7 +262,11 @@ var State = class {
|
|
|
248
262
|
*
|
|
249
263
|
* Every per-run field is reset: the cursor and end, the latest failure,
|
|
250
264
|
* hints and furthest failure, recorded recoveries, the tracer and tracing
|
|
251
|
-
* depth, the recorded encoding and streaming checkpoints.
|
|
265
|
+
* depth, the recorded encoding and streaming checkpoints. For string
|
|
266
|
+
* input, what the state has learnt about the string (where the stop
|
|
267
|
+
* characters of `takeTill` and the literals of `takeUntilAny` occur) is
|
|
268
|
+
* kept, as a string cannot change; for bytes and arrays it is dropped, so
|
|
269
|
+
* a buffer refilled in place between runs is searched afresh. Like the
|
|
252
270
|
* constructor, `partial` defaults to `false` and `context` to the empty
|
|
253
271
|
* context, so pass them again on every reset.
|
|
254
272
|
*
|
|
@@ -281,12 +299,13 @@ var State = class {
|
|
|
281
299
|
this.hintExpected = empty;
|
|
282
300
|
this.deepestFailure = void 0;
|
|
283
301
|
this.deepestIsLatest = false;
|
|
302
|
+
this.compiledRun = false;
|
|
284
303
|
this.recovered = void 0;
|
|
285
304
|
this.tracer = void 0;
|
|
286
305
|
this.depth = 0;
|
|
287
306
|
this.encoding = void 0;
|
|
288
307
|
this.resume = void 0;
|
|
289
|
-
this.searches = void 0;
|
|
308
|
+
if (this.inputKind !== 0) this.searches = void 0;
|
|
290
309
|
this.asciiRun = void 0;
|
|
291
310
|
return this;
|
|
292
311
|
}
|
|
@@ -347,12 +366,20 @@ var State = class {
|
|
|
347
366
|
* Records a recoverable failure at the current offset and returns {@link Fail}.
|
|
348
367
|
*/
|
|
349
368
|
backtrack(kind, expected = empty, offset = this.pos) {
|
|
369
|
+
if (this.compiledRun) {
|
|
370
|
+
this.mode = "Backtrack";
|
|
371
|
+
return Fail;
|
|
372
|
+
}
|
|
350
373
|
return this.failWith("Backtrack", this.makeFailure(offset, kind, expected));
|
|
351
374
|
}
|
|
352
375
|
/**
|
|
353
376
|
* Records an unrecoverable failure at the current offset and returns {@link Fail}.
|
|
354
377
|
*/
|
|
355
378
|
cut(kind, expected = empty, offset = this.pos) {
|
|
379
|
+
if (this.compiledRun) {
|
|
380
|
+
this.mode = "Cut";
|
|
381
|
+
return Fail;
|
|
382
|
+
}
|
|
356
383
|
return this.failWith("Cut", this.makeFailure(offset, kind, expected));
|
|
357
384
|
}
|
|
358
385
|
/**
|
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 Arr from \"effect/Array\"\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\"\nimport type { AsciiRun } from \"./internal/text.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 * The overloads of {@link fromSource}.\n *\n * @since 0.5.0\n * @category constructors\n */\nexport interface FromSourceFn {\n (source: BinaryInput): Uint8Array\n <I extends Input>(source: Source<I>): I\n}\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: FromSourceFn = (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: Input | BinaryInput): 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 /**\n * The current offset. Parsers advance it by assigning it; moving it back\n * (backtracking, or after a lookahead) goes through {@link rewind}.\n */\n 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. A builder\n * rather than a subclass of `State`, so that every state has one shape.\n *\n * @internal\n */\n syntax: SyntaxBuilder | undefined = undefined\n /**\n * Where the stop characters of compiled `takeTill`s next occur in this\n * state's input, by search site; created on first use. It lives as long\n * as the state (whose input never changes), and `reset` clears it with\n * the other per-run fields.\n *\n * @internal\n */\n searches: Map<object, Array<number>> | undefined = undefined\n /**\n * A run of ASCII bytes of this state's UTF-8 input, decoded once, from\n * which `Text.utf8` slices the long strings it decodes (see\n * `internal/text.ts`); `reset` clears it with the other per-run fields.\n *\n * @internal\n */\n asciiRun: AsciiRun | undefined = undefined\n /**\n * A `DataView` of this state's byte input, for the `Binary` parsers;\n * created on first use. It lives as long as the state, whose input never\n * changes: one per read cost most of a number's time.\n *\n * @internal\n */\n view: DataView | 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<I>(source)\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 this.searches = undefined\n this.asciiRun = undefined\n return this\n }\n\n /**\n * Moves the cursor back to `offset`, abandoning what was parsed after it:\n * how a parser backtracks, or returns to where a lookahead started. A step\n * that moves the cursor backwards must use this rather than assigning\n * {@link pos}, so that a `Syntax` parse drops the nodes the abandoned\n * attempt built. Moving forward is an assignment.\n *\n * @example\n * ```ts\n * import { Input, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // Like `Parser.opt`, for one parser\n * const optional = <A>(p: Parser.Parser<A>) =>\n * Parser.make<A | undefined>((state) => {\n * const start = state.pos\n * const a = p.step(state)\n * if (a !== Input.Fail) return a\n * if (state.mode !== \"Backtrack\") return Input.Fail\n * state.rewind(start)\n * return undefined\n * })\n * ```\n *\n * @since 0.4.0\n */\n rewind(offset: number): void {\n const syntax = this.syntax\n if (syntax !== undefined && offset < this.pos) syntax.rewound(this.pos, offset)\n this.pos = offset\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 // SAFETY: `inputKind` 1 is a `Uint8Array`, whose `subarray` returns a\n // `Uint8Array` view (its `Slice`); 0 and 2 are a string and an array, whose\n // `slice` returns a string and an array of the same elements (their\n // `Slice`). `subarray` is only called for kind 1\n const input = this.input as {\n slice(start: number, end: number): Slice<I>\n subarray(start: number, end: number): Slice<I>\n } & I\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 if (this.syntax !== undefined) this.syntax.reach(failure.offset)\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 if (this.syntax !== undefined) this.syntax.reach(head.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 = Arr.isReadonlyArrayEmpty(d.context)\n ? f.context\n : [...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.syntax !== undefined) this.syntax.reach(offset)\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 && Arr.isReadonlyArrayNonEmpty(this.hintExpected)) {\n expected = mergeExpected(this.hintExpected, expected)\n }\n return new Failure(offset, kind, expected, empty, false, undefined, undefined, 0)\n }\n}\n\n/**\n * The last merges {@link mergeExpected} made, as `[a, b, merged]` triples. A\n * parse merges the same few pairs of expectation arrays over and over (a\n * whitespace skipper's hint with a repetition's, then with the failure of\n * the token after them), and expectation arrays are never mutated, so a\n * merge seen recently returns its earlier result, which in turn keeps the\n * next merge's input the same array.\n */\nconst merges: Array<ReadonlyArray<string>> = /*#__PURE__*/ new Array(12).fill(empty)\nlet mergeSlot = 0\n\n/** @internal */\nexport const mergeExpected = (a: ReadonlyArray<string>, b: ReadonlyArray<string>): ReadonlyArray<string> => {\n if (Arr.isReadonlyArrayEmpty(a)) return b\n if (Arr.isReadonlyArrayEmpty(b)) return a\n for (let i = 0; i < 12; i += 3) if (merges[i] === a && merges[i + 1] === b) return merges[i + 2]\n const out = a.slice()\n for (const e of b) {\n if (!out.includes(e)) out.push(e)\n }\n merges[mergeSlot] = a\n merges[mergeSlot + 1] = b\n merges[mergeSlot + 2] = out\n mergeSlot = mergeSlot === 9 ? 0 : mergeSlot + 3\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 Arr.isReadonlyArrayNonEmpty(b.context) ? 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,MAAa,cAA4B,WAAqC;CAC5E,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,UAEA,SAEA,UAEA,OAEA,SAEA,QACA;EAfS,KAAA,SAAA;EAEA,KAAA,OAAA;EAEA,KAAA,WAAA;EAEA,KAAA,UAAA;EAEA,KAAA,WAAA;EAEA,KAAA,QAAA;EAEA,KAAA,UAAA;EAEA,KAAA,SAAA;CACR;AACL;AAEA,MAAM,QAA+B,CAAC;;AAGtC,MAAM,+BAA+B,IAAI,QAAQ,GAAG,QAAQ,OAAO,OAAO,OAAO,KAAA,GAAW,KAAA,GAAW,CAAC;;AAGxG,MAAa,eAAe;;;;;;;AA0B5B,IAAa,QAAb,MAA4C;;CAE1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E,OAAO,IAAI,EAAE,UAAU,EAAE,SACvD,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 Arr from \"effect/Array\"\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\"\nimport type { AsciiRun } from \"./internal/text.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 * The overloads of {@link fromSource}.\n *\n * @since 0.5.0\n * @category constructors\n */\nexport interface FromSourceFn {\n (source: BinaryInput): Uint8Array\n <I extends Input>(source: Source<I>): I\n}\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: FromSourceFn = (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: Input | BinaryInput): 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 /**\n * The current offset. Parsers advance it by assigning it; moving it back\n * (backtracking, or after a lookahead) goes through {@link rewind}.\n */\n 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 /**\n * Whether compiled code is running on this state. A compiled run that fails\n * is thrown away (the interpreter runs again to build the error) and one\n * that succeeds records no diagnostics, so interpreted steps called from it\n * (an opaque `Parser.make`, a leaf near the end of a partial input) record\n * a `Backtrack` or `Cut` failure's mode only, without building its\n * {@link Failure} (#82). `Incomplete` failures are still built: a compiled\n * run's `Incomplete` is reported as it stands.\n *\n * @internal\n */\n compiledRun = false\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. A builder\n * rather than a subclass of `State`, so that every state has one shape.\n *\n * @internal\n */\n syntax: SyntaxBuilder | undefined = undefined\n /**\n * Where the stop characters of compiled `takeTill`s next occur in this\n * state's input, by search site; created on first use. It lives as long\n * as the state. `reset` keeps it for string input (a string never\n * changes, and the positions are absolute, so they hold wherever the next\n * run starts) and drops it for bytes and arrays, which a caller may\n * refill in place between runs.\n *\n * @internal\n */\n searches: Map<object, Array<number>> | undefined = undefined\n /**\n * A run of ASCII bytes of this state's UTF-8 input, decoded once, from\n * which `Text.utf8` slices the long strings it decodes (see\n * `internal/text.ts`); `reset` clears it with the other per-run fields.\n *\n * @internal\n */\n asciiRun: AsciiRun | undefined = undefined\n /**\n * A `DataView` of this state's byte input, for the `Binary` parsers;\n * created on first use. It lives as long as the state, whose input never\n * changes: one per read cost most of a number's time.\n *\n * @internal\n */\n view: DataView | 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<I>(source)\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. For string\n * input, what the state has learnt about the string (where the stop\n * characters of `takeTill` and the literals of `takeUntilAny` occur) is\n * kept, as a string cannot change; for bytes and arrays it is dropped, so\n * a buffer refilled in place between runs is searched afresh. 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.compiledRun = false\n this.recovered = undefined\n this.tracer = undefined\n this.depth = 0\n this.encoding = undefined\n this.resume = undefined\n // For a string, `searches` is kept: it remembers where stop characters\n // and literals occur by absolute position, and a string never changes,\n // so it holds at any offset. A lexer that resets before each token\n // otherwise searched to the end of the buffer again for every token\n // (#126). Bytes and arrays can be refilled in place between runs (a\n // `Uint8Array` source is viewed, not copied), so theirs is dropped.\n if (this.inputKind !== 0) this.searches = undefined\n this.asciiRun = undefined\n return this\n }\n\n /**\n * Moves the cursor back to `offset`, abandoning what was parsed after it:\n * how a parser backtracks, or returns to where a lookahead started. A step\n * that moves the cursor backwards must use this rather than assigning\n * {@link pos}, so that a `Syntax` parse drops the nodes the abandoned\n * attempt built. Moving forward is an assignment.\n *\n * @example\n * ```ts\n * import { Input, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // Like `Parser.opt`, for one parser\n * const optional = <A>(p: Parser.Parser<A>) =>\n * Parser.make<A | undefined>((state) => {\n * const start = state.pos\n * const a = p.step(state)\n * if (a !== Input.Fail) return a\n * if (state.mode !== \"Backtrack\") return Input.Fail\n * state.rewind(start)\n * return undefined\n * })\n * ```\n *\n * @since 0.4.0\n */\n rewind(offset: number): void {\n const syntax = this.syntax\n if (syntax !== undefined && offset < this.pos) syntax.rewound(this.pos, offset)\n this.pos = offset\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 // SAFETY: `inputKind` 1 is a `Uint8Array`, whose `subarray` returns a\n // `Uint8Array` view (its `Slice`); 0 and 2 are a string and an array, whose\n // `slice` returns a string and an array of the same elements (their\n // `Slice`). `subarray` is only called for kind 1\n const input = this.input as {\n slice(start: number, end: number): Slice<I>\n subarray(start: number, end: number): Slice<I>\n } & I\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 if (this.compiledRun) {\n this.mode = \"Backtrack\"\n return Fail\n }\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 if (this.compiledRun) {\n this.mode = \"Cut\"\n return Fail\n }\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 if (this.syntax !== undefined) this.syntax.reach(failure.offset)\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 if (this.syntax !== undefined) this.syntax.reach(head.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 = Arr.isReadonlyArrayEmpty(d.context)\n ? f.context\n : [...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.syntax !== undefined) this.syntax.reach(offset)\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 && Arr.isReadonlyArrayNonEmpty(this.hintExpected)) {\n expected = mergeExpected(this.hintExpected, expected)\n }\n return new Failure(offset, kind, expected, empty, false, undefined, undefined, 0)\n }\n}\n\n/**\n * The last merges {@link mergeExpected} made, as `[a, b, merged]` triples. A\n * parse merges the same few pairs of expectation arrays over and over (a\n * whitespace skipper's hint with a repetition's, then with the failure of\n * the token after them), and expectation arrays are never mutated, so a\n * merge seen recently returns its earlier result, which in turn keeps the\n * next merge's input the same array.\n */\nconst merges: Array<ReadonlyArray<string>> = /*#__PURE__*/ new Array(12).fill(empty)\nlet mergeSlot = 0\n\n/** @internal */\nexport const mergeExpected = (a: ReadonlyArray<string>, b: ReadonlyArray<string>): ReadonlyArray<string> => {\n if (Arr.isReadonlyArrayEmpty(a)) return b\n if (Arr.isReadonlyArrayEmpty(b)) return a\n for (let i = 0; i < 12; i += 3) if (merges[i] === a && merges[i + 1] === b) return merges[i + 2]\n const out = a.slice()\n for (const e of b) {\n if (!out.includes(e)) out.push(e)\n }\n merges[mergeSlot] = a\n merges[mergeSlot + 1] = b\n merges[mergeSlot + 2] = out\n mergeSlot = mergeSlot === 9 ? 0 : mergeSlot + 3\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 Arr.isReadonlyArrayNonEmpty(b.context) ? 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,MAAa,cAA4B,WAAqC;CAC5E,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,UAEA,SAEA,UAEA,OAEA,SAEA,QACA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