Expand procedural attribute macros

This commit is contained in:
Jonas Schievink 2021-05-31 13:37:11 +02:00
parent 7f9c4a59d9
commit e5a2c6596d
7 changed files with 159 additions and 14 deletions

View file

@ -28,11 +28,16 @@ impl ProcMacroExpander {
Self { krate, proc_macro_id: None }
}
pub fn is_dummy(&self) -> bool {
self.proc_macro_id.is_none()
}
pub fn expand(
self,
db: &dyn AstDatabase,
calling_crate: CrateId,
tt: &tt::Subtree,
attr_arg: Option<&tt::Subtree>,
) -> Result<tt::Subtree, mbe::ExpandError> {
match self.proc_macro_id {
Some(id) => {
@ -46,7 +51,7 @@ impl ProcMacroExpander {
// Proc macros have access to the environment variables of the invoking crate.
let env = &krate_graph[calling_crate].env;
proc_macro.expander.expand(&tt, None, &env).map_err(mbe::ExpandError::from)
proc_macro.expander.expand(&tt, attr_arg, &env).map_err(mbe::ExpandError::from)
}
None => Err(mbe::ExpandError::UnresolvedProcMacro),
}