natter/src/intermediate/macros.rs

57 lines
1.8 KiB
Rust
Raw Normal View History

/// Write the implementation for the intermediate ast node for a type that is a noop or is not yet implemented.
///
/// This exists to make changing the type signature easier.
macro_rules! inoop {
($istruct:ident, $pstruct:ident) => {
#[derive(Debug, Clone)]
pub(crate) struct $istruct {}
impl $istruct {
pub(crate) async fn new<'reg, 'orig, 'parse>(
registry: &'reg mut Registry<'orig, 'parse>,
original: &'orig organic::types::$pstruct<'parse>,
) -> Result<$istruct, CustomError> {
Ok($istruct {})
}
}
};
}
pub(crate) use inoop;
/// Write the implementation for the intermediate ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! intermediate {
($istruct:ident, $pstruct:ident, $fnbody:expr) => {
impl $istruct {
pub(crate) async fn new<'reg, 'orig, 'parse>(
registry: &'reg mut Registry<'orig, 'parse>,
original: &'orig organic::types::$pstruct<'parse>,
) -> Result<$istruct, CustomError> {
$fnbody(registry, original).await
}
}
};
}
pub(crate) use intermediate;
/// Write the implementation for the intermediate ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! iselector {
($istruct:ident, $pstruct:ident, $fnbody:expr) => {
impl $istruct {
pub(crate) fn new<'reg, 'orig, 'parse, 'inp: 'reg + 'orig>(
registry: &'reg mut Registry<'orig, 'parse>,
original: &'orig organic::types::$pstruct<'parse>,
) -> BoxFuture<'inp, Result<$istruct, CustomError>> {
$fnbody(registry, original).boxed()
}
}
};
}
pub(crate) use iselector;