[][src]Macro nom::opt_res

macro_rules! opt_res {
    ($i:expr, $submac:ident!( $($args:tt)* )) => { ... };
    ($i:expr, $f:expr) => { ... };
}

opt_res!(I -> IResult<I,O>) => I -> IResult<I, Result<nom::Err,O>> make the underlying parser optional

returns a Result, with Err containing the parsing error

This example is not tested
 named!( o<&[u8], Result<&[u8], nom::Err<&[u8]> > >, opt_res!( tag!( "abcd" ) ) );

 let a = b"abcdef";
 let b = b"bcdefg";
 assert_eq!(o(&a[..]), Ok((&b"ef"[..], Ok(&b"abcd"[..])));
 assert_eq!(o(&b[..]), Ok((&b"bcdefg"[..], Err(error_position!(&b[..], ErrorKind::Tag))));