mirror of
https://github.com/zaphar/abortable_parser.git
synced 2025-07-21 20:29:49 -04:00
FEATURE: Add a with_err! macro.
This commit is contained in:
parent
a78831952f
commit
4c210c3c08
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "abortable_parser"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
authors = ["Jeremy Wall <jeremy@marzhillstudios.com>"]
|
||||
description = "A parser combinator library with an emphasis on error handling"
|
||||
repository = "https://github.com/zaphar/abortable_parser"
|
||||
|
@ -166,6 +166,28 @@ macro_rules! must {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Replaces the the sub error in a Fail case with one of your own errors.
|
||||
macro_rules! with_err {
|
||||
($i:expr, $f:ident!( $( $args:tt )* ), $e:expr) => {{
|
||||
let _i = $i.clone();
|
||||
match $f!($i, $($args)*) {
|
||||
$crate::Result::Complete(i, o) => $crate::Result::Complete(i, o),
|
||||
$crate::Result::Incomplete(ctx) => $crate::Result::Incomplete(ctx),
|
||||
$crate::Result::Fail(e) => $crate::Result::Fail($crate::Error::new($e, Box::new(_i.clone()))),
|
||||
$crate::Result::Abort(e) => $crate::Result::Abort($crate::Error::new($e, Box::new(_i.clone()))),
|
||||
}
|
||||
}};
|
||||
|
||||
($i:expr, $f:ident( $( $args:tt )* ), $e:expr ) => {
|
||||
with_err!($i, run!($f($($args)*)), $e:expr)
|
||||
};
|
||||
|
||||
($i:expr, $f:ident, $e:expr) => {
|
||||
with_err!($i, run!($f), $e)
|
||||
};
|
||||
}
|
||||
|
||||
/// Wraps any Error return from a subparser in another error. Stores the position at
|
||||
/// this point in the parse tree allowing you to associate context with wrapped errors.
|
||||
#[macro_export]
|
||||
|
Loading…
x
Reference in New Issue
Block a user