rust-bakery / nom

Rust parser combinator framework
MIT License
9.38k stars 805 forks source link

docs: Make `recognize` example more explicit #1688

Open RenjiSann opened 1 year ago

RenjiSann commented 1 year ago

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