-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
many0 returns Incomplete in weird cases #790
Comments
I can second this with another example error case: Test Case
Upon more testing it seems like |
I ran into the same issue when porting from nom 3 to nom 4. Essentially,
including |
Also see #795 |
Same issue here. I can't use |
So the reason this happens was explained to me on IRC: if your parser ends with a Since I now at least understand the behavior, maybe it would be better to close this bug, although I still stand by my assertion that the new behavior is not very ergonomic to use (but that is better represented by #795). |
Okay, that's really surprising: fn test_complete() {
named!(test<&str,Vec<&str>>, many0!(complete!(take_until_and_consume!("TEST"))));
let r = test("aTESTbTEST");
assert_eq!(r, Ok(("", vec!["a", "b"])));
} works, even though the first time around the |
Here's a test that still fails: I want to allow optional additional space between my items, so I do fn test_complete() {
named!(test<&str,Vec<&str>>, many0!(complete!(
do_parse!(s: take_until_and_consume!("TEST") >> multispace0 >> (s))
)));
let r = test("aTEST bTEST\n");
assert_eq!(r, Ok(("", vec!["a", "b"])));
} This says
On the other hand, this works: fn test_complete() {
use nom::types::CompleteStr;
named!(test<CompleteStr,Vec<&str>>, many0!(
do_parse!(s: take_until_and_consume!("TEST") >> multispace0 >> (s.0))
));
let r = test(CompleteStr("aTEST bTEST\n"));
assert_eq!(r, Ok((CompleteStr(""), vec!["a", "b"])));
} |
If I'm reading the docs right,
I got that to work like this: fn test_complete() {
named!(test<&str,Vec<&str>>, many0!(complete!(
do_parse!(s: take_until_and_consume!("TEST") >> many0!(complete!(one_of!(" \r\n\t"))) >> (s))
)));
let r = test("aTEST bTEST\n");
assert_eq!(r, Ok(("", vec!["a", "b"])));
} but yeah, couldn't get it to work with |
As a workaround to rust-bakery/nom#544, migrate to nom 4 to ensure that the verbose-errors feature becomes additive and therefore portus compiles when used as a dependency. There were two classes of changes to the parser structure: 1. Error handling, as predicted and outlined here: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#replacing-parser-result-matchers 2. Migration to "CompleteByteSlice". This was predicted in the migration notes: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#dealing-with-incomplete-usage but caused underlying errors as reported here: rust-bakery/nom#790 (comment) To address this, shadow nom's `named!` macro with our own, `named_complete!`, which replaces the types appropriately. This is the solution proposed here: rust-bakery/nom#795 (comment)
As a workaround to rust-bakery/nom#544, migrate to nom 4 to ensure that the verbose-errors feature becomes additive and therefore portus compiles when used as a dependency. There were two classes of changes to the parser structure: 1. Error handling, as predicted and outlined here: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#replacing-parser-result-matchers 2. Migration to "CompleteByteSlice". This was predicted in the migration notes: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#dealing-with-incomplete-usage but caused underlying errors as reported here: rust-bakery/nom#790 (comment) To address this, shadow nom's `named!` macro with our own, `named_complete!`, which replaces the types appropriately. This is the solution proposed here: rust-bakery/nom#795 (comment)
As a workaround to rust-bakery/nom#544, migrate to nom 4 to ensure that the verbose-errors feature becomes additive and therefore portus compiles when used as a dependency. There were two classes of changes to the parser structure: 1. Error handling, as predicted and outlined here: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#replacing-parser-result-matchers 2. Migration to "CompleteByteSlice". This was predicted in the migration notes: https://github.com/Geal/nom/blob/master/doc/upgrading_to_nom_4.md#dealing-with-incomplete-usage but caused underlying errors as reported here: rust-bakery/nom#790 (comment) To address this, shadow nom's `named!` macro with our own, `named_complete!`, which replaces the types appropriately. This is the solution proposed here: rust-bakery/nom#795 (comment)
In case anyone stumbles on this thread in the future, here's another workaround:
The EDIT: On second thought, this doesn't work – it fixes the empty case, but then falls back to the |
fixed in nom 5 where we can get specialized versions of some parsers for streaming or complete inputs |
This still happens on nom7. Trailing P.S. Please don't use IRC or chats in general as a knowledge base, because they are not one. |
If you pass a streaming parser to |
Prerequisites
Here are a few things you should provide to help me understand the issue:
Test case
Example test case:
This results in
Err(Incomplete(Size(2)))
, which doesn't make any sense to me. I looked at converting my actual code (in the Askama crate) toCompleteByteSlice
, but that seems like a very deep change.The text was updated successfully, but these errors were encountered: