Macro nom::many_till [] [src]

macro_rules! many_till {
    ($i:expr, $submac1:ident!( $($args1:tt)* ), $submac2:ident!( $($args2:tt)* )) => { ... };
    ($i:expr, $f:expr, $g: expr) => { ... };
}

many_till!(I -> IResult<I,O>, I -> IResult<I,P>) => I -> IResult<I, (Vec<O>, P)> Applies the first parser until the second applies. Returns a tuple containing the list of results from the first in a Vec and the result of the second.

The first embedded parser may return Incomplete

   named!(multi<&[u8], (Vec<&[u8]>, &[u8]) >, many_till!( tag!( "abcd" ), tag!( "efgh" ) ) );

   let a = b"abcdabcdefghabcd";
   let b = b"efghabcd";
   let c = b"azerty";

   let res_a = (vec![&b"abcd"[..], &b"abcd"[..]], &b"efgh"[..]);
   let res_b: (Vec<&[u8]>, &[u8]) = (Vec::new(), &b"efgh"[..]);
   assert_eq!(multi(&a[..]), Done(&b"abcd"[..], res_a));
   assert_eq!(multi(&b[..]), Done(&b"abcd"[..], res_b));
   assert_eq!(multi(&c[..]), Error(error_position!(ErrorKind::ManyTill,&c[..])));