rust/crates/ra_hir_expand/src/proc_macro.rs

32 lines
862 B
Rust
Raw Normal View History

2020-03-18 04:47:59 -05:00
//! Proc Macro Expander stub
2020-03-18 07:56:46 -05:00
use crate::{db::AstDatabase, LazyMacroId};
use ra_db::{CrateId, ProcMacroId};
2020-03-18 04:47:59 -05:00
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct ProcMacroExpander {
krate: CrateId,
2020-03-18 07:56:46 -05:00
proc_macro_id: ProcMacroId,
2020-03-18 04:47:59 -05:00
}
impl ProcMacroExpander {
2020-03-18 07:56:46 -05:00
pub fn new(krate: CrateId, proc_macro_id: ProcMacroId) -> ProcMacroExpander {
ProcMacroExpander { krate, proc_macro_id }
2020-03-18 04:47:59 -05:00
}
pub fn expand(
&self,
db: &dyn AstDatabase,
2020-03-18 07:56:46 -05:00
_id: LazyMacroId,
tt: &tt::Subtree,
2020-03-18 04:47:59 -05:00
) -> Result<tt::Subtree, mbe::ExpandError> {
2020-03-18 07:56:46 -05:00
let krate_graph = db.crate_graph();
let proc_macro = krate_graph[self.krate]
.proc_macro
.get(self.proc_macro_id.0)
.clone()
.ok_or_else(|| mbe::ExpandError::ConversionError)?;
proc_macro.custom_derive(tt)
2020-03-18 04:47:59 -05:00
}
}