@thomasfosterau/effect-parse 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +247 -230
- package/dist/Ascii.d.ts +32 -53
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +576 -571
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts +6 -29
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +129 -116
- package/dist/Binary.js.map +1 -1
- package/dist/Bits.d.ts +4 -2
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +121 -123
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +39 -0
- package/dist/Compiler.d.ts.map +1 -0
- package/dist/Compiler.js +48 -0
- package/dist/Compiler.js.map +1 -0
- package/dist/Encoding.d.ts +29 -46
- package/dist/Encoding.d.ts.map +1 -1
- package/dist/Encoding.js +76 -75
- package/dist/Encoding.js.map +1 -1
- package/dist/Expression.d.ts +15 -49
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +143 -131
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +206 -177
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +317 -299
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +44 -84
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js +423 -453
- package/dist/Nom.js.map +1 -1
- package/dist/ParseError.d.ts +54 -49
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +233 -275
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +345 -313
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +2010 -1802
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts +8 -7
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +49 -49
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +26 -20
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +267 -255
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +401 -0
- package/dist/Syntax.d.ts.map +1 -0
- package/dist/Syntax.js +717 -0
- package/dist/Syntax.js.map +1 -0
- package/dist/Text.d.ts +98 -134
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +534 -496
- package/dist/Text.js.map +1 -1
- package/dist/Token.d.ts +60 -42
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +331 -265
- package/dist/Token.js.map +1 -1
- package/dist/index.d.ts +16 -17
- package/dist/index.js +16 -17
- package/dist/internal/compiler/closure.d.ts +14 -16
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +1458 -1637
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +11 -11
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +36 -26
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts +19 -19
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +251 -227
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/jit.d.ts +6 -17
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +860 -988
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +20 -21
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js +21 -41
- package/dist/internal/compiler/registry.js.map +1 -1
- package/dist/internal/compiler/sets.d.ts +9 -13
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +76 -73
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/entries.d.ts +3 -3
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js +38 -30
- package/dist/internal/entries.js.map +1 -1
- package/dist/internal/node.d.ts +177 -173
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +77 -66
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts +7 -8
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js +246 -276
- package/dist/internal/numbers.js.map +1 -1
- package/dist/internal/resume.d.ts +6 -24
- package/dist/internal/resume.d.ts.map +1 -1
- package/dist/internal/resume.js +30 -29
- package/dist/internal/resume.js.map +1 -1
- package/dist/internal/run.d.ts +15 -0
- package/dist/internal/run.d.ts.map +1 -0
- package/dist/internal/run.js +36 -0
- package/dist/internal/run.js.map +1 -0
- package/dist/internal/stack.d.ts +16 -0
- package/dist/internal/stack.d.ts.map +1 -0
- package/dist/internal/stack.js +26 -0
- package/dist/internal/stack.js.map +1 -0
- package/dist/internal/syntax.d.ts +146 -0
- package/dist/internal/syntax.d.ts.map +1 -0
- package/dist/internal/syntax.js +305 -0
- package/dist/internal/syntax.js.map +1 -0
- package/dist/internal/text.d.ts +10 -2
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +295 -345
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/tokens.d.ts +25 -30
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +369 -363
- package/dist/internal/tokens.js.map +1 -1
- package/package.json +42 -28
- package/src/Ascii.ts +278 -187
- package/src/Binary.ts +150 -44
- package/src/Bits.ts +6 -3
- package/src/Compiler.ts +98 -0
- package/src/Expression.ts +10 -5
- package/src/Input.ts +106 -28
- package/src/Nom.ts +4 -3
- package/src/ParseError.ts +48 -51
- package/src/Parser.ts +1163 -795
- package/src/ParserStream.ts +104 -80
- package/src/Syntax.ts +900 -0
- package/src/Text.ts +272 -187
- package/src/Token.ts +180 -87
- package/src/index.ts +2 -0
- package/src/internal/compiler/closure.ts +121 -88
- package/src/internal/compiler/entries.ts +21 -8
- package/src/internal/compiler/first.ts +17 -15
- package/src/internal/compiler/jit.ts +360 -157
- package/src/internal/compiler/registry.ts +12 -33
- package/src/internal/compiler/sets.ts +17 -11
- package/src/internal/entries.ts +4 -2
- package/src/internal/node.ts +51 -37
- package/src/internal/numbers.ts +22 -20
- package/src/internal/resume.ts +8 -4
- package/src/internal/run.ts +41 -0
- package/src/internal/stack.ts +36 -0
- package/src/internal/syntax.ts +421 -0
- package/src/internal/text.ts +32 -25
- package/src/internal/tokens.ts +96 -51
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/Parser.d.ts
CHANGED
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* A `Parser<A, E, R, I>` consumes input of type `I` and produces a value of
|
|
5
|
-
* type `A`. It may fail with a `ParseError<E>`, where `E` is the type of
|
|
6
|
-
* user supplied error causes, and it may require services `R` from an Effect
|
|
7
|
-
* `Context`.
|
|
8
|
-
*
|
|
9
|
-
* Under the hood a parser is a function over a mutable cursor (`Input.State`),
|
|
10
|
-
* as in winnow. Failure is cheap and backtracking is a matter of resetting an
|
|
11
|
-
* offset. On the surface the API follows Effect's conventions: parsers are
|
|
12
|
-
* pipeable, combinators are dual (data-first or data-last), and parsers can
|
|
13
|
-
* be written with generators:
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { Ascii, Parser, Token } from "@thomasfosterau/effect-parse"
|
|
17
|
-
*
|
|
18
|
-
* const point = Parser.gen(function*() {
|
|
19
|
-
* yield* Token.literal("(")
|
|
20
|
-
* const x = yield* Ascii.decInt
|
|
21
|
-
* yield* Token.literal(",")
|
|
22
|
-
* const y = yield* Ascii.decInt
|
|
23
|
-
* yield* Token.literal(")")
|
|
24
|
-
* return { x, y }
|
|
25
|
-
* })
|
|
26
|
-
*
|
|
27
|
-
* Parser.parse(point, "(1,-2)") // Result.succeed({ x: 1, y: -2 })
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @since 0.1.0
|
|
31
|
-
*/
|
|
1
|
+
import * as Result from "effect/Result";
|
|
2
|
+
import { Fail, Input, Slice, Source, State, TraceEvent } from "./Input.js";
|
|
3
|
+
import * as Option from "effect/Option";
|
|
32
4
|
import * as Context from "effect/Context";
|
|
33
5
|
import * as Effect from "effect/Effect";
|
|
34
|
-
import
|
|
35
|
-
import type { Pipeable } from "effect/Pipeable";
|
|
36
|
-
import * as Result from "effect/Result";
|
|
37
|
-
import type { Contravariant, Covariant, Simplify } from "effect/Types";
|
|
38
|
-
import type { Input, Slice, Source, TraceEvent } from "./Input.js";
|
|
39
|
-
import { Fail, State } from "./Input.js";
|
|
40
|
-
import type { ErrorKind } from "./ParseError.js";
|
|
6
|
+
import { Pipeable } from "effect/Pipeable";
|
|
41
7
|
import * as ParseError from "./ParseError.js";
|
|
42
|
-
import
|
|
8
|
+
import { ErrorKind } from "./ParseError.js";
|
|
9
|
+
import { Node } from "./internal/node.js";
|
|
10
|
+
import { Contravariant, Covariant, Simplify } from "effect/Types";
|
|
11
|
+
//#region src/Parser.d.ts
|
|
43
12
|
/**
|
|
44
13
|
* @since 0.1.0
|
|
45
14
|
* @category type ids
|
|
@@ -53,18 +22,18 @@ export declare const TypeId: "~effect-parse/Parser";
|
|
|
53
22
|
* @category models
|
|
54
23
|
*/
|
|
55
24
|
export interface Parser<out A, out E = never, out R = never, in I extends Input = string> extends Pipeable {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
25
|
+
readonly [TypeId]: Parser.Variance<A, E, R, I>;
|
|
26
|
+
/**
|
|
27
|
+
* Runs one parsing step against a cursor. Returns the parsed value, or the
|
|
28
|
+
* `Fail` sentinel after recording the failure on the state.
|
|
29
|
+
*
|
|
30
|
+
* Calling `step` directly is how custom combinators built with
|
|
31
|
+
* {@link make} invoke other parsers.
|
|
32
|
+
*/
|
|
33
|
+
readonly step: (state: State<I>) => A | Fail;
|
|
34
|
+
/** A human-readable name, used by `toString` and tracing. */
|
|
35
|
+
readonly name: string | undefined;
|
|
36
|
+
[Symbol.iterator](): ParserIterator<Parser<A, E, R, I>>;
|
|
68
37
|
}
|
|
69
38
|
/**
|
|
70
39
|
* The iterator used by `yield*` inside {@link gen}.
|
|
@@ -73,53 +42,53 @@ export interface Parser<out A, out E = never, out R = never, in I extends Input
|
|
|
73
42
|
* @category models
|
|
74
43
|
*/
|
|
75
44
|
export interface ParserIterator<P extends Parser.Any> {
|
|
76
|
-
|
|
45
|
+
next(...args: ReadonlyArray<any>): IteratorResult<P, Parser.Success<P>>;
|
|
77
46
|
}
|
|
78
47
|
/**
|
|
79
48
|
* @since 0.1.0
|
|
80
49
|
* @category models
|
|
81
50
|
*/
|
|
82
51
|
export declare namespace Parser {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
52
|
+
/**
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
*/
|
|
55
|
+
interface Variance<A, E, R, I> {
|
|
56
|
+
readonly _A: Covariant<A>;
|
|
57
|
+
readonly _E: Covariant<E>;
|
|
58
|
+
readonly _R: Covariant<R>;
|
|
59
|
+
readonly _I: Contravariant<I>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Any parser.
|
|
63
|
+
*
|
|
64
|
+
* @since 0.1.0
|
|
65
|
+
*/
|
|
66
|
+
type Any = Parser<any, any, any, any>;
|
|
67
|
+
/**
|
|
68
|
+
* The output type of a parser.
|
|
69
|
+
*
|
|
70
|
+
* @since 0.1.0
|
|
71
|
+
*/
|
|
72
|
+
type Success<P> = P extends Parser<infer A, infer _E, infer _R, infer _I> ? A : never;
|
|
73
|
+
/**
|
|
74
|
+
* The user error type of a parser.
|
|
75
|
+
*
|
|
76
|
+
* @since 0.1.0
|
|
77
|
+
*/
|
|
78
|
+
type Error<P> = P extends Parser<infer _A, infer E, infer _R, infer _I> ? E : never;
|
|
79
|
+
/**
|
|
80
|
+
* The services required by a parser.
|
|
81
|
+
*
|
|
82
|
+
* @since 0.1.0
|
|
83
|
+
*/
|
|
84
|
+
type Services<P> = P extends Parser<infer _A, infer _E, infer R, infer _I> ? R : never;
|
|
85
|
+
/**
|
|
86
|
+
* The input accepted by a parser (or by every member of a union of
|
|
87
|
+
* parsers).
|
|
88
|
+
*
|
|
89
|
+
* @since 0.1.0
|
|
90
|
+
*/
|
|
91
|
+
type InputOf<P> = [P] extends [never] ? Input : [P] extends [Parser<infer _A, infer _E, infer _R, infer I>] ? I : never;
|
|
123
92
|
}
|
|
124
93
|
/**
|
|
125
94
|
* A repetition range, in the spirit of winnow's `impl Into<Range>`:
|
|
@@ -132,8 +101,8 @@ export declare namespace Parser {
|
|
|
132
101
|
* @category models
|
|
133
102
|
*/
|
|
134
103
|
export type Range = number | {
|
|
135
|
-
|
|
136
|
-
|
|
104
|
+
readonly min?: number | undefined;
|
|
105
|
+
readonly max?: number | undefined;
|
|
137
106
|
};
|
|
138
107
|
/**
|
|
139
108
|
* The output of a repetition: a non-empty array when the range has a literal
|
|
@@ -143,7 +112,7 @@ export type Range = number | {
|
|
|
143
112
|
* @category models
|
|
144
113
|
*/
|
|
145
114
|
export type Repeated<A, Rg> = Rg extends number ? number extends Rg ? Array<A> : Rg extends 0 ? Array<A> : NonEmpty<A> : Rg extends {
|
|
146
|
-
|
|
115
|
+
readonly min: infer M extends number;
|
|
147
116
|
} ? number extends M ? Array<A> : M extends 0 ? Array<A> : NonEmpty<A> : Array<A>;
|
|
148
117
|
type NonEmpty<A> = [A, ...Array<A>];
|
|
149
118
|
/**
|
|
@@ -153,8 +122,8 @@ type NonEmpty<A> = [A, ...Array<A>];
|
|
|
153
122
|
* @category models
|
|
154
123
|
*/
|
|
155
124
|
export interface Span {
|
|
156
|
-
|
|
157
|
-
|
|
125
|
+
readonly start: number;
|
|
126
|
+
readonly end: number;
|
|
158
127
|
}
|
|
159
128
|
/**
|
|
160
129
|
* Tests whether a value is a `Parser`.
|
|
@@ -206,8 +175,8 @@ export declare const described: <A, E = never, R = never, I extends Input = stri
|
|
|
206
175
|
* @category utils
|
|
207
176
|
*/
|
|
208
177
|
export declare const named: {
|
|
209
|
-
|
|
210
|
-
|
|
178
|
+
(name: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
|
|
179
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, name: string): Parser<A, E, R, I>;
|
|
211
180
|
};
|
|
212
181
|
/**
|
|
213
182
|
* A parser that consumes nothing and succeeds with the given value.
|
|
@@ -238,12 +207,6 @@ export declare const empty: Parser<void, never, never, Input>;
|
|
|
238
207
|
* @category constructors
|
|
239
208
|
*/
|
|
240
209
|
export declare const void_: Parser<void, never, never, Input>;
|
|
241
|
-
export {
|
|
242
|
-
/**
|
|
243
|
-
* @since 0.1.0
|
|
244
|
-
* @category constructors
|
|
245
|
-
*/
|
|
246
|
-
void_ as void };
|
|
247
210
|
/**
|
|
248
211
|
* A parser that always fails (backtracks) with the given user error as its
|
|
249
212
|
* cause.
|
|
@@ -279,6 +242,11 @@ export declare const todo: Parser<never, never, never, Input>;
|
|
|
279
242
|
* Lazily constructs a parser, which is needed to define recursive grammars.
|
|
280
243
|
* The thunk is evaluated once, on first use.
|
|
281
244
|
*
|
|
245
|
+
* Each level of recursion uses some of the call stack, interpreted or
|
|
246
|
+
* compiled, so input nested a few thousand levels deep exhausts it. The
|
|
247
|
+
* runners catch the overflow and fail with an unrecoverable `ParseError` of
|
|
248
|
+
* kind `"TooDeep"` at the offset reached, instead of throwing.
|
|
249
|
+
*
|
|
282
250
|
* @example
|
|
283
251
|
* ```ts
|
|
284
252
|
* import { Parser, Token } from "@thomasfosterau/effect-parse"
|
|
@@ -318,8 +286,8 @@ export declare const eof: Parser<void, never, never, Input>;
|
|
|
318
286
|
* @category mapping
|
|
319
287
|
*/
|
|
320
288
|
export declare const map: {
|
|
321
|
-
|
|
322
|
-
|
|
289
|
+
<A, B>(f: (a: A) => B): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E, R, I>;
|
|
290
|
+
<A, E, R, I extends Input, B>(self: Parser<A, E, R, I>, f: (a: A) => B): Parser<B, E, R, I>;
|
|
323
291
|
};
|
|
324
292
|
/**
|
|
325
293
|
* Builds an object from the `[key, value]` entries a parser returns, as
|
|
@@ -352,8 +320,8 @@ export declare const fromEntries: <K extends PropertyKey, V, E, R, I extends Inp
|
|
|
352
320
|
* @category mapping
|
|
353
321
|
*/
|
|
354
322
|
export declare const as: {
|
|
355
|
-
|
|
356
|
-
|
|
323
|
+
<B>(value: B): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E, R, I>;
|
|
324
|
+
<A, E, R, I extends Input, B>(self: Parser<A, E, R, I>, value: B): Parser<B, E, R, I>;
|
|
357
325
|
};
|
|
358
326
|
/**
|
|
359
327
|
* Discards the output of a parser (winnow's `void`).
|
|
@@ -376,8 +344,8 @@ export declare const asSome: <A, E, R, I extends Input>(self: Parser<A, E, R, I>
|
|
|
376
344
|
* @category mapping
|
|
377
345
|
*/
|
|
378
346
|
export declare const tap: {
|
|
379
|
-
|
|
380
|
-
|
|
347
|
+
<A>(f: (a: A) => void): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
|
|
348
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, f: (a: A) => void): Parser<A, E, R, I>;
|
|
381
349
|
};
|
|
382
350
|
/**
|
|
383
351
|
* Uses the output of a parser to choose the parser that consumes the rest
|
|
@@ -387,8 +355,8 @@ export declare const tap: {
|
|
|
387
355
|
* @category sequencing
|
|
388
356
|
*/
|
|
389
357
|
export declare const flatMap: {
|
|
390
|
-
|
|
391
|
-
|
|
358
|
+
<A, B, E2, R2, I2 extends Input>(f: (a: A) => Parser<B, E2, R2, I2>): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E | E2, R | R2, I & I2>;
|
|
359
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, f: (a: A) => Parser<B, E2, R2, I2>): Parser<B, E | E2, R | R2, I & I2>;
|
|
392
360
|
};
|
|
393
361
|
/**
|
|
394
362
|
* Applies a second parser to the *output* of the first (winnow's
|
|
@@ -411,8 +379,8 @@ export declare const flatMap: {
|
|
|
411
379
|
* @category sequencing
|
|
412
380
|
*/
|
|
413
381
|
export declare const mapParser: {
|
|
414
|
-
|
|
415
|
-
|
|
382
|
+
<A extends Input, B, E2, R2>(inner: Parser<B, E2, R2, A>): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E | E2, R | R2, I>;
|
|
383
|
+
<A extends Input, E, R, I extends Input, B, E2, R2>(self: Parser<A, E, R, I>, inner: Parser<B, E2, R2, A>): Parser<B, E | E2, R | R2, I>;
|
|
416
384
|
};
|
|
417
385
|
/**
|
|
418
386
|
* Transforms the output of a parser with a function that may fail with a
|
|
@@ -424,8 +392,8 @@ export declare const mapParser: {
|
|
|
424
392
|
* @category mapping
|
|
425
393
|
*/
|
|
426
394
|
export declare const tryMap: {
|
|
427
|
-
|
|
428
|
-
|
|
395
|
+
<A, B, E2>(f: (a: A) => Result.Result<B, E2>): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E | E2, R, I>;
|
|
396
|
+
<A, E, R, I extends Input, B, E2>(self: Parser<A, E, R, I>, f: (a: A) => Result.Result<B, E2>): Parser<B, E | E2, R, I>;
|
|
429
397
|
};
|
|
430
398
|
/**
|
|
431
399
|
* Like {@link tryMap}, but the function may throw. Thrown values become the
|
|
@@ -435,8 +403,8 @@ export declare const tryMap: {
|
|
|
435
403
|
* @category mapping
|
|
436
404
|
*/
|
|
437
405
|
export declare const tryMapUnknown: {
|
|
438
|
-
|
|
439
|
-
|
|
406
|
+
<A, B>(f: (a: A) => B): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E | unknown, R, I>;
|
|
407
|
+
<A, E, R, I extends Input, B>(self: Parser<A, E, R, I>, f: (a: A) => B): Parser<B, E | unknown, R, I>;
|
|
440
408
|
};
|
|
441
409
|
/**
|
|
442
410
|
* Transforms the output of a parser with a function returning an `Option`;
|
|
@@ -447,8 +415,8 @@ export declare const tryMapUnknown: {
|
|
|
447
415
|
* @category filtering
|
|
448
416
|
*/
|
|
449
417
|
export declare const filterMap: {
|
|
450
|
-
|
|
451
|
-
|
|
418
|
+
<A, B>(f: (a: A) => Option.Option<B>): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E, R, I>;
|
|
419
|
+
<A, E, R, I extends Input, B>(self: Parser<A, E, R, I>, f: (a: A) => Option.Option<B>): Parser<B, E, R, I>;
|
|
452
420
|
};
|
|
453
421
|
/**
|
|
454
422
|
* Keeps the output of a parser only if it satisfies a predicate, otherwise
|
|
@@ -458,10 +426,10 @@ export declare const filterMap: {
|
|
|
458
426
|
* @category filtering
|
|
459
427
|
*/
|
|
460
428
|
export declare const filter: {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
429
|
+
<A, B extends A>(refinement: (a: NoInfer<A>) => a is B): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E, R, I>;
|
|
430
|
+
<A>(predicate: (a: NoInfer<A>) => boolean): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
|
|
431
|
+
<A, E, R, I extends Input, B extends A>(self: Parser<A, E, R, I>, refinement: (a: A) => a is B): Parser<B, E, R, I>;
|
|
432
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, predicate: (a: A) => boolean): Parser<A, E, R, I>;
|
|
465
433
|
};
|
|
466
434
|
/**
|
|
467
435
|
* Keeps the output of a parser only if it satisfies a predicate, otherwise
|
|
@@ -471,10 +439,10 @@ export declare const filter: {
|
|
|
471
439
|
* @category filtering
|
|
472
440
|
*/
|
|
473
441
|
export declare const filterOrFail: {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
442
|
+
<A, B extends A, E2>(refinement: (a: NoInfer<A>) => a is B, orFailWith: (a: NoInfer<A>) => E2): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E | E2, R, I>;
|
|
443
|
+
<A, E2>(predicate: (a: NoInfer<A>) => boolean, orFailWith: (a: NoInfer<A>) => E2): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E | E2, R, I>;
|
|
444
|
+
<A, E, R, I extends Input, B extends A, E2>(self: Parser<A, E, R, I>, refinement: (a: A) => a is B, orFailWith: (a: A) => E2): Parser<B, E | E2, R, I>;
|
|
445
|
+
<A, E, R, I extends Input, E2>(self: Parser<A, E, R, I>, predicate: (a: A) => boolean, orFailWith: (a: A) => E2): Parser<A, E | E2, R, I>;
|
|
478
446
|
};
|
|
479
447
|
/**
|
|
480
448
|
* Returns the slice of input consumed by a parser instead of its output
|
|
@@ -550,8 +518,8 @@ export declare const complete: <A, E, R, I extends Input>(self: Parser<A, E, R,
|
|
|
550
518
|
* @category error management
|
|
551
519
|
*/
|
|
552
520
|
export declare const context: {
|
|
553
|
-
|
|
554
|
-
|
|
521
|
+
(label: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
|
|
522
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, label: string): Parser<A, E, R, I>;
|
|
555
523
|
};
|
|
556
524
|
/**
|
|
557
525
|
* Names what a parser expects. When the parser fails without consuming any
|
|
@@ -563,8 +531,8 @@ export declare const context: {
|
|
|
563
531
|
* @category error management
|
|
564
532
|
*/
|
|
565
533
|
export declare const expected: {
|
|
566
|
-
|
|
567
|
-
|
|
534
|
+
(description: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
|
|
535
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, description: string): Parser<A, E, R, I>;
|
|
568
536
|
};
|
|
569
537
|
/**
|
|
570
538
|
* Transforms the user error (cause) of a parser's failures.
|
|
@@ -573,8 +541,8 @@ export declare const expected: {
|
|
|
573
541
|
* @category error management
|
|
574
542
|
*/
|
|
575
543
|
export declare const mapError: {
|
|
576
|
-
|
|
577
|
-
|
|
544
|
+
<E, E2>(f: (e: E) => E2): <A, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E2, R, I>;
|
|
545
|
+
<A, E, R, I extends Input, E2>(self: Parser<A, E, R, I>, f: (e: E) => E2): Parser<A, E2, R, I>;
|
|
578
546
|
};
|
|
579
547
|
/**
|
|
580
548
|
* Replaces any failure of a parser with the given user error, keeping the
|
|
@@ -584,8 +552,8 @@ export declare const mapError: {
|
|
|
584
552
|
* @category error management
|
|
585
553
|
*/
|
|
586
554
|
export declare const orFail: {
|
|
587
|
-
|
|
588
|
-
|
|
555
|
+
<E2>(error: () => E2): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E2, R, I>;
|
|
556
|
+
<A, E, R, I extends Input, E2>(self: Parser<A, E, R, I>, error: () => E2): Parser<A, E2, R, I>;
|
|
589
557
|
};
|
|
590
558
|
/**
|
|
591
559
|
* If the parser fails recoverably, tries `that` from the same position.
|
|
@@ -595,8 +563,8 @@ export declare const orFail: {
|
|
|
595
563
|
* @category error management
|
|
596
564
|
*/
|
|
597
565
|
export declare const orElse: {
|
|
598
|
-
|
|
599
|
-
|
|
566
|
+
<B, E2, R2, I2 extends Input>(that: () => Parser<B, E2, R2, I2>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A | B, E | E2, R | R2, I & I2>;
|
|
567
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, that: () => Parser<B, E2, R2, I2>): Parser<A | B, E | E2, R | R2, I & I2>;
|
|
600
568
|
};
|
|
601
569
|
/**
|
|
602
570
|
* If the parser fails recoverably, succeeds with the given value without
|
|
@@ -606,8 +574,8 @@ export declare const orElse: {
|
|
|
606
574
|
* @category error management
|
|
607
575
|
*/
|
|
608
576
|
export declare const orElseSucceed: {
|
|
609
|
-
|
|
610
|
-
|
|
577
|
+
<B>(value: () => B): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A | B, E, R, I>;
|
|
578
|
+
<A, E, R, I extends Input, B>(self: Parser<A, E, R, I>, value: () => B): Parser<A | B, E, R, I>;
|
|
611
579
|
};
|
|
612
580
|
/**
|
|
613
581
|
* Makes a parser optional: returns `Option.none()` without consuming input if
|
|
@@ -678,8 +646,8 @@ export declare const struct: <const Fields extends Readonly<Record<string, Parse
|
|
|
678
646
|
* @category sequencing
|
|
679
647
|
*/
|
|
680
648
|
export declare const zip: {
|
|
681
|
-
|
|
682
|
-
|
|
649
|
+
<B, E2, R2, I2 extends Input>(that: Parser<B, E2, R2, I2>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<[A, B], E | E2, R | R2, I & I2>;
|
|
650
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, that: Parser<B, E2, R2, I2>): Parser<[A, B], E | E2, R | R2, I & I2>;
|
|
683
651
|
};
|
|
684
652
|
/**
|
|
685
653
|
* Runs two parsers in sequence and combines their outputs.
|
|
@@ -688,8 +656,8 @@ export declare const zip: {
|
|
|
688
656
|
* @category sequencing
|
|
689
657
|
*/
|
|
690
658
|
export declare const zipWith: {
|
|
691
|
-
|
|
692
|
-
|
|
659
|
+
<B, E2, R2, I2 extends Input, A, C>(that: Parser<B, E2, R2, I2>, f: (a: A, b: B) => C): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<C, E | E2, R | R2, I & I2>;
|
|
660
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input, C>(self: Parser<A, E, R, I>, that: Parser<B, E2, R2, I2>, f: (a: A, b: B) => C): Parser<C, E | E2, R | R2, I & I2>;
|
|
693
661
|
};
|
|
694
662
|
/**
|
|
695
663
|
* Runs two parsers in sequence, keeping the output of the first.
|
|
@@ -698,8 +666,8 @@ export declare const zipWith: {
|
|
|
698
666
|
* @category sequencing
|
|
699
667
|
*/
|
|
700
668
|
export declare const zipLeft: {
|
|
701
|
-
|
|
702
|
-
|
|
669
|
+
<B, E2, R2, I2 extends Input>(that: Parser<B, E2, R2, I2>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E | E2, R | R2, I & I2>;
|
|
670
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, that: Parser<B, E2, R2, I2>): Parser<A, E | E2, R | R2, I & I2>;
|
|
703
671
|
};
|
|
704
672
|
/**
|
|
705
673
|
* Runs two parsers in sequence, keeping the output of the second.
|
|
@@ -708,8 +676,8 @@ export declare const zipLeft: {
|
|
|
708
676
|
* @category sequencing
|
|
709
677
|
*/
|
|
710
678
|
export declare const zipRight: {
|
|
711
|
-
|
|
712
|
-
|
|
679
|
+
<B, E2, R2, I2 extends Input>(that: Parser<B, E2, R2, I2>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E | E2, R | R2, I & I2>;
|
|
680
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, that: Parser<B, E2, R2, I2>): Parser<B, E | E2, R | R2, I & I2>;
|
|
713
681
|
};
|
|
714
682
|
/**
|
|
715
683
|
* Runs `prefix` then `parser`, keeping the output of `parser` (winnow's and
|
|
@@ -759,6 +727,23 @@ export declare const separatedPair: <A1, E1, R1, I1 extends Input, A2, E2, R2, I
|
|
|
759
727
|
* })
|
|
760
728
|
* ```
|
|
761
729
|
*
|
|
730
|
+
* The body runs on every parse, so parsers created inside it, like
|
|
731
|
+
* `Token.literal("=")` above, are rebuilt on every run. On hot paths, build
|
|
732
|
+
* them once outside the body:
|
|
733
|
+
*
|
|
734
|
+
* ```ts
|
|
735
|
+
* import { Ascii, Parser, Token } from "@thomasfosterau/effect-parse"
|
|
736
|
+
*
|
|
737
|
+
* const equals = Token.literal("=")
|
|
738
|
+
*
|
|
739
|
+
* const keyValue = Parser.gen(function*() {
|
|
740
|
+
* const key = yield* Ascii.alpha1
|
|
741
|
+
* yield* equals
|
|
742
|
+
* const value = yield* Ascii.decInt
|
|
743
|
+
* return [key, value] as const
|
|
744
|
+
* })
|
|
745
|
+
* ```
|
|
746
|
+
*
|
|
762
747
|
* @since 0.1.0
|
|
763
748
|
* @category sequencing
|
|
764
749
|
*/
|
|
@@ -780,7 +765,7 @@ export declare const gen: <Eff extends Parser.Any, AEff>(f: () => Generator<Eff,
|
|
|
780
765
|
* @since 0.1.0
|
|
781
766
|
* @category do notation
|
|
782
767
|
*/
|
|
783
|
-
export declare const Do: Parser<
|
|
768
|
+
export declare const Do: Parser<Record<never, never>, never, never, Input>;
|
|
784
769
|
/**
|
|
785
770
|
* Binds the output of a parser to a field of the Do record.
|
|
786
771
|
*
|
|
@@ -788,12 +773,8 @@ export declare const Do: Parser<{}, never, never, Input>;
|
|
|
788
773
|
* @category do notation
|
|
789
774
|
*/
|
|
790
775
|
export declare const bind: {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}>, E | E2, R | R2, I & I2>;
|
|
794
|
-
<A extends object, E, R, I extends Input, N extends string, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Parser<B, E2, R2, I2>): Parser<Simplify<Omit<A, N> & {
|
|
795
|
-
[K in N]: B;
|
|
796
|
-
}>, E | E2, R | R2, I & I2>;
|
|
776
|
+
<N extends string, A extends object, B, E2, R2, I2 extends Input>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Parser<B, E2, R2, I2>): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<Simplify<Omit<A, N> & { [K in N]: B; }>, E | E2, R | R2, I & I2>;
|
|
777
|
+
<A extends object, E, R, I extends Input, N extends string, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => Parser<B, E2, R2, I2>): Parser<Simplify<Omit<A, N> & { [K in N]: B; }>, E | E2, R | R2, I & I2>;
|
|
797
778
|
};
|
|
798
779
|
/**
|
|
799
780
|
* Wraps the output of a parser in a record with a single field.
|
|
@@ -802,29 +783,13 @@ export declare const bind: {
|
|
|
802
783
|
* @category do notation
|
|
803
784
|
*/
|
|
804
785
|
export declare const bindTo: {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
}, E, R, I>;
|
|
808
|
-
<A, E, R, I extends Input, N extends string>(self: Parser<A, E, R, I>, name: N): Parser<{
|
|
809
|
-
[K in N]: A;
|
|
810
|
-
}, E, R, I>;
|
|
786
|
+
<N extends string>(name: N): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<{ [K in N]: A; }, E, R, I>;
|
|
787
|
+
<A, E, R, I extends Input, N extends string>(self: Parser<A, E, R, I>, name: N): Parser<{ [K in N]: A; }, E, R, I>;
|
|
811
788
|
};
|
|
812
789
|
declare const let_: {
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}>, E, R, I>;
|
|
816
|
-
<A extends object, E, R, I extends Input, N extends string, B>(self: Parser<A, E, R, I>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => B): Parser<Simplify<Omit<A, N> & {
|
|
817
|
-
[K in N]: B;
|
|
818
|
-
}>, E, R, I>;
|
|
790
|
+
<N extends string, A extends object, B>(name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => B): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<Simplify<Omit<A, N> & { [K in N]: B; }>, E, R, I>;
|
|
791
|
+
<A extends object, E, R, I extends Input, N extends string, B>(self: Parser<A, E, R, I>, name: Exclude<N, keyof A>, f: (a: NoInfer<A>) => B): Parser<Simplify<Omit<A, N> & { [K in N]: B; }>, E, R, I>;
|
|
819
792
|
};
|
|
820
|
-
export {
|
|
821
|
-
/**
|
|
822
|
-
* Adds a computed field to the Do record.
|
|
823
|
-
*
|
|
824
|
-
* @since 0.1.0
|
|
825
|
-
* @category do notation
|
|
826
|
-
*/
|
|
827
|
-
let_ as let };
|
|
828
793
|
/**
|
|
829
794
|
* Tries each parser in turn and returns the output of the first that
|
|
830
795
|
* succeeds (winnow's and nom's `alt`).
|
|
@@ -847,6 +812,11 @@ export declare const alt: <const Ps extends ReadonlyArray<Parser.Any>>(...parser
|
|
|
847
812
|
* an optional `otherwise` parser for unlisted keys, like winnow's `_ =>`
|
|
848
813
|
* arm), or as a function returning a parser (or `undefined` for no match).
|
|
849
814
|
*
|
|
815
|
+
* Prefer a record where the keys are known. Compiled code (see the
|
|
816
|
+
* `Compiler` module) switches on the key and runs every case compiled; the
|
|
817
|
+
* parser a function returns always runs interpreted, and one the function
|
|
818
|
+
* builds (`(c) => Parser.cut(p)`) is rebuilt on every run.
|
|
819
|
+
*
|
|
850
820
|
* @example
|
|
851
821
|
* ```ts
|
|
852
822
|
* import { Ascii, Parser, Token } from "@thomasfosterau/effect-parse"
|
|
@@ -868,10 +838,8 @@ export declare const alt: <const Ps extends ReadonlyArray<Parser.Any>>(...parser
|
|
|
868
838
|
* @category choice
|
|
869
839
|
*/
|
|
870
840
|
export declare const dispatch: {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
readonly [key in K]?: Parser.Any;
|
|
874
|
-
}, Otherwise extends Parser.Any = never>(selector: Parser<K, E, R, I>, cases: Cases, otherwise?: Otherwise): Parser<Parser.Success<NonNullable<Cases[keyof Cases]> | Otherwise>, E | Parser.Error<NonNullable<Cases[keyof Cases]> | Otherwise>, R | Parser.Services<NonNullable<Cases[keyof Cases]> | Otherwise>, I & Parser.InputOf<NonNullable<Cases[keyof Cases]> | Otherwise>>;
|
|
841
|
+
<K, E, R, I extends Input, P extends Parser.Any>(selector: Parser<K, E, R, I>, cases: (key: K) => P | undefined): Parser<Parser.Success<P>, E | Parser.Error<P>, R | Parser.Services<P>, I & Parser.InputOf<P>>;
|
|
842
|
+
<K extends PropertyKey, E, R, I extends Input, const Cases extends { readonly [key in K]?: Parser.Any; }, Otherwise extends Parser.Any = never>(selector: Parser<K, E, R, I>, cases: Cases, otherwise?: Otherwise): Parser<Parser.Success<NonNullable<Cases[keyof Cases]> | Otherwise>, E | Parser.Error<NonNullable<Cases[keyof Cases]> | Otherwise>, R | Parser.Services<NonNullable<Cases[keyof Cases]> | Otherwise>, I & Parser.InputOf<NonNullable<Cases[keyof Cases]> | Otherwise>>;
|
|
875
843
|
};
|
|
876
844
|
/**
|
|
877
845
|
* Applies every parser exactly once, in whatever order they match, and
|
|
@@ -906,32 +874,52 @@ export declare const permutation: <const Ps extends ReadonlyArray<Parser.Any>>(.
|
|
|
906
874
|
* @category repetition
|
|
907
875
|
*/
|
|
908
876
|
export declare const repeat: {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
877
|
+
<const Rg extends Range = {
|
|
878
|
+
readonly min: 0;
|
|
879
|
+
}>(range?: Rg): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<Repeated<A, Rg>, E, R, I>;
|
|
880
|
+
<A, E, R, I extends Input, const Rg extends Range = {
|
|
881
|
+
readonly min: 0;
|
|
882
|
+
}>(self: Parser<A, E, R, I>, range?: Rg): Parser<Repeated<A, Rg>, E, R, I>;
|
|
915
883
|
};
|
|
916
884
|
/**
|
|
917
885
|
* Applies a parser repeatedly, folding the outputs into an accumulator
|
|
918
886
|
* (winnow's `repeat(..).fold(..)`, nom's `fold_many0`/`fold_many1`/
|
|
919
887
|
* `fold_many_m_n`).
|
|
920
888
|
*
|
|
889
|
+
* With `while`, the repetition also stops, successfully and without
|
|
890
|
+
* consuming more input, as soon as the predicate is false of the
|
|
891
|
+
* accumulator. It is checked before each element once `range.min` elements
|
|
892
|
+
* have been folded, so `min` still holds.
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* ```ts
|
|
896
|
+
* import { Parser, Token } from "@thomasfosterau/effect-parse"
|
|
897
|
+
*
|
|
898
|
+
* // Keeps the first two digits, leaving the rest unparsed
|
|
899
|
+
* const two = Parser.fold(Token.oneOf("0123456789"), {
|
|
900
|
+
* init: () => "",
|
|
901
|
+
* f: (acc, d) => acc + d,
|
|
902
|
+
* while: (acc) => acc.length < 2
|
|
903
|
+
* })
|
|
904
|
+
* Parser.parsePeek(two, "1234") // Result.succeed(["34", "12"])
|
|
905
|
+
* ```
|
|
906
|
+
*
|
|
921
907
|
* @since 0.1.0
|
|
922
908
|
* @category repetition
|
|
923
909
|
*/
|
|
924
910
|
export declare const fold: {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
911
|
+
<A, B>(options: {
|
|
912
|
+
readonly init: () => B;
|
|
913
|
+
readonly f: (acc: B, a: A) => B;
|
|
914
|
+
readonly range?: Range | undefined;
|
|
915
|
+
readonly while?: ((acc: B) => boolean) | undefined;
|
|
916
|
+
}): <E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<B, E, R, I>;
|
|
917
|
+
<A, E, R, I extends Input, B>(self: Parser<A, E, R, I>, options: {
|
|
918
|
+
readonly init: () => B;
|
|
919
|
+
readonly f: (acc: B, a: A) => B;
|
|
920
|
+
readonly range?: Range | undefined;
|
|
921
|
+
readonly while?: ((acc: B) => boolean) | undefined;
|
|
922
|
+
}): Parser<B, E, R, I>;
|
|
935
923
|
};
|
|
936
924
|
/**
|
|
937
925
|
* Applies `self` repeatedly until `end` succeeds, returning the collected
|
|
@@ -942,20 +930,36 @@ export declare const fold: {
|
|
|
942
930
|
* @category repetition
|
|
943
931
|
*/
|
|
944
932
|
export declare const repeatTill: {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
933
|
+
<B, E2, R2, I2 extends Input, const Rg extends Range = {
|
|
934
|
+
readonly min: 0;
|
|
935
|
+
}>(end: Parser<B, E2, R2, I2>, range?: Rg): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<[Repeated<A, Rg>, B], E | E2, R | R2, I & I2>;
|
|
936
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input, const Rg extends Range = {
|
|
937
|
+
readonly min: 0;
|
|
938
|
+
}>(self: Parser<A, E, R, I>, end: Parser<B, E2, R2, I2>, range?: Rg): Parser<[Repeated<A, Rg>, B], E | E2, R | R2, I & I2>;
|
|
951
939
|
};
|
|
940
|
+
/**
|
|
941
|
+
* Applies `self` repeatedly, separated by `separator`, collecting the
|
|
942
|
+
* outputs of `self` (winnow's `separated`, nom's `separated_list0` and
|
|
943
|
+
* `separated_list1`). A trailing separator is not consumed.
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* ```ts
|
|
947
|
+
* import { Ascii, Parser, Token } from "@thomasfosterau/effect-parse"
|
|
948
|
+
*
|
|
949
|
+
* const csv = Parser.separated(Ascii.decInt, Token.literal(","))
|
|
950
|
+
* Parser.parse(csv, "1,2,3") // Result.succeed([1, 2, 3])
|
|
951
|
+
* ```
|
|
952
|
+
*
|
|
953
|
+
* @since 0.1.0
|
|
954
|
+
* @category repetition
|
|
955
|
+
*/
|
|
952
956
|
export declare const separated: {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
957
|
+
<S, E2, R2, I2 extends Input, const Rg extends Range = {
|
|
958
|
+
readonly min: 0;
|
|
959
|
+
}>(separator: Parser<S, E2, R2, I2>, range?: Rg): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<Repeated<A, Rg>, E | E2, R | R2, I & I2>;
|
|
960
|
+
<A, E, R, I extends Input, S, E2, R2, I2 extends Input, const Rg extends Range = {
|
|
961
|
+
readonly min: 0;
|
|
962
|
+
}>(self: Parser<A, E, R, I>, separator: Parser<S, E2, R2, I2>, range?: Rg): Parser<Repeated<A, Rg>, E | E2, R | R2, I & I2>;
|
|
959
963
|
};
|
|
960
964
|
/**
|
|
961
965
|
* Parses one or more `self` separated by `separator`, folding them from the
|
|
@@ -1028,8 +1032,8 @@ export declare const service: <Id, S>(key: Context.Key<Id, S>) => Parser<S, neve
|
|
|
1028
1032
|
* @category services
|
|
1029
1033
|
*/
|
|
1030
1034
|
export declare const provideService: {
|
|
1031
|
-
|
|
1032
|
-
|
|
1035
|
+
<Id, S>(key: Context.Key<Id, S>, service: NoInfer<S>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, Exclude<R, Id>, I>;
|
|
1036
|
+
<A, E, R, I extends Input, Id, S>(self: Parser<A, E, R, I>, key: Context.Key<Id, S>, service: NoInfer<S>): Parser<A, E, Exclude<R, Id>, I>;
|
|
1033
1037
|
};
|
|
1034
1038
|
/**
|
|
1035
1039
|
* Provides a context of services to a parser.
|
|
@@ -1038,8 +1042,8 @@ export declare const provideService: {
|
|
|
1038
1042
|
* @category services
|
|
1039
1043
|
*/
|
|
1040
1044
|
export declare const provide: {
|
|
1041
|
-
|
|
1042
|
-
|
|
1045
|
+
<R2>(context: Context.Context<R2>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, Exclude<R, R2>, I>;
|
|
1046
|
+
<A, E, R, I extends Input, R2>(self: Parser<A, E, R, I>, context: Context.Context<R2>): Parser<A, E, Exclude<R, R2>, I>;
|
|
1043
1047
|
};
|
|
1044
1048
|
/**
|
|
1045
1049
|
* Error recovery: if the parser fails, record the failure, skip input with
|
|
@@ -1052,8 +1056,8 @@ export declare const provide: {
|
|
|
1052
1056
|
* @category error recovery
|
|
1053
1057
|
*/
|
|
1054
1058
|
export declare const resumeAfter: {
|
|
1055
|
-
|
|
1056
|
-
|
|
1059
|
+
<B, E2, R2, I2 extends Input>(recover: Parser<B, E2, R2, I2>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<Option.Option<A>, E | E2, R | R2, I & I2>;
|
|
1060
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, recover: Parser<B, E2, R2, I2>): Parser<Option.Option<A>, E | E2, R | R2, I & I2>;
|
|
1057
1061
|
};
|
|
1058
1062
|
/**
|
|
1059
1063
|
* Error recovery: if the parser fails, record the failure, skip input with
|
|
@@ -1066,8 +1070,8 @@ export declare const resumeAfter: {
|
|
|
1066
1070
|
* @category error recovery
|
|
1067
1071
|
*/
|
|
1068
1072
|
export declare const retryAfter: {
|
|
1069
|
-
|
|
1070
|
-
|
|
1073
|
+
<B, E2, R2, I2 extends Input>(recover: Parser<B, E2, R2, I2>): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E | E2, R | R2, I & I2>;
|
|
1074
|
+
<A, E, R, I extends Input, B, E2, R2, I2 extends Input>(self: Parser<A, E, R, I>, recover: Parser<B, E2, R2, I2>): Parser<A, E | E2, R | R2, I & I2>;
|
|
1071
1075
|
};
|
|
1072
1076
|
/**
|
|
1073
1077
|
* Traces the execution of a parser (winnow's `trace`). When a tracer is
|
|
@@ -1079,8 +1083,8 @@ export declare const retryAfter: {
|
|
|
1079
1083
|
* @category debugging
|
|
1080
1084
|
*/
|
|
1081
1085
|
export declare const trace: {
|
|
1082
|
-
|
|
1083
|
-
|
|
1086
|
+
(name: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
|
|
1087
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, name: string): Parser<A, E, R, I>;
|
|
1084
1088
|
};
|
|
1085
1089
|
/**
|
|
1086
1090
|
* A tracer that writes an indented trace to `console.log`, similar to
|
|
@@ -1090,67 +1094,6 @@ export declare const trace: {
|
|
|
1090
1094
|
* @category debugging
|
|
1091
1095
|
*/
|
|
1092
1096
|
export declare const consoleTracer: (event: TraceEvent) => void;
|
|
1093
|
-
/**
|
|
1094
|
-
* Options for {@link compile}.
|
|
1095
|
-
*
|
|
1096
|
-
* @since 0.1.0
|
|
1097
|
-
* @category compilation
|
|
1098
|
-
*/
|
|
1099
|
-
export interface CompileOptions {
|
|
1100
|
-
/**
|
|
1101
|
-
* Which compiler to use:
|
|
1102
|
-
*
|
|
1103
|
-
* - `"auto"` (the default): generated code (a JIT) where `new Function`
|
|
1104
|
-
* is allowed, otherwise specialized closures
|
|
1105
|
-
* - `"closure"`: specialized closures only. It never generates code, so
|
|
1106
|
-
* it is the choice under a Content Security Policy, where even probing
|
|
1107
|
-
* for `new Function` is reported as a violation.
|
|
1108
|
-
*/
|
|
1109
|
-
readonly backend?: "auto" | "closure" | undefined;
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Compiles a parser into fused, specialized code, and returns the same
|
|
1113
|
-
* parser. Grammars are written as usual; compilation only makes
|
|
1114
|
-
* {@link parse}, {@link parseSync}, {@link parsePeek} and
|
|
1115
|
-
* {@link parseEffect} faster. Compile the root of a grammar once, where it
|
|
1116
|
-
* is defined:
|
|
1117
|
-
*
|
|
1118
|
-
* ```ts
|
|
1119
|
-
* import { Ascii, Parser, Token } from "@thomasfosterau/effect-parse"
|
|
1120
|
-
*
|
|
1121
|
-
* export const list = Parser.compile(
|
|
1122
|
-
* Parser.separated(Ascii.decInt, Token.literal(","))
|
|
1123
|
-
* )
|
|
1124
|
-
* Parser.parse(list, "1,2,3") // Result.succeed([1, 2, 3]), compiled
|
|
1125
|
-
* ```
|
|
1126
|
-
*
|
|
1127
|
-
* The code is generated lazily on the first run, for each kind of input
|
|
1128
|
-
* (string, bytes or array), and cached with the parser.
|
|
1129
|
-
*
|
|
1130
|
-
* **Results and errors are unchanged.** Compiled code records no
|
|
1131
|
-
* diagnostics. When it fails, the parser runs again, interpreted, from the
|
|
1132
|
-
* start, so every `ParseError` (offset, expected, context, cause and
|
|
1133
|
-
* message) is exactly the one the interpreter reports.
|
|
1134
|
-
*
|
|
1135
|
-
* **Callbacks should be pure.** On an input that fails, the callbacks given
|
|
1136
|
-
* to `map`, `filter`, `tryMap`, `tap`, `fold`, ... may run twice, once
|
|
1137
|
-
* compiled and once interpreted. Callbacks whose results are discarded
|
|
1138
|
-
* (a `map` inside `taken` or `preceded`, for example) may not run at all,
|
|
1139
|
-
* nor those of a branch that is certain to fail, and token-set predicates
|
|
1140
|
-
* may be called once per character code and cached.
|
|
1141
|
-
*
|
|
1142
|
-
* Runs on partial input ({@link parsePartial}, `ParserStream`), with
|
|
1143
|
-
* {@link parseRecoverable} or with the `trace` option are always
|
|
1144
|
-
* interpreted. Parsers that can't be described, such as {@link make} and
|
|
1145
|
-
* {@link gen}, run interpreted inside compiled code.
|
|
1146
|
-
*
|
|
1147
|
-
* @since 0.1.0
|
|
1148
|
-
* @category compilation
|
|
1149
|
-
*/
|
|
1150
|
-
export declare const compile: {
|
|
1151
|
-
(options?: CompileOptions): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>;
|
|
1152
|
-
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, options?: CompileOptions): Parser<A, E, R, I>;
|
|
1153
|
-
};
|
|
1154
1097
|
/**
|
|
1155
1098
|
* Options accepted by the runners.
|
|
1156
1099
|
*
|
|
@@ -1158,11 +1101,24 @@ export declare const compile: {
|
|
|
1158
1101
|
* @category running
|
|
1159
1102
|
*/
|
|
1160
1103
|
export interface ParseOptions {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1104
|
+
/**
|
|
1105
|
+
* Install a tracer for {@link trace}d parsers: `true` uses
|
|
1106
|
+
* {@link consoleTracer}.
|
|
1107
|
+
*/
|
|
1108
|
+
readonly trace?: boolean | ((event: TraceEvent) => void) | undefined;
|
|
1109
|
+
/**
|
|
1110
|
+
* Where to start parsing (default `0`): in code units for strings, bytes
|
|
1111
|
+
* for byte input and elements for arrays. The result is that of parsing
|
|
1112
|
+
* `input.slice(offset)`, but without copying the input, and every offset
|
|
1113
|
+
* (`parsePartial`'s `Done`, `location`, spans, `ParseError.offset` and its
|
|
1114
|
+
* line and column) is a position in the whole input. This is what an
|
|
1115
|
+
* incremental driver, such as a lexer reading one token at a time from a
|
|
1116
|
+
* buffer, needs: compiled parsers run compiled from any offset.
|
|
1117
|
+
*
|
|
1118
|
+
* Throws a `RangeError` unless it is an integer from `0` to the input's
|
|
1119
|
+
* length.
|
|
1120
|
+
*/
|
|
1121
|
+
readonly offset?: number | undefined;
|
|
1166
1122
|
}
|
|
1167
1123
|
/**
|
|
1168
1124
|
* Options accepted by the runners for parsers that require services.
|
|
@@ -1171,7 +1127,7 @@ export interface ParseOptions {
|
|
|
1171
1127
|
* @category running
|
|
1172
1128
|
*/
|
|
1173
1129
|
export interface ParseOptionsWithContext<R> extends ParseOptions {
|
|
1174
|
-
|
|
1130
|
+
readonly context: Context.Context<R>;
|
|
1175
1131
|
}
|
|
1176
1132
|
/**
|
|
1177
1133
|
* Runs a parser against a complete input, requiring the whole input to be
|
|
@@ -1190,8 +1146,8 @@ export interface ParseOptionsWithContext<R> extends ParseOptions {
|
|
|
1190
1146
|
* @category running
|
|
1191
1147
|
*/
|
|
1192
1148
|
export declare const parse: {
|
|
1193
|
-
|
|
1194
|
-
|
|
1149
|
+
<A, E, I extends Input>(self: Parser<A, E, never, I>, input: NoInfer<Source<I>>, options?: ParseOptions): Result.Result<A, ParseError.ParseError<E>>;
|
|
1150
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, input: NoInfer<Source<I>>, options: ParseOptionsWithContext<R>): Result.Result<A, ParseError.ParseError<E>>;
|
|
1195
1151
|
};
|
|
1196
1152
|
/**
|
|
1197
1153
|
* Like {@link parse}, but throws the `ParseError` on failure.
|
|
@@ -1200,20 +1156,24 @@ export declare const parse: {
|
|
|
1200
1156
|
* @category running
|
|
1201
1157
|
*/
|
|
1202
1158
|
export declare const parseSync: {
|
|
1203
|
-
|
|
1204
|
-
|
|
1159
|
+
<A, E, I extends Input>(self: Parser<A, E, never, I>, input: NoInfer<Source<I>>, options?: ParseOptions): A;
|
|
1160
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, input: NoInfer<Source<I>>, options: ParseOptionsWithContext<R>): A;
|
|
1205
1161
|
};
|
|
1206
1162
|
/**
|
|
1207
1163
|
* Runs a parser against the start of an input, returning the remaining
|
|
1208
1164
|
* input along with the output, nom-style (winnow's `parse_peek`, nom's
|
|
1209
1165
|
* `IResult`).
|
|
1210
1166
|
*
|
|
1167
|
+
* The parser ended at offset `input.length - remaining.length`, which is
|
|
1168
|
+
* how a caller running from an `offset` (see {@link ParseOptions}) finds
|
|
1169
|
+
* where to continue.
|
|
1170
|
+
*
|
|
1211
1171
|
* @since 0.1.0
|
|
1212
1172
|
* @category running
|
|
1213
1173
|
*/
|
|
1214
1174
|
export declare const parsePeek: {
|
|
1215
|
-
|
|
1216
|
-
|
|
1175
|
+
<A, E, I extends Input>(self: Parser<A, E, never, I>, input: NoInfer<Source<I>>, options?: ParseOptions): Result.Result<[remaining: Slice<I>, output: A], ParseError.ParseError<E>>;
|
|
1176
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, input: NoInfer<Source<I>>, options: ParseOptionsWithContext<R>): Result.Result<[remaining: Slice<I>, output: A], ParseError.ParseError<E>>;
|
|
1217
1177
|
};
|
|
1218
1178
|
/**
|
|
1219
1179
|
* The outcome of parsing a partial (streaming) input.
|
|
@@ -1225,12 +1185,12 @@ export declare const parsePeek: {
|
|
|
1225
1185
|
* @category running
|
|
1226
1186
|
*/
|
|
1227
1187
|
export type PartialResult<A> = {
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1188
|
+
readonly _tag: "Done";
|
|
1189
|
+
readonly value: A;
|
|
1190
|
+
readonly offset: number;
|
|
1231
1191
|
} | {
|
|
1232
|
-
|
|
1233
|
-
|
|
1192
|
+
readonly _tag: "Incomplete";
|
|
1193
|
+
readonly needed: Option.Option<number>;
|
|
1234
1194
|
};
|
|
1235
1195
|
/**
|
|
1236
1196
|
* Runs a parser against a *partial* input, i.e. a chunk of a stream that may
|
|
@@ -1239,7 +1199,14 @@ export type PartialResult<A> = {
|
|
|
1239
1199
|
* of failing or succeeding early.
|
|
1240
1200
|
*
|
|
1241
1201
|
* The parser does not have to consume the whole input; the returned
|
|
1242
|
-
* `offset` says
|
|
1202
|
+
* `offset` says where it stopped. It is a position in the whole input, so
|
|
1203
|
+
* with the `offset` option (see {@link ParseOptions}) it is where the next
|
|
1204
|
+
* parse starts.
|
|
1205
|
+
*
|
|
1206
|
+
* A parser compiled with the `Compiler` module runs compiled, with a build
|
|
1207
|
+
* that handles partial input. When it fails or needs more input, it runs again
|
|
1208
|
+
* interpreted, so `Incomplete`'s `needed` and every `ParseError` are the
|
|
1209
|
+
* interpreter's.
|
|
1243
1210
|
*
|
|
1244
1211
|
* @example
|
|
1245
1212
|
* ```ts
|
|
@@ -1255,8 +1222,8 @@ export type PartialResult<A> = {
|
|
|
1255
1222
|
* @category running
|
|
1256
1223
|
*/
|
|
1257
1224
|
export declare const parsePartial: {
|
|
1258
|
-
|
|
1259
|
-
|
|
1225
|
+
<A, E, I extends Input>(self: Parser<A, E, never, I>, input: NoInfer<Source<I>>, options?: ParseOptions): Result.Result<PartialResult<A>, ParseError.ParseError<E>>;
|
|
1226
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, input: NoInfer<Source<I>>, options: ParseOptionsWithContext<R>): Result.Result<PartialResult<A>, ParseError.ParseError<E>>;
|
|
1260
1227
|
};
|
|
1261
1228
|
/**
|
|
1262
1229
|
* Runs a parser against a complete input as an `Effect`. Services required
|
|
@@ -1277,6 +1244,77 @@ export declare const parsePartial: {
|
|
|
1277
1244
|
* @category running
|
|
1278
1245
|
*/
|
|
1279
1246
|
export declare const parseEffect: <A, E, R, I extends Input>(self: Parser<A, E, R, I>, input: NoInfer<Source<I>>, options?: ParseOptions) => Effect.Effect<A, ParseError.ParseError<E>, R>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Runs a parser on a state you own, from `state.pos`, and returns its output
|
|
1249
|
+
* or {@link Fail}: like calling `self.step(state)`, but using the parser's
|
|
1250
|
+
* compiled form when it has one (see the `Compiler` module). This is the
|
|
1251
|
+
* runner for drivers that make many small runs over one buffer, such as a
|
|
1252
|
+
* lexer reading one token at a time: keep one `Input.State` and
|
|
1253
|
+
* `reset` it (`Input.State.reset`) before each run, and no run allocates a
|
|
1254
|
+
* state, a `Result` or a slice.
|
|
1255
|
+
*
|
|
1256
|
+
* On success the cursor is where the parser stopped. On failure the state
|
|
1257
|
+
* holds the interpreter's failure (`mode`, `failure`, and what
|
|
1258
|
+
* `reportedFailure()` returns): a compiled run that fails is thrown away and
|
|
1259
|
+
* the parser's step runs again from the same position. A partial state
|
|
1260
|
+
* (`partial: true`) runs the compiled build that handles partial input, so
|
|
1261
|
+
* `Incomplete` is reported as the step would report it. Under a tracer,
|
|
1262
|
+
* with recovery on or inside a `Syntax` parse, the step runs interpreted.
|
|
1263
|
+
*
|
|
1264
|
+
* A driver that only needs to know *that* a parser failed (it tries
|
|
1265
|
+
* another, or skips a character) can pass `{ diagnostics: false }` to skip
|
|
1266
|
+
* the interpreted re-run; see {@link RunOptions}.
|
|
1267
|
+
*
|
|
1268
|
+
* Compiled code records no hints or furthest failure when it succeeds, so
|
|
1269
|
+
* a later failure on the same state can list fewer expectations than one
|
|
1270
|
+
* after interpreted runs would: reset the state between runs (as above) and
|
|
1271
|
+
* its errors are the ones {@link parse} reports. Deep nesting fails with an
|
|
1272
|
+
* unrecoverable `TooDeep` failure instead of throwing, as in the other
|
|
1273
|
+
* runners.
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```ts
|
|
1277
|
+
* import { Ascii, Compiler, Input, Parser, Token } from "@thomasfosterau/effect-parse"
|
|
1278
|
+
*
|
|
1279
|
+
* const token = Compiler.jit(Parser.preceded(Ascii.space0, Parser.alt(Ascii.alpha1, Token.oneOf("+-"))))
|
|
1280
|
+
*
|
|
1281
|
+
* const tokens = (text: string): Array<string> => {
|
|
1282
|
+
* const state = new Input.State(text)
|
|
1283
|
+
* const out: Array<string> = []
|
|
1284
|
+
* while (state.pos < state.end) {
|
|
1285
|
+
* const t = Parser.run(token, state.reset(state.pos))
|
|
1286
|
+
* if (t === Input.Fail) break
|
|
1287
|
+
* out.push(t)
|
|
1288
|
+
* }
|
|
1289
|
+
* return out
|
|
1290
|
+
* }
|
|
1291
|
+
*
|
|
1292
|
+
* tokens("a + b") // ["a", "+", "b"]
|
|
1293
|
+
* ```
|
|
1294
|
+
*
|
|
1295
|
+
* @since 0.2.0
|
|
1296
|
+
* @category running
|
|
1297
|
+
*/
|
|
1298
|
+
export declare const run: <A, E, R, I extends Input>(self: Parser<A, E, R, I>, state: State<I>, options?: RunOptions) => A | Fail;
|
|
1299
|
+
/**
|
|
1300
|
+
* Options for {@link run}.
|
|
1301
|
+
*
|
|
1302
|
+
* @since 0.2.0
|
|
1303
|
+
* @category running
|
|
1304
|
+
*/
|
|
1305
|
+
export interface RunOptions {
|
|
1306
|
+
/**
|
|
1307
|
+
* Whether a failure records the interpreter's diagnostics (default
|
|
1308
|
+
* `true`). With `false`, a compiled run that fails is not run again
|
|
1309
|
+
* interpreted: the state's `mode` (`Backtrack`, `Cut` or `Incomplete`)
|
|
1310
|
+
* is set and the cursor is back where the run started, but `failure`,
|
|
1311
|
+
* hints and the furthest failure are left as they were. For drivers that
|
|
1312
|
+
* try a parser and move on when it fails, without reporting why, this
|
|
1313
|
+
* halves the cost of each failure. Parsers that run interpreted record
|
|
1314
|
+
* their diagnostics either way.
|
|
1315
|
+
*/
|
|
1316
|
+
readonly diagnostics?: boolean | undefined;
|
|
1317
|
+
}
|
|
1280
1318
|
/**
|
|
1281
1319
|
* The outcome of {@link parseRecoverable}.
|
|
1282
1320
|
*
|
|
@@ -1284,10 +1322,10 @@ export declare const parseEffect: <A, E, R, I extends Input>(self: Parser<A, E,
|
|
|
1284
1322
|
* @category running
|
|
1285
1323
|
*/
|
|
1286
1324
|
export interface RecoverableResult<A, E> {
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1325
|
+
/** The output, if parsing ultimately succeeded. */
|
|
1326
|
+
readonly value: Option.Option<A>;
|
|
1327
|
+
/** Every error encountered: recovered ones, then the fatal one (if any). */
|
|
1328
|
+
readonly errors: ReadonlyArray<ParseError.ParseError<E>>;
|
|
1291
1329
|
}
|
|
1292
1330
|
/**
|
|
1293
1331
|
* Runs a parser with error recovery enabled (winnow's `Recoverable`
|
|
@@ -1298,15 +1336,9 @@ export interface RecoverableResult<A, E> {
|
|
|
1298
1336
|
* @category running
|
|
1299
1337
|
*/
|
|
1300
1338
|
export declare const parseRecoverable: {
|
|
1301
|
-
|
|
1302
|
-
|
|
1339
|
+
<A, E, I extends Input>(self: Parser<A, E, never, I>, input: NoInfer<Source<I>>, options?: ParseOptions): RecoverableResult<A, E>;
|
|
1340
|
+
<A, E, R, I extends Input>(self: Parser<A, E, R, I>, input: NoInfer<Source<I>>, options: ParseOptionsWithContext<R>): RecoverableResult<A, E>;
|
|
1303
1341
|
};
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
* convenience.
|
|
1307
|
-
*
|
|
1308
|
-
* @since 0.1.0
|
|
1309
|
-
* @category models
|
|
1310
|
-
*/
|
|
1311
|
-
export type { ErrorKind };
|
|
1342
|
+
//#endregion
|
|
1343
|
+
export { type ErrorKind, let_ as let, void_ as void };
|
|
1312
1344
|
//# sourceMappingURL=Parser.d.ts.map
|