@thomasfosterau/effect-parse 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +202 -0
- package/README.md +56 -14
- package/dist/Ascii.d.ts +11 -4
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +12 -4
- 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 +83 -37
- package/dist/Binary.js.map +1 -1
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +11 -4
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +74 -2
- package/dist/Compiler.d.ts.map +1 -1
- package/dist/Compiler.js +78 -1
- package/dist/Compiler.js.map +1 -1
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +86 -74
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +56 -5
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +70 -1
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +5 -15
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js.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 +375 -29
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +394 -37
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +2 -3
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +122 -14
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +293 -62
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +23 -5
- package/dist/Syntax.d.ts.map +1 -1
- package/dist/Syntax.js +1 -1
- package/dist/Syntax.js.map +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +21 -15
- package/dist/Text.js.map +1 -1
- package/dist/Token.d.ts +65 -11
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +73 -26
- 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 +263 -113
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +3 -1
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +3 -2
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +9 -2
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/graph.d.ts +39 -0
- package/dist/internal/compiler/graph.d.ts.map +1 -0
- package/dist/internal/compiler/graph.js +78 -0
- package/dist/internal/compiler/graph.js.map +1 -0
- package/dist/internal/compiler/jit.d.ts +5 -0
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +208 -106
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +11 -3
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js.map +1 -1
- package/dist/internal/compiler/search.d.ts +32 -0
- package/dist/internal/compiler/search.d.ts.map +1 -0
- package/dist/internal/compiler/search.js +68 -0
- package/dist/internal/compiler/search.js.map +1 -0
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +1 -1
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/compiler/wasm.d.ts +8 -0
- package/dist/internal/compiler/wasm.d.ts.map +1 -0
- package/dist/internal/compiler/wasm.js +2840 -0
- package/dist/internal/compiler/wasm.js.map +1 -0
- package/dist/internal/compiler/wasmAsm.d.ts +199 -0
- package/dist/internal/compiler/wasmAsm.d.ts.map +1 -0
- package/dist/internal/compiler/wasmAsm.js +427 -0
- package/dist/internal/compiler/wasmAsm.js.map +1 -0
- package/dist/internal/entries.d.ts +3 -1
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js.map +1 -1
- package/dist/internal/node.d.ts +77 -3
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +54 -10
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js.map +1 -1
- package/dist/internal/run.d.ts +14 -0
- package/dist/internal/run.d.ts.map +1 -1
- package/dist/internal/run.js +53 -11
- package/dist/internal/run.js.map +1 -1
- package/dist/internal/stack.d.ts +14 -0
- package/dist/internal/stack.d.ts.map +1 -1
- package/dist/internal/stack.js +24 -2
- package/dist/internal/stack.js.map +1 -1
- package/dist/internal/syntax.d.ts +4 -4
- package/dist/internal/syntax.d.ts.map +1 -1
- package/dist/internal/syntax.js +18 -10
- package/dist/internal/syntax.js.map +1 -1
- package/dist/internal/text.d.ts +32 -0
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +68 -14
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/tokens.d.ts +20 -0
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +72 -39
- 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 +18 -10
- package/src/Ascii.ts +47 -12
- package/src/Binary.ts +174 -73
- package/src/Bits.ts +16 -6
- package/src/Compiler.ts +101 -10
- package/src/Expression.ts +94 -81
- package/src/Input.ts +99 -7
- package/src/Nom.ts +15 -5
- package/src/ParseError.ts +209 -52
- package/src/Parser.ts +684 -143
- package/src/ParserSchema.ts +1 -2
- package/src/ParserStream.ts +361 -68
- package/src/Syntax.ts +60 -36
- package/src/Text.ts +32 -27
- package/src/Token.ts +152 -34
- package/src/internal/compiler/closure.ts +371 -153
- package/src/internal/compiler/entries.ts +4 -2
- package/src/internal/compiler/first.ts +16 -0
- package/src/internal/compiler/graph.ts +96 -0
- package/src/internal/compiler/jit.ts +319 -169
- package/src/internal/compiler/registry.ts +10 -2
- package/src/internal/compiler/search.ts +68 -0
- package/src/internal/compiler/sets.ts +7 -3
- package/src/internal/compiler/wasm.ts +3276 -0
- package/src/internal/compiler/wasmAsm.ts +484 -0
- package/src/internal/entries.ts +8 -2
- package/src/internal/node.ts +103 -7
- package/src/internal/numbers.ts +3 -1
- package/src/internal/run.ts +73 -12
- package/src/internal/stack.ts +25 -1
- package/src/internal/syntax.ts +39 -18
- package/src/internal/text.ts +97 -9
- package/src/internal/tokens.ts +106 -14
- package/src/internal/tuple.ts +141 -0
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. */
|
|
@@ -177,6 +189,33 @@ var State = class {
|
|
|
177
189
|
* @internal
|
|
178
190
|
*/
|
|
179
191
|
syntax = void 0;
|
|
192
|
+
/**
|
|
193
|
+
* Where the stop characters of compiled `takeTill`s next occur in this
|
|
194
|
+
* state's input, by search site; created on first use. It lives as long
|
|
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.
|
|
199
|
+
*
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
searches = void 0;
|
|
203
|
+
/**
|
|
204
|
+
* A run of ASCII bytes of this state's UTF-8 input, decoded once, from
|
|
205
|
+
* which `Text.utf8` slices the long strings it decodes (see
|
|
206
|
+
* `internal/text.ts`); `reset` clears it with the other per-run fields.
|
|
207
|
+
*
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
210
|
+
asciiRun = void 0;
|
|
211
|
+
/**
|
|
212
|
+
* A `DataView` of this state's byte input, for the `Binary` parsers;
|
|
213
|
+
* created on first use. It lives as long as the state, whose input never
|
|
214
|
+
* changes: one per read cost most of a number's time.
|
|
215
|
+
*
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
view = void 0;
|
|
180
219
|
constructor(source, options) {
|
|
181
220
|
const input = fromSource(source);
|
|
182
221
|
this.input = input;
|
|
@@ -223,7 +262,11 @@ var State = class {
|
|
|
223
262
|
*
|
|
224
263
|
* Every per-run field is reset: the cursor and end, the latest failure,
|
|
225
264
|
* hints and furthest failure, recorded recoveries, the tracer and tracing
|
|
226
|
-
* 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
|
|
227
270
|
* constructor, `partial` defaults to `false` and `context` to the empty
|
|
228
271
|
* context, so pass them again on every reset.
|
|
229
272
|
*
|
|
@@ -256,11 +299,14 @@ var State = class {
|
|
|
256
299
|
this.hintExpected = empty;
|
|
257
300
|
this.deepestFailure = void 0;
|
|
258
301
|
this.deepestIsLatest = false;
|
|
302
|
+
this.compiledRun = false;
|
|
259
303
|
this.recovered = void 0;
|
|
260
304
|
this.tracer = void 0;
|
|
261
305
|
this.depth = 0;
|
|
262
306
|
this.encoding = void 0;
|
|
263
307
|
this.resume = void 0;
|
|
308
|
+
if (this.inputKind !== 0) this.searches = void 0;
|
|
309
|
+
this.asciiRun = void 0;
|
|
264
310
|
return this;
|
|
265
311
|
}
|
|
266
312
|
/**
|
|
@@ -320,12 +366,20 @@ var State = class {
|
|
|
320
366
|
* Records a recoverable failure at the current offset and returns {@link Fail}.
|
|
321
367
|
*/
|
|
322
368
|
backtrack(kind, expected = empty, offset = this.pos) {
|
|
369
|
+
if (this.compiledRun) {
|
|
370
|
+
this.mode = "Backtrack";
|
|
371
|
+
return Fail;
|
|
372
|
+
}
|
|
323
373
|
return this.failWith("Backtrack", this.makeFailure(offset, kind, expected));
|
|
324
374
|
}
|
|
325
375
|
/**
|
|
326
376
|
* Records an unrecoverable failure at the current offset and returns {@link Fail}.
|
|
327
377
|
*/
|
|
328
378
|
cut(kind, expected = empty, offset = this.pos) {
|
|
379
|
+
if (this.compiledRun) {
|
|
380
|
+
this.mode = "Cut";
|
|
381
|
+
return Fail;
|
|
382
|
+
}
|
|
329
383
|
return this.failWith("Cut", this.makeFailure(offset, kind, expected));
|
|
330
384
|
}
|
|
331
385
|
/**
|
|
@@ -426,12 +480,27 @@ var State = class {
|
|
|
426
480
|
return new Failure(offset, kind, expected, empty, false, void 0, void 0, 0);
|
|
427
481
|
}
|
|
428
482
|
};
|
|
483
|
+
/**
|
|
484
|
+
* The last merges {@link mergeExpected} made, as `[a, b, merged]` triples. A
|
|
485
|
+
* parse merges the same few pairs of expectation arrays over and over (a
|
|
486
|
+
* whitespace skipper's hint with a repetition's, then with the failure of
|
|
487
|
+
* the token after them), and expectation arrays are never mutated, so a
|
|
488
|
+
* merge seen recently returns its earlier result, which in turn keeps the
|
|
489
|
+
* next merge's input the same array.
|
|
490
|
+
*/
|
|
491
|
+
const merges = /*#__PURE__*/ new Array(12).fill(empty);
|
|
492
|
+
let mergeSlot = 0;
|
|
429
493
|
/** @internal */
|
|
430
494
|
const mergeExpected = (a, b) => {
|
|
431
495
|
if (Arr.isReadonlyArrayEmpty(a)) return b;
|
|
432
496
|
if (Arr.isReadonlyArrayEmpty(b)) return a;
|
|
497
|
+
for (let i = 0; i < 12; i += 3) if (merges[i] === a && merges[i + 1] === b) return merges[i + 2];
|
|
433
498
|
const out = a.slice();
|
|
434
499
|
for (const e of b) if (!out.includes(e)) out.push(e);
|
|
500
|
+
merges[mergeSlot] = a;
|
|
501
|
+
merges[mergeSlot + 1] = b;
|
|
502
|
+
merges[mergeSlot + 2] = out;
|
|
503
|
+
mergeSlot = mergeSlot === 9 ? 0 : mergeSlot + 3;
|
|
435
504
|
return out;
|
|
436
505
|
};
|
|
437
506
|
/**
|
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\"\n\n/**\n * The kinds of input a parser can consume.\n *\n * - `string`: tokens are Unicode code points (returned as strings), offsets\n * are UTF-16 code-unit indices.\n * - `Uint8Array`: tokens are bytes (numbers), slices are `subarray` views.\n * - `ReadonlyArray<T>`: tokens are elements, e.g. the output of a lexer.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Input = string | Uint8Array | ReadonlyArray<unknown>\n\n/**\n * Binary data that can be passed wherever a `Uint8Array` input is expected:\n * an `ArrayBuffer`, a `SharedArrayBuffer`, a `DataView` or any typed array.\n *\n * It is viewed, not copied, as a `Uint8Array` of its bytes. A typed array\n * with wider elements is viewed in the platform's byte order, which is\n * little endian on all common platforms, so a `Uint16Array` of UTF-16 code\n * units can be parsed with `Text.utf16le`.\n *\n * @since 0.1.0\n * @category models\n */\nexport type BinaryInput = ArrayBufferLike | ArrayBufferView\n\n/**\n * What the runners accept for a parser over `I`: the input itself, or, for\n * byte parsers, any {@link BinaryInput}.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never)\n\n/**\n * Converts a {@link Source} to the input parsers read: binary data becomes a\n * `Uint8Array` view of the same memory, everything else is returned as is.\n *\n * @example\n * ```ts\n * import { Input } from \"@thomasfosterau/effect-parse\"\n *\n * Input.fromSource(new Uint16Array([0x41]).buffer) // Uint8Array [0x41, 0x00]\n * ```\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const fromSource: {\n (source: BinaryInput): Uint8Array\n <I extends Input>(source: Source<I>): I\n} = (source: Input | BinaryInput): any => {\n if (Predicate.isString(source) || source instanceof Uint8Array || Array.isArray(source)) return source\n if (ArrayBuffer.isView(source)) return new Uint8Array(source.buffer, source.byteOffset, source.byteLength)\n // An explicit length fixes the view's size even for a resizable buffer\n if (isArrayBufferLike(source)) return new Uint8Array(source, 0, source.byteLength)\n return source\n}\n\nconst isArrayBufferLike = (u: 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 constructor(\n source: I | Source<I>,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n readonly offset?: number | undefined\n }\n ) {\n const input = fromSource(source as Input) as I\n this.input = input\n this.end = input.length\n this.pos = options?.offset ?? 0\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.inputKind = Predicate.isString(input) ? 0 : input instanceof Uint8Array ? 1 : 2\n this.failureHead = initialFailure\n }\n\n /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */\n get failure(): Failure {\n if (this.failureTie1 !== undefined) this.settleFailure()\n return this.failureHead\n }\n set failure(failure: Failure) {\n if (this.deepestIsLatest) this.settleFailure()\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n\n /** Merges the latest failure's ties into it (see {@link failureHead}). */\n private settleFailure(): void {\n let failure = this.failureHead\n const tie1 = this.failureTie1\n if (tie1 !== undefined) {\n failure = mergeTiedFailures(failure, tie1, mergeExpected(failure.expected, tie1.expected))\n const tie2 = this.failureTie2\n if (tie2 !== undefined) failure = mergeTiedFailures(failure, tie2, mergeExpected(failure.expected, tie2.expected))\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n if (this.deepestIsLatest) {\n this.deepestFailure = failure\n this.deepestIsLatest = false\n }\n }\n\n /**\n * Prepares the state for another run over the same input, starting at\n * `offset`: afterwards it behaves exactly like\n * `new State(state.input, { ...options, offset })`, without allocating a\n * new state.\n *\n * Every per-run field is reset: the cursor and end, the latest failure,\n * hints and furthest failure, recorded recoveries, the tracer and tracing\n * depth, the recorded encoding and streaming checkpoints. Like the\n * constructor, `partial` defaults to `false` and `context` to the empty\n * context, so pass them again on every reset.\n *\n * Use it to run many small parses over one buffer, for example one per\n * token, with `parser.step`. A state can be reused after any run,\n * including one that failed, returned `Incomplete` or threw.\n *\n * @example\n * ```ts\n * import { Ascii, Input } from \"@thomasfosterau/effect-parse\"\n *\n * const state = new Input.State(\"12 34\")\n * Ascii.decUint.step(state) // 12\n * state.reset(3)\n * Ascii.decUint.step(state) // 34\n * ```\n *\n * @since 0.2.0\n */\n reset(\n offset: number = 0,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n }\n ): this {\n this.pos = offset\n this.end = this.input.length\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.mode = \"Backtrack\"\n this.failureHead = initialFailure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n this.hintOffset = -1\n this.hintExpected = empty\n this.deepestFailure = undefined\n this.deepestIsLatest = false\n this.recovered = undefined\n this.tracer = undefined\n this.depth = 0\n this.encoding = undefined\n this.resume = undefined\n return this\n }\n\n /**\n * 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 const input = this.input as any\n switch (this.inputKind) {\n case 0:\n return input.slice(start, end)\n case 1:\n return input.subarray(start, end)\n default:\n return input.slice(start, end)\n }\n }\n\n /**\n * Records a recoverable failure at the current offset and returns {@link Fail}.\n */\n backtrack(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Backtrack\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an unrecoverable failure at the current offset and returns {@link Fail}.\n */\n cut(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Cut\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an `Incomplete` failure (only meaningful for partial input) and\n * returns {@link Fail}.\n */\n incomplete(needed: number, expected: ReadonlyArray<string> = empty): Fail {\n return this.failWith(\n \"Incomplete\",\n new Failure(this.pos, \"Incomplete\", expected, empty, false, undefined, undefined, needed)\n )\n }\n\n /**\n * Fails because the input ended: `Incomplete` for partial input, otherwise\n * a `Backtrack` failure of the given kind.\n */\n eoi(kind: ErrorKind, expected: ReadonlyArray<string>, needed: number): Fail {\n return this.partial ? this.incomplete(needed, expected) : this.backtrack(kind, expected)\n }\n\n /**\n * Records a failure carrying a user supplied cause.\n */\n failCause(mode: ErrMode, kind: ErrorKind, cause: unknown, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, true, cause, undefined, 0))\n }\n\n /**\n * Records a failure carrying a message.\n */\n failMessage(mode: ErrMode, kind: ErrorKind, message: string, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, false, undefined, message, 0))\n }\n\n /**\n * Records the given failure and returns {@link Fail}.\n */\n failWith(mode: ErrMode, failure: Failure): Fail {\n this.mode = mode\n if (this.deepestIsLatest) {\n // The furthest failure is the latest one: it is replaced below, unmerged, if `failure` is as far\n if (mode === \"Backtrack\" && failure.offset >= this.failureHead.offset) this.deepestIsLatest = false\n else this.settleFailure()\n }\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n if (mode === \"Backtrack\" && (this.deepestFailure === undefined || failure.offset >= this.deepestFailure.offset)) {\n this.deepestFailure = failure\n }\n 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/** @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 const out = a.slice()\n for (const e of b) {\n if (!out.includes(e)) out.push(e)\n }\n return out\n}\n\n/**\n * Combines the failures of two alternatives: the furthest failure wins, and\n * failures at the same offset have their expectations merged.\n *\n * @internal\n */\nexport const mergeFailures = (a: Failure, b: Failure): Failure => {\n if (a.offset > b.offset) return a\n if (b.offset > a.offset) return b\n return mergeTiedFailures(a, b, mergeExpected(a.expected, b.expected))\n}\n\n/**\n * {@link mergeFailures} for two failures at the same offset, given their\n * merged expectations (`mergeExpected(a.expected, b.expected)`, possibly\n * memoised by the caller).\n *\n * @internal\n */\nexport const mergeTiedFailures = (a: Failure, b: Failure, expected: ReadonlyArray<string>): Failure => {\n if (expected === b.expected) return b\n return new Failure(\n b.offset,\n b.kind,\n expected,\n 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAa,cAGR,WAAqC;CACxC,IAAI,UAAU,SAAS,MAAM,KAAK,kBAAkB,cAAc,MAAM,QAAQ,MAAM,GAAG,OAAO;CAChG,IAAI,YAAY,OAAO,MAAM,GAAG,OAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;CAEzG,IAAI,kBAAkB,MAAM,GAAG,OAAO,IAAI,WAAW,QAAQ,GAAG,OAAO,UAAU;CACjF,OAAO;AACT;AAEA,MAAM,qBAAqB,MACzB,aAAa,eAAgB,WAAW,sBAAsB,KAAA,KAAa,aAAa;;;;;;;;AAqC1F,MAAa,OAAoC,qBAAO,IAAI,mBAAmB;;;;;;;AA0B/E,IAAa,UAAb,MAAqB;CAGR;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAhBX,YAEE,QAEA,MAEA,UAEA,SAEA,UAEA,OAEA,SAEA,QACA;EAfS,KAAA,SAAA;EAEA,KAAA,OAAA;EAEA,KAAA,WAAA;EAEA,KAAA,UAAA;EAEA,KAAA,WAAA;EAEA,KAAA,QAAA;EA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{@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;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,Q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E,IAAI,EAAE,SAAS,EAAE,QAAQ,OAAO;CAChC,IAAI,EAAE,SAAS,EAAE,QAAQ,OAAO;CAChC,OAAO,kBAAkB,GAAG,GAAG,cAAc,EAAE,UAAU,EAAE,QAAQ,CAAC;AACtE;;;;;;;;AASA,MAAa,qBAAqB,GAAY,GAAY,aAA6C;CACrG,IAAI,aAAa,EAAE,UAAU,OAAO;CACpC,OAAO,IAAI,QACT,EAAE,QACF,EAAE,MACF,UACA,IAAI,wBAAwB,EAAE,OAAO,IAAI,EAAE,UAAU,EAAE,SACvD,EAAE,YAAY,EAAE,UAChB,EAAE,WAAW,EAAE,QAAQ,EAAE,OACzB,EAAE,WAAW,EAAE,SACf,EAAE,MACJ;AACF"}
|
package/dist/Nom.d.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import * as Result from "effect/Result";
|
|
2
2
|
import { Input, Slice, Token } from "./Input.js";
|
|
3
|
-
import * as P from "./Parser.js";
|
|
4
3
|
import { Parser } from "./Parser.js";
|
|
4
|
+
import * as Token$1 from "./Token.js";
|
|
5
5
|
import { TokenSet } from "./Token.js";
|
|
6
6
|
import * as Option from "effect/Option";
|
|
7
|
+
import * as Ascii from "./Ascii.js";
|
|
7
8
|
/**
|
|
8
9
|
* Matches a literal (nom's `tag`).
|
|
9
10
|
*
|
|
10
11
|
* @since 0.1.0
|
|
11
12
|
* @category bytes
|
|
12
13
|
*/
|
|
13
|
-
export declare const tag:
|
|
14
|
-
<const L extends string>(literal: L): Parser<L, never, never, string>;
|
|
15
|
-
(literal: Uint8Array): Parser<Uint8Array, never, never, Uint8Array>;
|
|
16
|
-
<const T>(literal: ReadonlyArray<T>): Parser<ReadonlyArray<T>, never, never, ReadonlyArray<T>>;
|
|
17
|
-
};
|
|
14
|
+
export declare const tag: Token$1.LiteralFn;
|
|
18
15
|
/**
|
|
19
16
|
* Matches a literal, ignoring ASCII case (nom's `tag_no_case`).
|
|
20
17
|
*
|
|
21
18
|
* @since 0.1.0
|
|
22
19
|
* @category bytes
|
|
23
20
|
*/
|
|
24
|
-
export declare const tagNoCase:
|
|
25
|
-
(literal: string): Parser<string>;
|
|
26
|
-
(literal: Uint8Array): Parser<Uint8Array, never, never, Uint8Array>;
|
|
27
|
-
};
|
|
21
|
+
export declare const tagNoCase: Ascii.CaselessFn;
|
|
28
22
|
/**
|
|
29
23
|
* Matches a single character (nom's `char`).
|
|
30
24
|
*
|
|
@@ -102,11 +96,7 @@ export declare const takeTill1: <I extends Input = string>(predicate: (token: To
|
|
|
102
96
|
* @since 0.1.0
|
|
103
97
|
* @category bytes
|
|
104
98
|
*/
|
|
105
|
-
export declare const takeUntil:
|
|
106
|
-
(literal: string, range?: P.Range): Parser<string, never, never, string>;
|
|
107
|
-
(literal: Uint8Array, range?: P.Range): Parser<Uint8Array, never, never, Uint8Array>;
|
|
108
|
-
<T>(literal: ReadonlyArray<T>, range?: P.Range): Parser<ReadonlyArray<T>, never, never, ReadonlyArray<T>>;
|
|
109
|
-
};
|
|
99
|
+
export declare const takeUntil: Token$1.TakeUntilFn;
|
|
110
100
|
/**
|
|
111
101
|
* Recognizes an escaped string (nom's `escaped`).
|
|
112
102
|
*
|
package/dist/Nom.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Nom.d.ts","names":["TokenOf"],"sources":["../src/Nom.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Nom.d.ts","names":["Token","TokenOf"],"sources":["../src/Nom.ts"],"mappings":";;;;;;;;;;;;;qBA2Da,KAAGA,QAAA;;;;;;;qBAQH,WAAS,MAAA;;;;;;;qBAQT,aAAc,kBAAkB,GAAG,MAAI,OAAO;;;;;;;qBAQ9C,SAAS;;;;;qBAMT,QAAK,UAAA,gBAAA,KAAA,SAAA,OAAA,OAAAC,MAAA,QAAA,mBAAA,QAAA;;;;;qBAML,SAAM,UAAA,gBAAA,KAAA,SAAA,OAAA,OAAAA,MAAA,QAAA,mBAAA,QAAA;;;;;qBAMN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n *\n * effect-parse's main API follows winnow's naming (in camelCase). This module\n * offers the names, and argument orders, that nom users know, so grammars\n * can be ported with minimal changes:\n *\n * | nom | effect-parse |\n * |---|---|\n * | `tag(\"abc\")` | `Token.literal(\"abc\")` |\n * | `many0(p)` | `Parser.repeat(p)` |\n * | `separated_list1(sep, p)` | `Parser.separated(p, sep, { min: 1 })` |\n * | `map_res(p, f)` | `Parser.tryMap(p, f)` |\n * | `recognize(p)` | `Parser.taken(p)` |\n * | `value(v, p)` | `Parser.as(p, v)` |\n *\n * nom's `streaming` and `complete` variants are not separate functions here.\n * Whether input is partial is decided by the runner (`Parser.parsePartial`\n * vs `Parser.parse`).\n *\n * @example\n * ```ts\n * import { Result } from \"effect\"\n * import { Nom, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * const hexPrimary = Nom.mapRes(\n * Nom.takeWhileMN(2, 2, (c: string) => /[0-9a-fA-F]/.test(c)),\n * (s) => Result.succeed(parseInt(s, 16))\n * )\n * const hexColor = Nom.preceded(\n * Nom.tag(\"#\"),\n * Nom.tuple(hexPrimary, hexPrimary, hexPrimary)\n * )\n *\n * Parser.parse(hexColor, \"#2F14DF\") // Result.succeed([47, 20, 223])\n * ```\n *\n * @since 0.1.0\n */\nimport * as Option from \"effect/Option\"\nimport * as Result from \"effect/Result\"\nimport * as Ascii from \"./Ascii.js\"\nimport * as Binary from \"./Binary.js\"\nimport type { Input, Slice, Token as TokenOf } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\nimport type { TokenSet } from \"./Token.js\"\n\n// -----------------------------------------------------------------------------\n// bytes / character\n// -----------------------------------------------------------------------------\n\n/**\n * Matches a literal (nom's `tag`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tag = Token.literal\n\n/**\n * Matches a literal, ignoring ASCII case (nom's `tag_no_case`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tagNoCase = Ascii.caseless\n\n/**\n * Matches a single character (nom's `char`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const char = <const C extends string>(c: C): Parser<C> => Token.literal(c)\n\n/**\n * Matches any character (nom's `anychar`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const anychar: Parser<string> = Token.any\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const oneOf = Token.oneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const noneOf = Token.noneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const satisfy = Token.satisfy\n\n/**\n * The longest non-empty run of tokens from a set (nom's `is_a`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isA = <I extends Input = string>(set: TokenSet<I>): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n Token.takeWhile<I>(set, { min: 1 })\n\n/**\n * The longest non-empty run of tokens *not* from a set (nom's `is_not`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isNot = <I extends Input = string>(\n set: TokenSet<I>\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(set, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const take = Token.take\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeWhile<I>(predicate as any)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeWhile<I>(predicate as any, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhileMN = <I extends Input = string>(\n m: number,\n n: number,\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeWhile<I>(predicate as any, { min: m, max: n })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(predicate as any)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(predicate as any, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeUntil = Token.takeUntil\n\n/**\n * Recognizes an escaped string (nom's `escaped`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escaped = Ascii.takeEscaped\n\n/**\n * Unescapes an escaped string (nom's `escaped_transform`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escapedTransform = Ascii.escaped\n\n/** @since 0.1.0 @category character */\nexport const alpha0 = Ascii.alpha0\n/** @since 0.1.0 @category character */\nexport const alpha1 = Ascii.alpha1\n/** @since 0.1.0 @category character */\nexport const digit0 = Ascii.digit0\n/** @since 0.1.0 @category character */\nexport const digit1 = Ascii.digit1\n/** @since 0.1.0 @category character */\nexport const hexDigit0 = Ascii.hexDigit0\n/** @since 0.1.0 @category character */\nexport const hexDigit1 = Ascii.hexDigit1\n/** @since 0.1.0 @category character */\nexport const octDigit0 = Ascii.octDigit0\n/** @since 0.1.0 @category character */\nexport const octDigit1 = Ascii.octDigit1\n/** @since 0.1.0 @category character */\nexport const alphanumeric0 = Ascii.alphanumeric0\n/** @since 0.1.0 @category character */\nexport const alphanumeric1 = Ascii.alphanumeric1\n/** @since 0.1.0 @category character */\nexport const space0 = Ascii.space0\n/** @since 0.1.0 @category character */\nexport const space1 = Ascii.space1\n/** @since 0.1.0 @category character */\nexport const multispace0 = Ascii.multispace0\n/** @since 0.1.0 @category character */\nexport const multispace1 = Ascii.multispace1\n/** @since 0.1.0 @category character */\nexport const lineEnding = Ascii.lineEnding\n/** @since 0.1.0 @category character */\nexport const newline = Ascii.newline\n/** @since 0.1.0 @category character */\nexport const tab = Ascii.tab\n/** @since 0.1.0 @category character */\nexport const crlf = Ascii.crlf\n/**\n * nom's `not_line_ending`.\n *\n * @since 0.1.0\n * @category character\n */\nexport const notLineEnding = Ascii.tillLineEnding\n/**\n * A decimal unsigned integer (nom's `character::complete::u64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const u64 = Ascii.decUint\n/**\n * A decimal signed integer (nom's `character::complete::i64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const i64 = Ascii.decInt\n\n// -----------------------------------------------------------------------------\n// number\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `double` (and `float`).\n *\n * @since 0.1.0\n * @category number\n */\nexport const double = Ascii.float\n\n/**\n * nom's `recognize_float`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const recognizeFloat: Parser<string> = /*#__PURE__*/ P.taken(Ascii.float)\n\n/**\n * nom's `hex_u32`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const hexU32 = Ascii.hexUint\n\n/** @since 0.1.0 @category number */\nexport const beU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const beI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const leU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const leI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const beU16 = Binary.beU16\n/** @since 0.1.0 @category number */\nexport const leU16 = Binary.leU16\n/** @since 0.1.0 @category number */\nexport const beI16 = Binary.beI16\n/** @since 0.1.0 @category number */\nexport const leI16 = Binary.leI16\n/** @since 0.1.0 @category number */\nexport const beU24 = Binary.beU24\n/** @since 0.1.0 @category number */\nexport const leU24 = Binary.leU24\n/** @since 0.1.0 @category number */\nexport const beI24 = Binary.beI24\n/** @since 0.1.0 @category number */\nexport const leI24 = Binary.leI24\n/** @since 0.1.0 @category number */\nexport const beU32 = Binary.beU32\n/** @since 0.1.0 @category number */\nexport const leU32 = Binary.leU32\n/** @since 0.1.0 @category number */\nexport const beI32 = Binary.beI32\n/** @since 0.1.0 @category number */\nexport const leI32 = Binary.leI32\n/** @since 0.1.0 @category number */\nexport const beU64 = Binary.beU64\n/** @since 0.1.0 @category number */\nexport const leU64 = Binary.leU64\n/** @since 0.1.0 @category number */\nexport const beI64 = Binary.beI64\n/** @since 0.1.0 @category number */\nexport const leI64 = Binary.leI64\n/** @since 0.1.0 @category number */\nexport const beU128 = Binary.beU128\n/** @since 0.1.0 @category number */\nexport const leU128 = Binary.leU128\n/** @since 0.1.0 @category number */\nexport const beI128 = Binary.beI128\n/** @since 0.1.0 @category number */\nexport const leI128 = Binary.leI128\n/** @since 0.1.0 @category number */\nexport const beF32 = Binary.beF32\n/** @since 0.1.0 @category number */\nexport const leF32 = Binary.leF32\n/** @since 0.1.0 @category number */\nexport const beF64 = Binary.beF64\n/** @since 0.1.0 @category number */\nexport const leF64 = Binary.leF64\n\n// -----------------------------------------------------------------------------\n// multi\n// -----------------------------------------------------------------------------\n\n/**\n * Zero or more (nom's `many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many0 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<Array<A>, E, R, I> =>\n P.repeat(parser)\n\n/**\n * One or more (nom's `many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many1 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[A, ...Array<A>], E, R, I> =>\n P.repeat(parser, { min: 1 })\n\n/**\n * Between `m` and `n` times (nom's `many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyMN = <A, E, R, I extends Input>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E, R, I> => P.repeat(parser, { min: m, max: n })\n\n/**\n * Exactly `count` times (nom's `count`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const count = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>, count: number): Parser<Array<A>, E, R, I> =>\n P.repeat(parser, count)\n\n/**\n * Repeats `parser` until `end` succeeds (nom's `many_till`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyTill = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n end: Parser<B, E2, R2, I2>\n): Parser<[Array<A>, B], E | E2, R | R2, I & I2> => P.repeatTill(parser, end)\n\n/**\n * Zero or more `parser` separated by `separator` (nom's `separated_list0`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList0 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E | E2, R | R2, I & I2> => P.separated(parser, separator)\n\n/**\n * One or more `parser` separated by `separator` (nom's `separated_list1`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList1 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<[A, ...Array<A>], E | E2, R | R2, I & I2> => P.separated(parser, separator, { min: 1 })\n\n/**\n * Folds zero or more (nom's `fold_many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany0 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f })\n\n/**\n * Folds one or more (nom's `fold_many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany1 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: 1 } })\n\n/**\n * Folds between `m` and `n` times (nom's `fold_many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldManyMN = <A, E, R, I extends Input, B>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: m, max: n } })\n\n/**\n * nom's `length_data`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthData = Binary.lengthTake\n\n/**\n * nom's `length_value`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthValue = Binary.lengthAndThen\n\n/**\n * nom's `length_count`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthCount = Binary.lengthRepeat\n\n// -----------------------------------------------------------------------------\n// sequence / branch\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `pair`.\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const pair = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n first: Parser<A, E, R, I>,\n second: Parser<B, E2, R2, I2>\n): Parser<[A, B], E | E2, R | R2, I & I2> => P.zip(first, second)\n\n/**\n * nom's tuples of parsers (`(a, b, c)`, formerly `tuple`).\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const tuple = P.seq\n\n/** @since 0.1.0 @category sequence */\nexport const preceded = P.preceded\n/** @since 0.1.0 @category sequence */\nexport const terminated = P.terminated\n/** @since 0.1.0 @category sequence */\nexport const delimited = P.delimited\n/** @since 0.1.0 @category sequence */\nexport const separatedPair = P.separatedPair\n/** @since 0.1.0 @category branch */\nexport const alt = P.alt\n/** @since 0.1.0 @category branch */\nexport const permutation = P.permutation\n\n// -----------------------------------------------------------------------------\n// combinator\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const map = <A, E, R, I extends Input, B>(parser: Parser<A, E, R, I>, f: (a: A) => B): Parser<B, E, R, I> =>\n P.map(parser, f)\n\n/**\n * nom's `map_res`: the function returns a `Result`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapRes = <A, E, R, I extends Input, B, E2>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Result.Result<B, E2>\n): Parser<B, E | E2, R, I> => P.tryMap(parser, f)\n\n/**\n * nom's `map_opt`: the function returns an `Option`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapOpt = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Option.Option<B>\n): Parser<B, E, R, I> => P.filterMap(parser, f)\n\n/**\n * nom's `map_parser`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapParser = <A extends Input, E, R, I extends Input, B, E2, R2>(\n parser: Parser<A, E, R, I>,\n applied: Parser<B, E2, R2, A>\n): Parser<B, E | E2, R | R2, I> => P.mapParser(parser, applied)\n\n/**\n * nom's `flat_map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const flatMap = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Parser<B, E2, R2, I2>\n): Parser<B, E | E2, R | R2, I & I2> => P.flatMap(parser, f)\n\n/**\n * nom's `value` (note the value comes first).\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const value = <B, A, E, R, I extends Input>(val: B, parser: Parser<A, E, R, I>): Parser<B, E, R, I> =>\n P.as(parser, val)\n\n/**\n * nom's `verify`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const verify = <A, E, R, I extends Input>(\n parser: Parser<A, E, R, I>,\n predicate: (a: A) => boolean\n): Parser<A, E, R, I> => P.filter(parser, predicate)\n\n/**\n * nom's `recognize`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const recognize = P.taken\n\n/**\n * nom's `consumed`: returns `[consumed, output]`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const consumed = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[Slice<I>, A], E, R, I> =>\n P.map(P.withTaken(parser), ([a, s]) => [s, a])\n\n/** @since 0.1.0 @category combinator */\nexport const opt = P.opt\n/** @since 0.1.0 @category combinator */\nexport const cond = P.cond\n/** @since 0.1.0 @category combinator */\nexport const peek = P.peek\n/** @since 0.1.0 @category combinator */\nexport const not = P.not\n/** @since 0.1.0 @category combinator */\nexport const eof = P.eof\n/** @since 0.1.0 @category combinator */\nexport const allConsuming = P.allConsuming\n/** @since 0.1.0 @category combinator */\nexport const complete = P.complete\n/** @since 0.1.0 @category combinator */\nexport const cut = P.cut\n/** @since 0.1.0 @category combinator */\nexport const success = P.succeed\n/**\n * nom's `fail()`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const fail = P.reject\n/** @since 0.1.0 @category combinator */\nexport const rest = Token.rest\n/** @since 0.1.0 @category combinator */\nexport const restLen = Token.restLen\n\n/**\n * nom's `context` (note the label comes first).\n *\n * @since 0.1.0\n * @category error\n */\nexport const context = <A, E, R, I extends Input>(label: string, parser: Parser<A, E, R, I>): Parser<A, E, R, I> =>\n P.context(parser, label)\n"],"mappings":";;;;;;;;;;;;;AA2DA,MAAa,MAAM,MAAM;;;;;;;AAQzB,MAAa,YAAY,MAAM;;;;;;;AAQ/B,MAAa,QAAgC,MAAoB,MAAM,QAAQ,CAAC;;;;;;;AAQhF,MAAa,UAA0B,MAAM;;;;;AAM7C,MAAa,QAAQ,MAAM;;;;;AAM3B,MAAa,SAAS,MAAM;;;;;AAM5B,MAAa,UAAU,MAAM;;;;;;;AAQ7B,MAAa,OAAiC,QAC5C,MAAM,UAAa,KAAK,EAAE,KAAK,EAAE,CAAC;;;;;;;AAQpC,MAAa,SACX,QACwD,MAAM,SAAY,KAAK,EAAE,KAAK,EAAE,CAAC;;;;;AAM3F,MAAa,OAAO,MAAM;;;;;AAM1B,MAAa,aACX,cACwD,MAAM,UAAa,SAAgB;;;;;AAM7F,MAAa,cACX,cACwD,MAAM,UAAa,WAAkB,EAAE,KAAK,EAAE,CAAC;;;;;AAMzG,MAAa,eACX,GACA,GACA,cACwD,MAAM,UAAa,WAAkB;CAAE,KAAK;CAAG,KAAK;AAAE,CAAC;;;;;AAMjH,MAAa,YACX,cACwD,MAAM,SAAY,SAAgB;;;;;AAM5F,MAAa,aACX,cACwD,MAAM,SAAY,WAAkB,EAAE,KAAK,EAAE,CAAC;;;;;AAM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C,OAAe,WAC/D,EAAE,QAAQ,QAAQ,KAAK"}
|
|
1
|
+
{"version":3,"file":"Nom.js","names":[],"sources":["../src/Nom.ts"],"sourcesContent":["/**\n * nom-flavoured names for effect-parse's parsers and combinators.\n *\n * effect-parse's main API follows winnow's naming (in camelCase). This module\n * offers the names, and argument orders, that nom users know, so grammars\n * can be ported with minimal changes:\n *\n * | nom | effect-parse |\n * |---|---|\n * | `tag(\"abc\")` | `Token.literal(\"abc\")` |\n * | `many0(p)` | `Parser.repeat(p)` |\n * | `separated_list1(sep, p)` | `Parser.separated(p, sep, { min: 1 })` |\n * | `map_res(p, f)` | `Parser.tryMap(p, f)` |\n * | `recognize(p)` | `Parser.taken(p)` |\n * | `value(v, p)` | `Parser.as(p, v)` |\n *\n * nom's `streaming` and `complete` variants are not separate functions here.\n * Whether input is partial is decided by the runner (`Parser.parsePartial`\n * vs `Parser.parse`).\n *\n * @example\n * ```ts\n * import { Result } from \"effect\"\n * import { Nom, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * const hexPrimary = Nom.mapRes(\n * Nom.takeWhileMN(2, 2, (c: string) => /[0-9a-fA-F]/.test(c)),\n * (s) => Result.succeed(parseInt(s, 16))\n * )\n * const hexColor = Nom.preceded(\n * Nom.tag(\"#\"),\n * Nom.tuple(hexPrimary, hexPrimary, hexPrimary)\n * )\n *\n * Parser.parse(hexColor, \"#2F14DF\") // Result.succeed([47, 20, 223])\n * ```\n *\n * @since 0.1.0\n */\nimport * as Option from \"effect/Option\"\nimport * as Result from \"effect/Result\"\nimport * as Ascii from \"./Ascii.js\"\nimport * as Binary from \"./Binary.js\"\nimport type { Input, Slice, Token as TokenOf } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\nimport type { TokenSet } from \"./Token.js\"\n\n// -----------------------------------------------------------------------------\n// bytes / character\n// -----------------------------------------------------------------------------\n\n/**\n * Matches a literal (nom's `tag`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tag = Token.literal\n\n/**\n * Matches a literal, ignoring ASCII case (nom's `tag_no_case`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tagNoCase = Ascii.caseless\n\n/**\n * Matches a single character (nom's `char`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const char = <const C extends string>(c: C): Parser<C> => Token.literal(c)\n\n/**\n * Matches any character (nom's `anychar`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const anychar: Parser<string> = Token.any\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const oneOf = Token.oneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const noneOf = Token.noneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const satisfy = Token.satisfy\n\n/**\n * The longest non-empty run of tokens from a set (nom's `is_a`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isA = <I extends Input = string>(set: TokenSet<I>): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n Token.takeWhile<I>(set, { min: 1 })\n\n/**\n * The longest non-empty run of tokens *not* from a set (nom's `is_not`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isNot = <I extends Input = string>(\n set: TokenSet<I>\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(set, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const take = Token.take\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeWhile<I>(predicate as Token.TokenSet<I>)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeWhile<I>(predicate as Token.TokenSet<I>, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhileMN = <I extends Input = string>(\n m: number,\n n: number,\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeWhile<I>(predicate as Token.TokenSet<I>, { min: m, max: n })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeTill<I>(predicate as Token.TokenSet<I>)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeTill<I>(predicate as Token.TokenSet<I>, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeUntil = Token.takeUntil\n\n/**\n * Recognizes an escaped string (nom's `escaped`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escaped = Ascii.takeEscaped\n\n/**\n * Unescapes an escaped string (nom's `escaped_transform`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escapedTransform = Ascii.escaped\n\n/** @since 0.1.0 @category character */\nexport const alpha0 = Ascii.alpha0\n/** @since 0.1.0 @category character */\nexport const alpha1 = Ascii.alpha1\n/** @since 0.1.0 @category character */\nexport const digit0 = Ascii.digit0\n/** @since 0.1.0 @category character */\nexport const digit1 = Ascii.digit1\n/** @since 0.1.0 @category character */\nexport const hexDigit0 = Ascii.hexDigit0\n/** @since 0.1.0 @category character */\nexport const hexDigit1 = Ascii.hexDigit1\n/** @since 0.1.0 @category character */\nexport const octDigit0 = Ascii.octDigit0\n/** @since 0.1.0 @category character */\nexport const octDigit1 = Ascii.octDigit1\n/** @since 0.1.0 @category character */\nexport const alphanumeric0 = Ascii.alphanumeric0\n/** @since 0.1.0 @category character */\nexport const alphanumeric1 = Ascii.alphanumeric1\n/** @since 0.1.0 @category character */\nexport const space0 = Ascii.space0\n/** @since 0.1.0 @category character */\nexport const space1 = Ascii.space1\n/** @since 0.1.0 @category character */\nexport const multispace0 = Ascii.multispace0\n/** @since 0.1.0 @category character */\nexport const multispace1 = Ascii.multispace1\n/** @since 0.1.0 @category character */\nexport const lineEnding = Ascii.lineEnding\n/** @since 0.1.0 @category character */\nexport const newline = Ascii.newline\n/** @since 0.1.0 @category character */\nexport const tab = Ascii.tab\n/** @since 0.1.0 @category character */\nexport const crlf = Ascii.crlf\n/**\n * nom's `not_line_ending`.\n *\n * @since 0.1.0\n * @category character\n */\nexport const notLineEnding = Ascii.tillLineEnding\n/**\n * A decimal unsigned integer (nom's `character::complete::u64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const u64 = Ascii.decUint\n/**\n * A decimal signed integer (nom's `character::complete::i64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const i64 = Ascii.decInt\n\n// -----------------------------------------------------------------------------\n// number\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `double` (and `float`).\n *\n * @since 0.1.0\n * @category number\n */\nexport const double = Ascii.float\n\n/**\n * nom's `recognize_float`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const recognizeFloat: Parser<string> = /*#__PURE__*/ P.taken(Ascii.float)\n\n/**\n * nom's `hex_u32`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const hexU32 = Ascii.hexUint\n\n/** @since 0.1.0 @category number */\nexport const beU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const beI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const leU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const leI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const beU16 = Binary.beU16\n/** @since 0.1.0 @category number */\nexport const leU16 = Binary.leU16\n/** @since 0.1.0 @category number */\nexport const beI16 = Binary.beI16\n/** @since 0.1.0 @category number */\nexport const leI16 = Binary.leI16\n/** @since 0.1.0 @category number */\nexport const beU24 = Binary.beU24\n/** @since 0.1.0 @category number */\nexport const leU24 = Binary.leU24\n/** @since 0.1.0 @category number */\nexport const beI24 = Binary.beI24\n/** @since 0.1.0 @category number */\nexport const leI24 = Binary.leI24\n/** @since 0.1.0 @category number */\nexport const beU32 = Binary.beU32\n/** @since 0.1.0 @category number */\nexport const leU32 = Binary.leU32\n/** @since 0.1.0 @category number */\nexport const beI32 = Binary.beI32\n/** @since 0.1.0 @category number */\nexport const leI32 = Binary.leI32\n/** @since 0.1.0 @category number */\nexport const beU64 = Binary.beU64\n/** @since 0.1.0 @category number */\nexport const leU64 = Binary.leU64\n/** @since 0.1.0 @category number */\nexport const beI64 = Binary.beI64\n/** @since 0.1.0 @category number */\nexport const leI64 = Binary.leI64\n/** @since 0.1.0 @category number */\nexport const beU128 = Binary.beU128\n/** @since 0.1.0 @category number */\nexport const leU128 = Binary.leU128\n/** @since 0.1.0 @category number */\nexport const beI128 = Binary.beI128\n/** @since 0.1.0 @category number */\nexport const leI128 = Binary.leI128\n/** @since 0.1.0 @category number */\nexport const beF32 = Binary.beF32\n/** @since 0.1.0 @category number */\nexport const leF32 = Binary.leF32\n/** @since 0.1.0 @category number */\nexport const beF64 = Binary.beF64\n/** @since 0.1.0 @category number */\nexport const leF64 = Binary.leF64\n\n// -----------------------------------------------------------------------------\n// multi\n// -----------------------------------------------------------------------------\n\n/**\n * Zero or more (nom's `many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many0 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<Array<A>, E, R, I> =>\n P.repeat(parser)\n\n/**\n * One or more (nom's `many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many1 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[A, ...Array<A>], E, R, I> =>\n P.repeat(parser, { min: 1 })\n\n/**\n * Between `m` and `n` times (nom's `many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyMN = <A, E, R, I extends Input>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E, R, I> => P.repeat(parser, { min: m, max: n })\n\n/**\n * Exactly `count` times (nom's `count`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const count = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>, count: number): Parser<Array<A>, E, R, I> =>\n P.repeat(parser, count)\n\n/**\n * Repeats `parser` until `end` succeeds (nom's `many_till`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyTill = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n end: Parser<B, E2, R2, I2>\n): Parser<[Array<A>, B], E | E2, R | R2, I & I2> => P.repeatTill(parser, end)\n\n/**\n * Zero or more `parser` separated by `separator` (nom's `separated_list0`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList0 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E | E2, R | R2, I & I2> => P.separated(parser, separator)\n\n/**\n * One or more `parser` separated by `separator` (nom's `separated_list1`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList1 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<[A, ...Array<A>], E | E2, R | R2, I & I2> => P.separated(parser, separator, { min: 1 })\n\n/**\n * Folds zero or more (nom's `fold_many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany0 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f })\n\n/**\n * Folds one or more (nom's `fold_many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany1 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: 1 } })\n\n/**\n * Folds between `m` and `n` times (nom's `fold_many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldManyMN = <A, E, R, I extends Input, B>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: m, max: n } })\n\n/**\n * nom's `length_data`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthData = Binary.lengthTake\n\n/**\n * nom's `length_value`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthValue = Binary.lengthAndThen\n\n/**\n * nom's `length_count`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthCount = Binary.lengthRepeat\n\n// -----------------------------------------------------------------------------\n// sequence / branch\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `pair`.\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const pair = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n first: Parser<A, E, R, I>,\n second: Parser<B, E2, R2, I2>\n): Parser<[A, B], E | E2, R | R2, I & I2> => P.zip(first, second)\n\n/**\n * nom's tuples of parsers (`(a, b, c)`, formerly `tuple`).\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const tuple = P.seq\n\n/** @since 0.1.0 @category sequence */\nexport const preceded = P.preceded\n/** @since 0.1.0 @category sequence */\nexport const terminated = P.terminated\n/** @since 0.1.0 @category sequence */\nexport const delimited = P.delimited\n/** @since 0.1.0 @category sequence */\nexport const separatedPair = P.separatedPair\n/** @since 0.1.0 @category branch */\nexport const alt = P.alt\n/** @since 0.1.0 @category branch */\nexport const permutation = P.permutation\n\n// -----------------------------------------------------------------------------\n// combinator\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const map = <A, E, R, I extends Input, B>(parser: Parser<A, E, R, I>, f: (a: A) => B): Parser<B, E, R, I> =>\n P.map(parser, f)\n\n/**\n * nom's `map_res`: the function returns a `Result`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapRes = <A, E, R, I extends Input, B, E2>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Result.Result<B, E2>\n): Parser<B, E | E2, R, I> => P.tryMap(parser, f)\n\n/**\n * nom's `map_opt`: the function returns an `Option`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapOpt = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Option.Option<B>\n): Parser<B, E, R, I> => P.filterMap(parser, f)\n\n/**\n * nom's `map_parser`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapParser = <A extends Input, E, R, I extends Input, B, E2, R2>(\n parser: Parser<A, E, R, I>,\n applied: Parser<B, E2, R2, A>\n): Parser<B, E | E2, R | R2, I> => P.mapParser(parser, applied)\n\n/**\n * nom's `flat_map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const flatMap = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Parser<B, E2, R2, I2>\n): Parser<B, E | E2, R | R2, I & I2> => P.flatMap(parser, f)\n\n/**\n * nom's `value` (note the value comes first).\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const value = <B, A, E, R, I extends Input>(val: B, parser: Parser<A, E, R, I>): Parser<B, E, R, I> =>\n P.as(parser, val)\n\n/**\n * nom's `verify`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const verify = <A, E, R, I extends Input>(\n parser: Parser<A, E, R, I>,\n predicate: (a: A) => boolean\n): Parser<A, E, R, I> => P.filter(parser, predicate)\n\n/**\n * nom's `recognize`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const recognize = P.taken\n\n/**\n * nom's `consumed`: returns `[consumed, output]`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const consumed = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[Slice<I>, A], E, R, I> =>\n P.map(P.withTaken(parser), ([a, s]) => [s, a])\n\n/** @since 0.1.0 @category combinator */\nexport const opt = P.opt\n/** @since 0.1.0 @category combinator */\nexport const cond = P.cond\n/** @since 0.1.0 @category combinator */\nexport const peek = P.peek\n/** @since 0.1.0 @category combinator */\nexport const not = P.not\n/** @since 0.1.0 @category combinator */\nexport const eof = P.eof\n/** @since 0.1.0 @category combinator */\nexport const allConsuming = P.allConsuming\n/** @since 0.1.0 @category combinator */\nexport const complete = P.complete\n/** @since 0.1.0 @category combinator */\nexport const cut = P.cut\n/** @since 0.1.0 @category combinator */\nexport const success = P.succeed\n/**\n * nom's `fail()`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const fail = P.reject\n/** @since 0.1.0 @category combinator */\nexport const rest = Token.rest\n/** @since 0.1.0 @category combinator */\nexport const restLen = Token.restLen\n\n/**\n * nom's `context` (note the label comes first).\n *\n * @since 0.1.0\n * @category error\n */\nexport const context = <A, E, R, I extends Input>(label: string, parser: Parser<A, E, R, I>): Parser<A, E, R, I> =>\n P.context(parser, label)\n"],"mappings":";;;;;;;;;;;;;AA2DA,MAAa,MAAM,MAAM;;;;;;;AAQzB,MAAa,YAAY,MAAM;;;;;;;AAQ/B,MAAa,QAAgC,MAAoB,MAAM,QAAQ,CAAC;;;;;;;AAQhF,MAAa,UAA0B,MAAM;;;;;AAM7C,MAAa,QAAQ,MAAM;;;;;AAM3B,MAAa,SAAS,MAAM;;;;;AAM5B,MAAa,UAAU,MAAM;;;;;;;AAQ7B,MAAa,OAAiC,QAC5C,MAAM,UAAa,KAAK,EAAE,KAAK,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;;;;;;AAQ3B,MAAa,YAAsC,WACjD,EAAE,IAAI,EAAE,UAAU,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;;AAG/C,MAAa,MAAM,EAAE;;AAErB,MAAa,OAAO,EAAE;;AAEtB,MAAa,OAAO,EAAE;;AAEtB,MAAa,MAAM,EAAE;;AAErB,MAAa,MAAM,EAAE;;AAErB,MAAa,eAAe,EAAE;;AAE9B,MAAa,WAAW,EAAE;;AAE1B,MAAa,MAAM,EAAE;;AAErB,MAAa,UAAU,EAAE;;;;;;;AAOzB,MAAa,OAAO,EAAE;;AAEtB,MAAa,OAAO,MAAM;;AAE1B,MAAa,UAAU,MAAM;;;;;;;AAQ7B,MAAa,WAAqC,OAAe,WAC/D,EAAE,QAAQ,QAAQ,KAAK"}
|
package/dist/ParseError.d.ts
CHANGED
|
@@ -17,16 +17,8 @@ export type ErrorKind = "Alpha" | "AlphaNumeric" | "Alt" | "Assert" | "Bits" | "
|
|
|
17
17
|
* @category type ids
|
|
18
18
|
*/
|
|
19
19
|
export declare const TypeId: "~effect-parse/ParseError";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} & Readonly<A>;
|
|
23
|
-
/**
|
|
24
|
-
* An error produced by running a parser.
|
|
25
|
-
*
|
|
26
|
-
* @since 0.1.0
|
|
27
|
-
* @category models
|
|
28
|
-
*/
|
|
29
|
-
export declare class ParseError<out E = never> extends /*#__PURE__*/ ParseError_base<{
|
|
20
|
+
/** What a {@link ParseError} is built from. */
|
|
21
|
+
interface Fields<E> {
|
|
30
22
|
/** The input that was being parsed. */
|
|
31
23
|
readonly input: Input;
|
|
32
24
|
/** The offset of the failure in the input. */
|
|
@@ -48,7 +40,73 @@ export declare class ParseError<out E = never> extends /*#__PURE__*/ ParseError_
|
|
|
48
40
|
* then show the input as text, with line and column numbers.
|
|
49
41
|
*/
|
|
50
42
|
readonly encoding?: Encoding<Uint8Array> | undefined;
|
|
51
|
-
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What a {@link ParseError} serialises as (`toJSON`): everything but the
|
|
46
|
+
* input it was parsing and the encoding it was read in.
|
|
47
|
+
*
|
|
48
|
+
* @since 0.6.0
|
|
49
|
+
* @category models
|
|
50
|
+
*/
|
|
51
|
+
export interface ParseErrorJson<out E = never> {
|
|
52
|
+
readonly _tag: "ParseError";
|
|
53
|
+
/** The offset of the failure in the input. */
|
|
54
|
+
readonly offset: number;
|
|
55
|
+
/** The 1-based line and column of the failure. */
|
|
56
|
+
readonly position: LineColumn;
|
|
57
|
+
readonly kind: ErrorKind;
|
|
58
|
+
readonly mode: ErrMode;
|
|
59
|
+
readonly expected: ReadonlyArray<string>;
|
|
60
|
+
readonly context: ReadonlyArray<string>;
|
|
61
|
+
readonly cause: E | undefined;
|
|
62
|
+
readonly description: string | undefined;
|
|
63
|
+
/** The rendered message, which shows a bounded window of the input around the failure. */
|
|
64
|
+
readonly message: string;
|
|
65
|
+
}
|
|
66
|
+
declare const ParseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
67
|
+
readonly _tag: "ParseError";
|
|
68
|
+
} & Readonly<A>;
|
|
69
|
+
/**
|
|
70
|
+
* An error produced by running a parser.
|
|
71
|
+
*
|
|
72
|
+
* The error keeps the whole input alive for as long as it is retained
|
|
73
|
+
* (`input`), but does not serialise it: `input` and `encoding` are
|
|
74
|
+
* accessors, not own properties, `toJSON` (which `JSON.stringify`,
|
|
75
|
+
* Effect's `Cause` rendering and Node's `inspect` use) leaves them out, and
|
|
76
|
+
* `message` shows a bounded window around the failure, never a whole line.
|
|
77
|
+
*
|
|
78
|
+
* @since 0.1.0
|
|
79
|
+
* @category models
|
|
80
|
+
*/
|
|
81
|
+
export declare class ParseError<out E = never> extends /*#__PURE__*/ ParseError_base<Omit<Fields<unknown>, "input" | "encoding">> {
|
|
82
|
+
#private;
|
|
83
|
+
/** The user supplied cause, if any. */
|
|
84
|
+
readonly cause: E | undefined;
|
|
85
|
+
constructor(fields: Fields<E>);
|
|
86
|
+
/**
|
|
87
|
+
* The input that was being parsed. The error holds it (for
|
|
88
|
+
* {@link ParseError.position} and the message) and keeps it alive, but it
|
|
89
|
+
* is not one of the error's own properties, so `JSON.stringify`, object
|
|
90
|
+
* spread, `Object.keys`, `toJSON` and loggers do not see it.
|
|
91
|
+
*
|
|
92
|
+
* @since 0.1.0
|
|
93
|
+
*/
|
|
94
|
+
get input(): Input;
|
|
95
|
+
/**
|
|
96
|
+
* For byte inputs parsed by `Text` parsers, the text encoding. Errors
|
|
97
|
+
* then show the input as text, with line and column numbers. Like
|
|
98
|
+
* `input`, it is not an own property.
|
|
99
|
+
*
|
|
100
|
+
* @since 0.1.0
|
|
101
|
+
*/
|
|
102
|
+
get encoding(): Encoding<Uint8Array> | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* The error without its `input` and `encoding`: what `JSON.stringify`,
|
|
105
|
+
* Effect's `Cause` rendering and Node's `inspect` show.
|
|
106
|
+
*
|
|
107
|
+
* @since 0.6.0
|
|
108
|
+
*/
|
|
109
|
+
toJSON(): ParseErrorJson<E>;
|
|
52
110
|
/**
|
|
53
111
|
* @since 0.1.0
|
|
54
112
|
*/
|
package/dist/ParseError.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParseError.d.ts","names":[],"sources":["../src/ParseError.ts"],"mappings":";;;;;;;;;;;;;YAwCY;;;;;qBAuCC
|
|
1
|
+
{"version":3,"file":"ParseError.d.ts","names":[],"sources":["../src/ParseError.ts"],"mappings":";;;;;;;;;;;;;YAwCY;;;;;qBAuCC;;UAGH,OAAO;;WAEN,OAAO;;WAEP;;WAEA,MAAM;;WAEN,MAAM;;WAEN,UAAU;;WAEV,SAAS;;WAET,OAAO;;WAEP;;;;;WAKA,WAAW,SAAS;;;;;;;;;iBAUd,mBAAmB;WACzB;;WAEA;;WAEA,UAAU;WACV,MAAM;WACN,MAAM;WACN,UAAU;WACV,SAAS;WACT,OAAO;WACP;;WAEA;;;;;;;;;;;;;;;;;qBAeE,eAAe,iCACJ,gBAA+B,KAAK;;;WAGzC,OAAO;EAYZ,YAAA,QAAQ,OAAO;;;;;;;;;MAsBvB,SAAS;;;;;;;;MAWT,YAAY,SAAS;;;;;;;EAUhB,UAAU,eAAe;;;;YAkBxB,gBAAgB;;;;;;;MAQtB,YAAY;;;;;;MASH;;;;EAOJ;;;;;;qBASE,eAAgB,eAAa,KAAK;;;;;;;qBAQlC,cAAe,WAC1B,OAAO,OACP,SAAS,SACT,MAAM,SACN,WAAW,kBACV,WAAW;;;;;;;qBAsBD,WAAY,GAAG,MAAM,WAAW,OAAK,OAAO,OAAO;;;;;;;iBAS/C;WACN;WACA;;;;;;;;;;;qBAYE,aAAc,OAAO,OAAO,gBAAgB,WAAW,kBAAgB;;;;;;;qBA6CvE,iBAAkB,UAAU;;qBA8B5B,eAAgB"}
|