@thomasfosterau/effect-parse 0.0.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.
Files changed (155) hide show
  1. package/README.md +247 -230
  2. package/dist/Ascii.d.ts +32 -53
  3. package/dist/Ascii.d.ts.map +1 -1
  4. package/dist/Ascii.js +576 -571
  5. package/dist/Ascii.js.map +1 -1
  6. package/dist/Binary.d.ts +6 -29
  7. package/dist/Binary.d.ts.map +1 -1
  8. package/dist/Binary.js +129 -116
  9. package/dist/Binary.js.map +1 -1
  10. package/dist/Bits.d.ts +4 -2
  11. package/dist/Bits.d.ts.map +1 -1
  12. package/dist/Bits.js +121 -123
  13. package/dist/Bits.js.map +1 -1
  14. package/dist/Compiler.d.ts +39 -0
  15. package/dist/Compiler.d.ts.map +1 -0
  16. package/dist/Compiler.js +48 -0
  17. package/dist/Compiler.js.map +1 -0
  18. package/dist/Encoding.d.ts +29 -46
  19. package/dist/Encoding.d.ts.map +1 -1
  20. package/dist/Encoding.js +76 -75
  21. package/dist/Encoding.js.map +1 -1
  22. package/dist/Expression.d.ts +15 -49
  23. package/dist/Expression.d.ts.map +1 -1
  24. package/dist/Expression.js +143 -131
  25. package/dist/Expression.js.map +1 -1
  26. package/dist/Input.d.ts +206 -177
  27. package/dist/Input.d.ts.map +1 -1
  28. package/dist/Input.js +317 -299
  29. package/dist/Input.js.map +1 -1
  30. package/dist/Nom.d.ts +44 -84
  31. package/dist/Nom.d.ts.map +1 -1
  32. package/dist/Nom.js +423 -453
  33. package/dist/Nom.js.map +1 -1
  34. package/dist/ParseError.d.ts +54 -49
  35. package/dist/ParseError.d.ts.map +1 -1
  36. package/dist/ParseError.js +233 -275
  37. package/dist/ParseError.js.map +1 -1
  38. package/dist/Parser.d.ts +345 -313
  39. package/dist/Parser.d.ts.map +1 -1
  40. package/dist/Parser.js +2010 -1802
  41. package/dist/Parser.js.map +1 -1
  42. package/dist/ParserSchema.d.ts +8 -7
  43. package/dist/ParserSchema.d.ts.map +1 -1
  44. package/dist/ParserSchema.js +49 -49
  45. package/dist/ParserSchema.js.map +1 -1
  46. package/dist/ParserStream.d.ts +26 -20
  47. package/dist/ParserStream.d.ts.map +1 -1
  48. package/dist/ParserStream.js +267 -255
  49. package/dist/ParserStream.js.map +1 -1
  50. package/dist/Syntax.d.ts +401 -0
  51. package/dist/Syntax.d.ts.map +1 -0
  52. package/dist/Syntax.js +717 -0
  53. package/dist/Syntax.js.map +1 -0
  54. package/dist/Text.d.ts +98 -134
  55. package/dist/Text.d.ts.map +1 -1
  56. package/dist/Text.js +534 -496
  57. package/dist/Text.js.map +1 -1
  58. package/dist/Token.d.ts +60 -42
  59. package/dist/Token.d.ts.map +1 -1
  60. package/dist/Token.js +331 -265
  61. package/dist/Token.js.map +1 -1
  62. package/dist/index.d.ts +16 -17
  63. package/dist/index.js +16 -17
  64. package/dist/internal/compiler/closure.d.ts +14 -16
  65. package/dist/internal/compiler/closure.d.ts.map +1 -1
  66. package/dist/internal/compiler/closure.js +1458 -1637
  67. package/dist/internal/compiler/closure.js.map +1 -1
  68. package/dist/internal/compiler/entries.d.ts +11 -11
  69. package/dist/internal/compiler/entries.d.ts.map +1 -1
  70. package/dist/internal/compiler/entries.js +36 -26
  71. package/dist/internal/compiler/entries.js.map +1 -1
  72. package/dist/internal/compiler/first.d.ts +19 -19
  73. package/dist/internal/compiler/first.d.ts.map +1 -1
  74. package/dist/internal/compiler/first.js +251 -227
  75. package/dist/internal/compiler/first.js.map +1 -1
  76. package/dist/internal/compiler/jit.d.ts +6 -17
  77. package/dist/internal/compiler/jit.d.ts.map +1 -1
  78. package/dist/internal/compiler/jit.js +860 -988
  79. package/dist/internal/compiler/jit.js.map +1 -1
  80. package/dist/internal/compiler/registry.d.ts +20 -21
  81. package/dist/internal/compiler/registry.d.ts.map +1 -1
  82. package/dist/internal/compiler/registry.js +21 -41
  83. package/dist/internal/compiler/registry.js.map +1 -1
  84. package/dist/internal/compiler/sets.d.ts +9 -13
  85. package/dist/internal/compiler/sets.d.ts.map +1 -1
  86. package/dist/internal/compiler/sets.js +76 -73
  87. package/dist/internal/compiler/sets.js.map +1 -1
  88. package/dist/internal/entries.d.ts +3 -3
  89. package/dist/internal/entries.d.ts.map +1 -1
  90. package/dist/internal/entries.js +38 -30
  91. package/dist/internal/entries.js.map +1 -1
  92. package/dist/internal/node.d.ts +177 -173
  93. package/dist/internal/node.d.ts.map +1 -1
  94. package/dist/internal/node.js +77 -66
  95. package/dist/internal/node.js.map +1 -1
  96. package/dist/internal/numbers.d.ts +7 -8
  97. package/dist/internal/numbers.d.ts.map +1 -1
  98. package/dist/internal/numbers.js +246 -276
  99. package/dist/internal/numbers.js.map +1 -1
  100. package/dist/internal/resume.d.ts +6 -24
  101. package/dist/internal/resume.d.ts.map +1 -1
  102. package/dist/internal/resume.js +30 -29
  103. package/dist/internal/resume.js.map +1 -1
  104. package/dist/internal/run.d.ts +15 -0
  105. package/dist/internal/run.d.ts.map +1 -0
  106. package/dist/internal/run.js +36 -0
  107. package/dist/internal/run.js.map +1 -0
  108. package/dist/internal/stack.d.ts +16 -0
  109. package/dist/internal/stack.d.ts.map +1 -0
  110. package/dist/internal/stack.js +26 -0
  111. package/dist/internal/stack.js.map +1 -0
  112. package/dist/internal/syntax.d.ts +146 -0
  113. package/dist/internal/syntax.d.ts.map +1 -0
  114. package/dist/internal/syntax.js +305 -0
  115. package/dist/internal/syntax.js.map +1 -0
  116. package/dist/internal/text.d.ts +10 -2
  117. package/dist/internal/text.d.ts.map +1 -1
  118. package/dist/internal/text.js +295 -345
  119. package/dist/internal/text.js.map +1 -1
  120. package/dist/internal/tokens.d.ts +25 -30
  121. package/dist/internal/tokens.d.ts.map +1 -1
  122. package/dist/internal/tokens.js +369 -363
  123. package/dist/internal/tokens.js.map +1 -1
  124. package/package.json +42 -28
  125. package/src/Ascii.ts +278 -187
  126. package/src/Binary.ts +150 -44
  127. package/src/Bits.ts +6 -3
  128. package/src/Compiler.ts +98 -0
  129. package/src/Expression.ts +10 -5
  130. package/src/Input.ts +106 -28
  131. package/src/Nom.ts +4 -3
  132. package/src/ParseError.ts +48 -51
  133. package/src/Parser.ts +1163 -795
  134. package/src/ParserStream.ts +104 -80
  135. package/src/Syntax.ts +900 -0
  136. package/src/Text.ts +272 -187
  137. package/src/Token.ts +180 -87
  138. package/src/index.ts +2 -0
  139. package/src/internal/compiler/closure.ts +121 -88
  140. package/src/internal/compiler/entries.ts +21 -8
  141. package/src/internal/compiler/first.ts +17 -15
  142. package/src/internal/compiler/jit.ts +360 -157
  143. package/src/internal/compiler/registry.ts +12 -33
  144. package/src/internal/compiler/sets.ts +17 -11
  145. package/src/internal/entries.ts +4 -2
  146. package/src/internal/node.ts +51 -37
  147. package/src/internal/numbers.ts +22 -20
  148. package/src/internal/resume.ts +8 -4
  149. package/src/internal/run.ts +41 -0
  150. package/src/internal/stack.ts +36 -0
  151. package/src/internal/syntax.ts +421 -0
  152. package/src/internal/text.ts +32 -25
  153. package/src/internal/tokens.ts +96 -51
  154. package/dist/index.d.ts.map +0 -1
  155. package/dist/index.js.map +0 -1
package/dist/Input.d.ts CHANGED
@@ -1,20 +1,8 @@
1
- /**
2
- * Input types and the mutable parse {@link State} cursor.
3
- *
4
- * Like winnow, effect-parse parsers advance a mutable cursor rather than
5
- * returning the remaining input. A {@link State} wraps the original input
6
- * together with the current offset, the streaming (partial) flag, the
7
- * services available to the parser, and the details of the most recent
8
- * failure.
9
- *
10
- * Most users never touch `State` directly. It is exposed for writing custom
11
- * low-level parsers with `Parser.make`.
12
- *
13
- * @since 0.1.0
14
- */
15
1
  import * as Context from "effect/Context";
16
- import type { Encoding } from "./Encoding.js";
17
- import type { ErrorKind } from "./ParseError.js";
2
+ import { ErrorKind } from "./ParseError.js";
3
+ import { Builder } from "./internal/syntax.js";
4
+ import { Encoding } from "./Encoding.js";
5
+ //#region src/Input.d.ts
18
6
  /**
19
7
  * The kinds of input a parser can consume.
20
8
  *
@@ -63,8 +51,8 @@ export type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never);
63
51
  * @category constructors
64
52
  */
65
53
  export declare const fromSource: {
66
- (source: BinaryInput): Uint8Array;
67
- <I extends Input>(source: Source<I>): I;
54
+ (source: BinaryInput): Uint8Array;
55
+ <I extends Input>(source: Source<I>): I;
68
56
  };
69
57
  /**
70
58
  * The type of a single token of an input.
@@ -111,39 +99,39 @@ export type ErrMode = "Backtrack" | "Cut" | "Incomplete";
111
99
  * @category failure
112
100
  */
113
101
  export declare class Failure {
114
- /** Offset into the input where the failure occurred. */
115
- readonly offset: number;
116
- /** The kind of parser that failed. */
117
- readonly kind: ErrorKind;
118
- /** Rendered descriptions of what was expected at `offset`. */
119
- readonly expected: ReadonlyArray<string>;
120
- /** Context labels added by `Parser.context`, innermost first. */
121
- readonly context: ReadonlyArray<string>;
122
- /** Whether a user supplied cause is present. */
123
- readonly hasCause: boolean;
124
- /** A user supplied (typed) cause. */
125
- readonly cause: unknown;
126
- /** An optional free-form message. */
127
- readonly message: string | undefined;
128
- /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */
129
- readonly needed: number;
130
- constructor(
131
- /** Offset into the input where the failure occurred. */
132
- offset: number,
133
- /** The kind of parser that failed. */
134
- kind: ErrorKind,
135
- /** Rendered descriptions of what was expected at `offset`. */
136
- expected: ReadonlyArray<string>,
137
- /** Context labels added by `Parser.context`, innermost first. */
138
- context: ReadonlyArray<string>,
139
- /** Whether a user supplied cause is present. */
140
- hasCause: boolean,
141
- /** A user supplied (typed) cause. */
142
- cause: unknown,
143
- /** An optional free-form message. */
144
- message: string | undefined,
145
- /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */
146
- needed: number);
102
+ /** Offset into the input where the failure occurred. */
103
+ readonly offset: number;
104
+ /** The kind of parser that failed. */
105
+ readonly kind: ErrorKind;
106
+ /** Rendered descriptions of what was expected at `offset`. */
107
+ readonly expected: ReadonlyArray<string>;
108
+ /** Context labels added by `Parser.context`, innermost first. */
109
+ readonly context: ReadonlyArray<string>;
110
+ /** Whether a user supplied cause is present. */
111
+ readonly hasCause: boolean;
112
+ /** A user supplied (typed) cause. */
113
+ readonly cause: unknown;
114
+ /** An optional free-form message. */
115
+ readonly message: string | undefined;
116
+ /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */
117
+ readonly needed: number;
118
+ constructor(
119
+ /** Offset into the input where the failure occurred. */
120
+ offset: number,
121
+ /** The kind of parser that failed. */
122
+ kind: ErrorKind,
123
+ /** Rendered descriptions of what was expected at `offset`. */
124
+ expected: ReadonlyArray<string>,
125
+ /** Context labels added by `Parser.context`, innermost first. */
126
+ context: ReadonlyArray<string>,
127
+ /** Whether a user supplied cause is present. */
128
+ hasCause: boolean,
129
+ /** A user supplied (typed) cause. */
130
+ cause: unknown,
131
+ /** An optional free-form message. */
132
+ message: string | undefined,
133
+ /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */
134
+ needed: number);
147
135
  }
148
136
  /** @internal */
149
137
  export declare const emptyStrings: readonly string[];
@@ -154,15 +142,15 @@ export declare const emptyStrings: readonly string[];
154
142
  * @category tracing
155
143
  */
156
144
  export interface TraceEvent {
157
- readonly _tag: "Enter" | "Exit";
158
- readonly name: string;
159
- readonly depth: number;
160
- readonly offset: number;
161
- /** For `Exit` events: the outcome. */
162
- readonly result?: "Ok" | ErrMode;
163
- /** For `Exit` events: the offset reached. */
164
- readonly endOffset?: number;
165
- readonly state: State;
145
+ readonly _tag: "Enter" | "Exit";
146
+ readonly name: string;
147
+ readonly depth: number;
148
+ readonly offset: number;
149
+ /** For `Exit` events: the outcome. */
150
+ readonly result?: "Ok" | ErrMode;
151
+ /** For `Exit` events: the offset reached. */
152
+ readonly endOffset?: number;
153
+ readonly state: State;
166
154
  }
167
155
  /**
168
156
  * The mutable parsing cursor.
@@ -171,123 +159,163 @@ export interface TraceEvent {
171
159
  * @category models
172
160
  */
173
161
  export declare class State<I extends Input = Input> {
174
- /** The full input being parsed. */
175
- readonly input: I;
176
- /** The current offset. Advanced by parsers, rewound on backtracking. */
177
- pos: number;
178
- /** The end offset (the input's length; in bits inside `Bits.bits`). */
179
- end: number;
180
- /** 0 = string, 1 = Uint8Array, 2 = array. */
181
- readonly inputKind: 0 | 1 | 2;
182
- /** Whether the input is partial (streaming): running out yields `Incomplete`. */
183
- partial: boolean;
184
- /** Services available to `Parser.service`. */
185
- context: Context.Context<never>;
186
- /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */
187
- mode: ErrMode;
188
- /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */
189
- failure: Failure;
190
- /**
191
- * The offset of a recoverable failure that occurred without consuming
192
- * input (for example the last attempt of a `repeat`). Its
193
- * expectations are merged into new failures at the same offset, producing
194
- * messages like `expected digit or ")"`.
195
- */
196
- hintOffset: number;
197
- /** The expectations of the hint at {@link hintOffset}. */
198
- hintExpected: ReadonlyArray<string>;
199
- /**
200
- * The furthest recoverable failure seen so far, including failures that
201
- * were later swallowed by backtracking (for example a trailing separator
202
- * followed by an invalid element). It is reported instead of the final
203
- * failure when it lies further into the input. This is the classic PEG
204
- * "farthest failure" heuristic.
205
- */
206
- deepest: Failure | undefined;
207
- /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */
208
- recovered: Array<Failure> | undefined;
209
- /** When defined, `Parser.trace` reports events here. */
210
- tracer: ((event: TraceEvent) => void) | undefined;
211
- /** Current tracing depth. */
212
- depth: number;
213
- /**
214
- * The text encoding of a byte input, recorded by `Text` parsers when they
215
- * fail so that errors can show the input as text.
216
- */
217
- encoding: Encoding<any> | undefined;
218
- /**
219
- * The checkpoints of a resumable streaming parse (see
220
- * `ParserStream.parseAll`); `undefined` otherwise.
221
- *
222
- * @internal
223
- */
224
- resume: Map<object, Map<number, unknown>> | undefined;
225
- constructor(source: I | Source<I>, options?: {
226
- readonly partial?: boolean | undefined;
227
- readonly context?: Context.Context<never> | undefined;
228
- readonly offset?: number | undefined;
229
- });
230
- /**
231
- * The number of input units (code units, bytes or elements) remaining.
232
- */
233
- remaining(): number;
234
- /**
235
- * Whether the cursor is at the end of the input.
236
- */
237
- atEnd(): boolean;
238
- /**
239
- * Extracts the slice `[start, end)` of the input.
240
- */
241
- slice(start: number, end: number): Slice<I>;
242
- /**
243
- * Records a recoverable failure at the current offset and returns {@link Fail}.
244
- */
245
- backtrack(kind: ErrorKind, expected?: ReadonlyArray<string>, offset?: number): Fail;
246
- /**
247
- * Records an unrecoverable failure at the current offset and returns {@link Fail}.
248
- */
249
- cut(kind: ErrorKind, expected?: ReadonlyArray<string>, offset?: number): Fail;
250
- /**
251
- * Records an `Incomplete` failure (only meaningful for partial input) and
252
- * returns {@link Fail}.
253
- */
254
- incomplete(needed: number, expected?: ReadonlyArray<string>): Fail;
255
- /**
256
- * Fails because the input ended: `Incomplete` for partial input, otherwise
257
- * a `Backtrack` failure of the given kind.
258
- */
259
- eoi(kind: ErrorKind, expected: ReadonlyArray<string>, needed: number): Fail;
260
- /**
261
- * Records a failure carrying a user supplied cause.
262
- */
263
- failCause(mode: ErrMode, kind: ErrorKind, cause: unknown, offset?: number): Fail;
264
- /**
265
- * Records a failure carrying a message.
266
- */
267
- failMessage(mode: ErrMode, kind: ErrorKind, message: string, offset?: number): Fail;
268
- /**
269
- * Records the given failure and returns {@link Fail}.
270
- */
271
- failWith(mode: ErrMode, failure: Failure): Fail;
272
- /**
273
- * Replaces the details of the current failure (for example to add context),
274
- * keeping the record of the furthest failure consistent.
275
- */
276
- replaceFailure(failure: Failure): void;
277
- /**
278
- * The failure to report to the user: the current failure, or the furthest
279
- * failure if it lies beyond the current one and the current failure is a
280
- * plain syntax error (no user cause or message).
281
- */
282
- reportedFailure(): Failure;
283
- /**
284
- * Records that, at `offset`, any of `expected` could also have been
285
- * accepted. Used by parsers that stop without failing, such as `opt`,
286
- * `repeat` and `Ascii.digit1`.
287
- */
288
- setHint(offset: number, expected: ReadonlyArray<string>): void;
289
- /** @internal */
290
- makeFailure(offset: number, kind: ErrorKind, expected: ReadonlyArray<string>): Failure;
162
+ /** The full input being parsed. */
163
+ readonly input: I;
164
+ /** The current offset. Advanced by parsers, rewound on backtracking. */
165
+ pos: number;
166
+ /** The end offset (the input's length; in bits inside `Bits.bits`). */
167
+ end: number;
168
+ /** 0 = string, 1 = Uint8Array, 2 = array. */
169
+ readonly inputKind: 0 | 1 | 2;
170
+ /** Whether the input is partial (streaming): running out yields `Incomplete`. */
171
+ partial: boolean;
172
+ /** Services available to `Parser.service`. */
173
+ context: Context.Context<never>;
174
+ /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */
175
+ mode: ErrMode;
176
+ /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */
177
+ failure: Failure;
178
+ /**
179
+ * The offset of a recoverable failure that occurred without consuming
180
+ * input (for example the last attempt of a `repeat`). Its
181
+ * expectations are merged into new failures at the same offset, producing
182
+ * messages like `expected digit or ")"`.
183
+ */
184
+ hintOffset: number;
185
+ /** The expectations of the hint at {@link hintOffset}. */
186
+ hintExpected: ReadonlyArray<string>;
187
+ /**
188
+ * The furthest recoverable failure seen so far, including failures that
189
+ * were later swallowed by backtracking (for example a trailing separator
190
+ * followed by an invalid element). It is reported instead of the final
191
+ * failure when it lies further into the input. This is the classic PEG
192
+ * "farthest failure" heuristic. `Parser.cut` keeps only the failures
193
+ * recorded inside it when it commits, and `Parser.peek` and `Parser.not`
194
+ * forget the failures of a lookahead that succeeded.
195
+ */
196
+ deepest: Failure | undefined;
197
+ /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */
198
+ recovered: Array<Failure> | undefined;
199
+ /** When defined, `Parser.trace` reports events here. */
200
+ tracer: ((event: TraceEvent) => void) | undefined;
201
+ /** Current tracing depth. */
202
+ depth: number;
203
+ /**
204
+ * The text encoding of a byte input, recorded by `Text` parsers when they
205
+ * fail so that errors can show the input as text.
206
+ */
207
+ encoding: Encoding<any> | undefined;
208
+ /**
209
+ * The checkpoints of a resumable streaming parse (see
210
+ * `ParserStream.parseAll`); `undefined` otherwise.
211
+ *
212
+ * @internal
213
+ */
214
+ resume: Map<object, Map<number, unknown>> | undefined;
215
+ /**
216
+ * The tree builder of a `Syntax` parse; `undefined` otherwise.
217
+ *
218
+ * @internal
219
+ */
220
+ syntax: Builder | undefined;
221
+ constructor(source: I | Source<I>, options?: {
222
+ readonly partial?: boolean | undefined;
223
+ readonly context?: Context.Context<never> | undefined;
224
+ readonly offset?: number | undefined;
225
+ });
226
+ /**
227
+ * Prepares the state for another run over the same input, starting at
228
+ * `offset`: afterwards it behaves exactly like
229
+ * `new State(state.input, { ...options, offset })`, without allocating a
230
+ * new state.
231
+ *
232
+ * Every per-run field is reset: the cursor and end, the latest failure,
233
+ * hints and furthest failure, recorded recoveries, the tracer and tracing
234
+ * depth, the recorded encoding and streaming checkpoints. Like the
235
+ * constructor, `partial` defaults to `false` and `context` to the empty
236
+ * context, so pass them again on every reset.
237
+ *
238
+ * Use it to run many small parses over one buffer, for example one per
239
+ * token, with `parser.step`. A state can be reused after any run,
240
+ * including one that failed, returned `Incomplete` or threw.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * import { Ascii, Input } from "@thomasfosterau/effect-parse"
245
+ *
246
+ * const state = new Input.State("12 34")
247
+ * Ascii.decUint.step(state) // 12
248
+ * state.reset(3)
249
+ * Ascii.decUint.step(state) // 34
250
+ * ```
251
+ *
252
+ * @since 0.2.0
253
+ */
254
+ reset(offset?: number, options?: {
255
+ readonly partial?: boolean | undefined;
256
+ readonly context?: Context.Context<never> | undefined;
257
+ }): this;
258
+ /**
259
+ * The number of input units (code units, bytes or elements) remaining.
260
+ */
261
+ remaining(): number;
262
+ /**
263
+ * Whether the cursor is at the end of the input.
264
+ */
265
+ atEnd(): boolean;
266
+ /**
267
+ * Extracts the slice `[start, end)` of the input.
268
+ */
269
+ slice(start: number, end: number): Slice<I>;
270
+ /**
271
+ * Records a recoverable failure at the current offset and returns {@link Fail}.
272
+ */
273
+ backtrack(kind: ErrorKind, expected?: ReadonlyArray<string>, offset?: number): Fail;
274
+ /**
275
+ * Records an unrecoverable failure at the current offset and returns {@link Fail}.
276
+ */
277
+ cut(kind: ErrorKind, expected?: ReadonlyArray<string>, offset?: number): Fail;
278
+ /**
279
+ * Records an `Incomplete` failure (only meaningful for partial input) and
280
+ * returns {@link Fail}.
281
+ */
282
+ incomplete(needed: number, expected?: ReadonlyArray<string>): Fail;
283
+ /**
284
+ * Fails because the input ended: `Incomplete` for partial input, otherwise
285
+ * a `Backtrack` failure of the given kind.
286
+ */
287
+ eoi(kind: ErrorKind, expected: ReadonlyArray<string>, needed: number): Fail;
288
+ /**
289
+ * Records a failure carrying a user supplied cause.
290
+ */
291
+ failCause(mode: ErrMode, kind: ErrorKind, cause: unknown, offset?: number): Fail;
292
+ /**
293
+ * Records a failure carrying a message.
294
+ */
295
+ failMessage(mode: ErrMode, kind: ErrorKind, message: string, offset?: number): Fail;
296
+ /**
297
+ * Records the given failure and returns {@link Fail}.
298
+ */
299
+ failWith(mode: ErrMode, failure: Failure): Fail;
300
+ /**
301
+ * Replaces the details of the current failure (for example to add context),
302
+ * keeping the record of the furthest failure consistent.
303
+ */
304
+ replaceFailure(failure: Failure): void;
305
+ /**
306
+ * The failure to report to the user: the current failure, or the furthest
307
+ * failure if it lies beyond the current one and the current failure is a
308
+ * plain syntax error (no user cause or message).
309
+ */
310
+ reportedFailure(): Failure;
311
+ /**
312
+ * Records that, at `offset`, any of `expected` could also have been
313
+ * accepted. Used by parsers that stop without failing, such as `opt`,
314
+ * `repeat` and `Ascii.digit1`.
315
+ */
316
+ setHint(offset: number, expected: ReadonlyArray<string>): void;
317
+ /** @internal */
318
+ makeFailure(offset: number, kind: ErrorKind, expected: ReadonlyArray<string>): Failure;
291
319
  }
292
320
  /** @internal */
293
321
  export declare const mergeExpected: (a: ReadonlyArray<string>, b: ReadonlyArray<string>) => ReadonlyArray<string>;
@@ -298,4 +326,5 @@ export declare const mergeExpected: (a: ReadonlyArray<string>, b: ReadonlyArray<
298
326
  * @internal
299
327
  */
300
328
  export declare const mergeFailures: (a: Failure, b: Failure) => Failure;
329
+ //#endregion
301
330
  //# sourceMappingURL=Input.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../src/Input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;AAEhE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,eAAe,CAAA;AAE3D;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,WAAW,GAAG,KAAK,CAAC,CAAA;AAE5E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,EAAE;IACvB,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,CAAA;IACjC,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;CAOxC,CAAA;AAKD;;;;;GAKG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAC5C,CAAC,SAAS,UAAU,GAAG,MAAM,GAC7B,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GACpC,KAAK,CAAA;AAET;;;;;GAKG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAC5C,CAAC,SAAS,UAAU,GAAG,UAAU,GACjC,CAAC,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