Macro nom::add_return_error

source ·
macro_rules! add_return_error {
    ($i:expr, $code:expr, $submac:ident!( $($args:tt)* )) => { ... };
    ($i:expr, $code:expr, $f:expr) => { ... };
}
Expand description

Add an error if the child parser fails

While return_error! does an early return and avoids backtracking, add_return_error! backtracks normally. It just provides more context for an error

    named!(err_test, add_return_error!(ErrorKind::Tag, tag!("abcd")));

    let a = &b"efghblah"[..];
    let res_a = err_test(a);
    assert_eq!(res_a, Err(Err::Error(error_node_position!(a, ErrorKind::Tag, error_position!(a, ErrorKind::Tag)))));