Files
natter/src/intermediate/macros.rs

73 lines
2.2 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>(
2023-10-29 22:31:29 -04:00
_registry: crate::intermediate::RefRegistry<'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:ty, $original:ident, $registry:ident, $fnbody:tt) => {
impl $istruct {
pub(crate) async fn new<'orig, 'parse>(
$registry: crate::intermediate::RefRegistry<'orig, 'parse>,
$original: $pstruct,
) -> Result<$istruct, CustomError> {
$fnbody
}
}
};
}
pub(crate) use intermediate;
/// Write the implementation for the intermediate ast node.
///
/// This exists to make changing the type signature easier.
macro_rules! iselector {
2023-10-29 18:54:50 -04:00
($istruct:ident, $pstruct:ident, $original:ident, $registry:ident, $fnbody:tt) => {
impl $istruct {
pub(crate) fn new<'orig, 'parse>(
registry: crate::intermediate::RefRegistry<'orig, 'parse>,
original: &'orig organic::types::$pstruct<'parse>,
) -> BoxFuture<'orig, Result<$istruct, CustomError>> {
2023-10-29 20:01:44 -04:00
let $registry = registry;
let $original = original;
async move { $fnbody }.boxed()
}
}
};
}
pub(crate) use iselector;
macro_rules! iitem {
($registry:expr, $original:expr, $(($penum:path, $ienum:path, $istruct:ident),)*) => {
match $original {
$(
2023-10-29 18:54:50 -04:00
$penum(inner) => Ok($ienum(
$istruct::new($registry.clone(), inner).await?,
)),
)*
}
};
}
pub(crate) use iitem;