[][src]Macro nom::many_till

macro_rules! many_till {
    (__impl $i:expr, $submac1:ident!( $($args1:tt)* ), $submac2:ident!( $($args2:tt)* )) => { ... };
    ($i:expr, $submac1:ident!( $($args1:tt)* ), $submac2:ident!( $($args2:tt)* )) => { ... };
    ($i:expr, $submac1:ident!( $($args1:tt)* ), $g:expr) => { ... };
    ($i:expr, $f:expr, $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[..]),Ok((&b"abcd"[..], res_a)));
   assert_eq!(multi(&b[..]),Ok((&b"abcd"[..], res_b)));
   assert_eq!(multi(&c[..]), Err(Err::Error(error_node_position!(&c[..], ErrorKind::ManyTill,
     error_position!(&c[..], ErrorKind::Tag)))));