This crate provides the derive macros used by `peepmatic`, notable AST-related derives that enumerate child AST nodes, and operator-related derives that provide helpers for type checking.
24 lines
647 B
Rust
24 lines
647 B
Rust
use quote::quote;
|
|
use syn::DeriveInput;
|
|
use syn::Result;
|
|
|
|
pub fn derive_into_dyn_ast_ref(input: &DeriveInput) -> Result<impl quote::ToTokens> {
|
|
let ty = &input.ident;
|
|
|
|
let opts = crate::PeepmaticOpts::from_attrs(&mut input.attrs.clone())?;
|
|
if opts.no_into_dyn_node {
|
|
return Ok(quote! {});
|
|
}
|
|
|
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
|
|
|
Ok(quote! {
|
|
impl #impl_generics From<&'a #ty #ty_generics> for DynAstRef<'a> #where_clause {
|
|
#[inline]
|
|
fn from(x: &'a #ty #ty_generics) -> Self {
|
|
Self::#ty(x)
|
|
}
|
|
}
|
|
})
|
|
}
|