peepmatic: Introduce the peepmatic-macro crate

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.
This commit is contained in:
Nick Fitzgerald
2020-05-01 15:33:55 -07:00
parent c82326a1ae
commit 0f03a97475
6 changed files with 679 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
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)
}
}
})
}