Add basic bultin macro infrastructure

This commit is contained in:
Edwin Cheng
2019-11-10 11:03:24 +08:00
parent defc7ad772
commit c46768d13d
8 changed files with 148 additions and 29 deletions

View File

@@ -0,0 +1,26 @@
//! Builtin macro
use crate::{ast, name, AstId, BuiltinMacro, CrateId, MacroDefId};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BuiltinExpander {
Line
}
impl BuiltinExpander {
pub fn expand(&self, _tt: &tt::Subtree) -> Result<tt::Subtree, mbe::ExpandError> {
Err(mbe::ExpandError::UnexpectedToken)
}
}
pub fn find_builtin_macro(
ident: &name::Name,
krate: CrateId,
ast_id: AstId<ast::MacroCall>,
) -> Option<MacroDefId> {
// FIXME: Better registering method
if ident == &name::LINE {
Some(MacroDefId::BuiltinMacro(BuiltinMacro { expander: BuiltinExpander::Line, krate, ast_id }))
} else {
None
}
}