You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into an unexpected panic. I managed to reduce into this code:
use nom::{Finish,IResult,Parser,
bytes::tag,
combinator::{all_consuming, iterator},};fnmain(){let data = "hellohellohellohel";let parser = all_consuming(parse_list).parse_complete(data).finish();}fnparse_list(i:&str) -> IResult<&str,Vec<&str>,()>{letmut 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_consumingnor 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,})?;
The text was updated successfully, but these errors were encountered:
What happens is that the OutputMode (which you set to Complete by calling parse_complete() is not passed all the way to tag("hello"). This happens because inside ParseIterator's Iterator impl, anything you pass into it is implicitly used as a streaming parser (the bug is the .parse(input) instead of .parse_complete(input) when in Complete mode):
You could fix this by using nom::bytes::complete::tag instead of nom::bytes::tag inside your parse_list fn, but the behaviour of nom here is still a bug (at least in the documentation, but overall it seems to go against the idea of nom v8).
I am not sure how to deal with this nicely given the large amount of functions inside nom which still return IResult. It would help to get some guidance on the next steps for nom :)
I guess one argument might be that iterator() generally doesn't make that much sense for streaming parsers, as there is no way to provide more data without iterating over the first successfully parsed elements. Hrm...
Hello,
I ran into an unexpected panic. I managed to reduce into this code:
error message:
Considering neither
all_consuming
norparse_complete
should returnIncomplete
, 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.
The text was updated successfully, but these errors were encountered: