1//! Macros useful when writing procedural syntax extensions.
2//!
3//! The macros themselves are ordinary `macro_rules!` macros.
4
5/// Call `span_err` on an `ExtCtxt` and return `DummyResult::any`.
6#[macro_export]
7macro_rules! ext_bail {
8 ($cx:expr, $sp:expr, $msg:expr) => {{
9 $cx.span_err($sp, $msg);
10 return ::syntax::ext::base::DummyResult::any($sp);
11 }}
12}
13
14/// `ext_bail!` if the condition `$e` is true.
15#[macro_export]
16macro_rules! ext_bail_if {
17 ($e:expr, $cx:expr, $sp:expr, $msg:expr) => {{
18 if $e { ext_bail!($cx, $sp, $msg) }
19 }}
20}
21
22/// Unwrap the `Option` `$e`, or `ext_bail!`.
23#[macro_export]
24macro_rules! ext_expect {
25 ($cx:expr, $sp:expr, $e:expr, $msg:expr) => {{
26 match $e {
27 Some(x) => x,
28 None => ext_bail!($cx, $sp, $msg),
29 }
30 }}
31}
32