Skip to content

Commit 6e45c5d

Browse files
wolthomGeal
andauthored
Remove duplicated section from error_management.md (#1529)
* Remove duplicated section from error_management.md The section explaining the three different error types was duplicated (with minimal changes between the two sections). This (small) PR removes the redundancy. * Update doc/error_management.md Co-authored-by: Geoffroy Couprie <[email protected]>
1 parent 3c5e08c commit 6e45c5d

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

doc/error_management.md

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub enum Err<E> {
2222
The result is either an `Ok((I, O))` containing the remaining input and the
2323
parsed value, or an `Err(nom::Err<E>)` with `E` the error type.
2424
`nom::Err<E>` is an enum because combinators can have different behaviours
25-
depending on the value:
25+
depending on the value. The `Err<E>` enum expresses 3 conditions for a parser error:
26+
- `Incomplete` indicates that a parser did not have enough data to decide. This can be returned by parsers found in `streaming` submodules to indicate that we should buffer more data from a file or socket. Parsers in the `complete` submodules assume that they have the entire input data, so if it was not sufficient, they will instead return a `Err::Error`. When a parser returns `Incomplete`, we should accumulate more data in the buffer (example: reading from a socket) and call the parser again
2627
- `Error` is a normal parser error. If a child parser of the `alt` combinator returns `Error`, it will try another child parser
27-
- `Failure` is an error from which we cannot recover: The `alt` combinator will not try other branches if a child parser returns `Failure`. This is used when we know we were in the right branch of `alt` and do not need to try other branches
28-
- `Incomplete` indicates that a parser did not have enough data to decide. This can be returned by parsers found in `streaming` submodules. Parsers in the `complete` submodules assume that they have the entire input data, so if it was not sufficient, they will instead return a `Err::Error`. When a parser returns `Incomplete`, we should accumulate more data in the buffer (example: reading from a socket) and call the parser again
28+
- `Failure` is an error from which we cannot recover: The `alt` combinator will not try other branches if a child parser returns `Failure`. If we know we were in the right branch (example: we found a correct prefix character but input after that was wrong), we can transform a `Err::Error` into a `Err::Failure` with the `cut()` combinator
2929

3030
If we are running a parser and know it will not return `Err::Incomplete`, we can
3131
directly extract the error type from `Err::Error` or `Err::Failure` with the
@@ -68,11 +68,6 @@ directly at the call site.
6868
See [the JSON parser](https://github.com/Geal/nom/blob/5405e1173f1052f7e006dcb0b9cfda2b06557b65/examples/json.rs#L209-L286)
6969
for an example of choosing different error types at the call site.
7070

71-
The `Err<E>` enum expresses 3 conditions for a parser error:
72-
- `Incomplete` indicates that a parser did not have enough data to decide. This can be returned by parsers found in `streaming` submodules to indicate that we should buffer more data from a file or socket. Parsers in the `complete` submodules assume that they have the entire input data, so if it was not sufficient, they will instead return a `Err::Error`
73-
- `Error` is a normal parser error. If a child parser of the `alt` combinator returns `Error`, it will try another child parser
74-
- `Failure` is an error from which we cannot recover: The `alt` combinator will not try other branches if a child parser returns `Failure`. If we know we were in the right branch (example: we found a correct prefix character but input after that was wrong), we can transform a `Err::Error` into a `Err::Failure` with the `cut()` combinator
75-
7671
## Common error types
7772

7873
### the default error type: nom::error::Error

0 commit comments

Comments
 (0)