From 70f2a21b55c1b09e575798a75807e13991f2cfec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 9 Nov 2019 13:14:10 +0300 Subject: Remove typed macro parsing API We do type-erasure on every path anyway, so it doesn't make much sense to duplicate this function for every type --- crates/ra_hir_expand/Cargo.toml | 1 + crates/ra_hir_expand/src/db.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir_expand') diff --git a/crates/ra_hir_expand/Cargo.toml b/crates/ra_hir_expand/Cargo.toml index 9bf5b7918..8f29bf7d9 100644 --- a/crates/ra_hir_expand/Cargo.toml +++ b/crates/ra_hir_expand/Cargo.toml @@ -10,6 +10,7 @@ log = "0.4.5" ra_arena = { path = "../ra_arena" } ra_db = { path = "../ra_db" } ra_syntax = { path = "../ra_syntax" } +ra_parser = { path = "../ra_parser" } ra_prof = { path = "../ra_prof" } tt = { path = "../ra_tt", package = "ra_tt" } mbe = { path = "../ra_mbe", package = "ra_mbe" } diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs index b789c6e7b..b4dafe1d8 100644 --- a/crates/ra_hir_expand/src/db.rs +++ b/crates/ra_hir_expand/src/db.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use mbe::MacroRules; use ra_db::{salsa, SourceDatabase}; +use ra_parser::FragmentKind; use ra_prof::profile; use ra_syntax::{AstNode, Parse, SyntaxNode}; @@ -108,12 +109,10 @@ pub(crate) fn parse_macro( }) .ok()?; - match macro_file.macro_file_kind { - MacroFileKind::Items => { - mbe::token_tree_to_items(&tt).ok().map(|(p, map)| (p.to_syntax(), Arc::new(map))) - } - MacroFileKind::Expr => { - mbe::token_tree_to_expr(&tt).ok().map(|(p, map)| (p.to_syntax(), Arc::new(map))) - } - } + let fragment_kind = match macro_file.macro_file_kind { + MacroFileKind::Items => FragmentKind::Items, + MacroFileKind::Expr => FragmentKind::Expr, + }; + let (parse, rev_token_map) = mbe::token_tree_to_syntax_node(&tt, fragment_kind).ok()?; + Some((parse, Arc::new(rev_token_map))) } -- cgit v1.2.3