nom icon indicating copy to clipboard operation
nom copied to clipboard

docs: Make `recognize` example more explicit

Open RenjiSann opened this issue 1 year ago • 0 comments

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

RenjiSann avatar Aug 21 '23 14:08 RenjiSann