Open
Description
Hello,
I ran into an unexpected panic. I managed to reduce into this code:
use nom::{
Finish, IResult, Parser,
bytes::tag,
combinator::{all_consuming, iterator},
};
fn main() {
let data = "hellohellohellohel";
let parser = all_consuming(parse_list).parse_complete(data).finish();
}
fn parse_list(i: &str) -> IResult<&str, Vec<&str>, ()> {
let mut iter = iterator(i, tag("hello"));
let result = iter.by_ref().collect();
let (i, ()) = iter.finish()?;
Ok((i, result))
}
error message:
Cannot call `finish()` on `Err(Err::Incomplete(_))`: this result means that the parser does not have enough data to decide, you should gather more data and try to reapply the parser instead
Considering neither all_consuming
nor parse_complete
should return Incomplete
, this was a bit of a surprise. I am not sure where the mishap is.
In my actual code I managed to avoid it by doing this.
let (i, ()) = iter.finish().map_err(|e| match e {
nom::Err::Incomplete(_) => {
nom::Err::Error(error::make_error(i, error::ErrorKind::TooLarge))
}
fail => fail,
})?;
Metadata
Metadata
Assignees
Labels
No labels