use {
proc_macro_error::proc_macro_error,
proc_macro2::TokenStream,
};
mod args;
use args::Args;
mod ast;
mod cst;
mod error;
#[proc_macro_attribute]
#[proc_macro_error]
pub fn laburnum_syntax(
args: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
process(args.into(), item.into())
.unwrap_or_else(|syn_error| {
syn_error.into_compile_error()
})
.into()
}
pub(crate) fn process(
attr: TokenStream,
item: TokenStream,
) -> Result<TokenStream, syn::Error> {
let f = Args::parse(attr.clone());
match (f.is_cst(), f.is_ast()) {
| (true, false) => cst::process(item, f),
| (false, true) => ast::process(item, f),
| (true, true) => {
Err(syn::Error::new(
f.conflicting_span(),
"Cannot specify both AST and CST flags. Choose either AST or CST, not both: #[laburnum_syntax(AST)] or #[laburnum_syntax(CST)].",
))
},
| (false, false) => {
Err(syn::Error::new(
f.missing_type_span(),
"Missing syntax type specification. Add either AST or CST to the attribute: #[laburnum_syntax(AST)] or #[laburnum_syntax(CST)].",
))
},
}
}
#[cfg(test)]
mod tests;