Files
natter/src/intermediate/macros.rs

76 lines
2.4 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)]
2023-12-21 14:56:58 -05:00
pub(crate) struct $istruct {
pub(crate) post_blank: organic::types::PostBlank,
}
impl $istruct {
2025-02-22 19:42:24 -05:00
#[allow(clippy::extra_unused_lifetimes)]
pub(crate) async fn new<'reg, 'orig, 'parse>(
_intermediate_context: crate::intermediate::IntermediateContext<'orig, 'parse>,
2023-12-21 14:56:58 -05:00
original: &'orig organic::types::$pstruct<'parse>,
) -> Result<$istruct, CustomError> {
2023-12-21 14:56:58 -05:00
Ok($istruct {
post_blank: original.get_post_blank(),
})
}
}
};
}
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, $intermediate_context:ident, $fnbody:tt) => {
impl $istruct {
pub(crate) async fn new<'orig, 'parse>(
$intermediate_context: crate::intermediate::IntermediateContext<'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 {
($istruct:ident, $pstruct:ident, $original:ident, $intermediate_context:ident, $fnbody:tt) => {
impl $istruct {
pub(crate) fn new<'orig, 'parse>(
$intermediate_context: crate::intermediate::IntermediateContext<'orig, 'parse>,
$original: &'orig organic::types::$pstruct<'parse>,
) -> BoxFuture<'orig, Result<$istruct, CustomError>> {
2023-10-29 20:01:44 -04:00
async move { $fnbody }.boxed()
}
}
};
}
pub(crate) use iselector;
macro_rules! iitem {
($intermediate_context: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($intermediate_context.clone(), inner).await?,
)),
)*
}
};
}
pub(crate) use iitem;