[][src]Macro nom::fold_many_m_n

macro_rules! fold_many_m_n {
    ($i:expr, $m:expr, $n: expr, $submac:ident!( $($args:tt)* ), $init:expr, $f:expr) => { ... };
    ($i:expr, $m:expr, $n: expr, $f:expr, $init:expr, $fold_f:expr) => { ... };
}

fold_many_m_n!(usize, usize, I -> IResult<I,O>, R, Fn(R, O) -> R) => I -> IResult<I, R> Applies the parser between m and n times (n included) and folds the list of return value

the embedded parser may return Incomplete

 named!(multi<&[u8], Vec<&[u8]> >,
   fold_many_m_n!(2, 4, tag!( "abcd" ), Vec::new(), |mut acc: Vec<_>, item| {
     acc.push(item);
     acc
 }));

 let a = b"abcdefgh";
 let b = b"abcdabcdefgh";
 let c = b"abcdabcdabcdabcdabcdefgh";

 assert_eq!(multi(&a[..]), Err(Err::Error(error_position!(&a[..], ErrorKind::ManyMN))));
 let res = vec![&b"abcd"[..], &b"abcd"[..]];
 assert_eq!(multi(&b[..]),Ok((&b"efgh"[..], res)));
 let res2 = vec![&b"abcd"[..], &b"abcd"[..], &b"abcd"[..], &b"abcd"[..]];
 assert_eq!(multi(&c[..]),Ok((&b"abcdefgh"[..], res2)));