Skip to content
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

docs: Make recognize example more explicit #1688

Open
RenjiSann opened this issue Aug 21, 2023 · 0 comments
Open

docs: Make recognize example more explicit #1688

RenjiSann opened this issue Aug 21, 2023 · 0 comments

Comments

@RenjiSann
Copy link

RenjiSann commented Aug 21, 2023

Hi !

Just wanted to suggest to modify slightly to the recognize example, as the ordering of the output type is not obvious to me
Here is my suggestion:

use nom::combinator::recognize;
use nom::character::complete::{char, alpha1};
use nom::sequence::separated_pair;

let mut parser = recognize(separated_pair(alpha1, char(','), alpha1));

assert_eq!(parser("abcd,efgh_"), Ok(("_", "abcd,efgh"))); // 'abcd,efgh' is consumed, _ is left
assert_eq!(parser("abcd;"),Err(Err::Error((";", ErrorKind::Char)))); // Missing second part
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant