[−][src]Function gchemol_parser::parsers::count
pub fn count<I, O, E, F>(f: F, count: usize) -> impl Fn(I) where
E: ParseError<I>,
F: Fn(I) -> Result<(I, O), Err<E>>,
I: Clone + PartialEq<I>,
Runs the embedded parser a specified number
of times. Returns the results in a Vec
.
Arguments
f
The parser to apply.count
How often to apply the parser.
use nom::multi::count; use nom::bytes::complete::tag; fn parser(s: &str) -> IResult<&str, Vec<&str>> { count(tag("abc"), 2)(s) } assert_eq!(parser("abcabc"), Ok(("", vec!["abc", "abc"]))); assert_eq!(parser("abc123"), Err(Err::Error(("123", ErrorKind::Tag)))); assert_eq!(parser("123123"), Err(Err::Error(("123123", ErrorKind::Tag)))); assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag)))); assert_eq!(parser("abcabcabc"), Ok(("abc", vec!["abc", "abc"])));