Remove delimiters from proc macro input

This commit is contained in:
Jonas Schievink 2021-05-12 01:01:51 +02:00
parent c868414dcd
commit e78221bc58
2 changed files with 14 additions and 1 deletions

View File

@ -267,7 +267,16 @@ fn parse_macro_expansion(
fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
let arg = db.macro_arg_text(id)?;
let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg));
let (mut tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg));
if let MacroCallId::LazyMacro(id) = id {
let loc: MacroCallLoc = db.lookup_intern_macro(id);
if loc.def.is_proc_macro() {
// proc macros expect their inputs without parentheses, MBEs expect it with them included
tt.delimiter = None;
}
}
Some(Arc::new((tt, tmap)))
}

View File

@ -272,6 +272,10 @@ pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
};
Either::Left(*id)
}
pub fn is_proc_macro(&self) -> bool {
matches!(self.kind, MacroDefKind::ProcMacro(..))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]