diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-09 10:16:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-09 10:16:48 +0000 |
commit | defc7ad772123a449f7cc384dd46d88c3a45fb53 (patch) | |
tree | b0b01d1397542585802a3622fdf9491e20fa8c0b /crates/ra_hir_expand | |
parent | 561bb979cecd786f5d311ea7bddb1e15d77a3848 (diff) | |
parent | 70f2a21b55c1b09e575798a75807e13991f2cfec (diff) |
Merge #2197
2197: Remove typed macro parsing API r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/db.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 14 |
3 files changed, 16 insertions, 14 deletions
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" | |||
10 | ra_arena = { path = "../ra_arena" } | 10 | ra_arena = { path = "../ra_arena" } |
11 | ra_db = { path = "../ra_db" } | 11 | ra_db = { path = "../ra_db" } |
12 | ra_syntax = { path = "../ra_syntax" } | 12 | ra_syntax = { path = "../ra_syntax" } |
13 | ra_parser = { path = "../ra_parser" } | ||
13 | ra_prof = { path = "../ra_prof" } | 14 | ra_prof = { path = "../ra_prof" } |
14 | tt = { path = "../ra_tt", package = "ra_tt" } | 15 | tt = { path = "../ra_tt", package = "ra_tt" } |
15 | mbe = { path = "../ra_mbe", package = "ra_mbe" } | 16 | 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; | |||
4 | 4 | ||
5 | use mbe::MacroRules; | 5 | use mbe::MacroRules; |
6 | use ra_db::{salsa, SourceDatabase}; | 6 | use ra_db::{salsa, SourceDatabase}; |
7 | use ra_parser::FragmentKind; | ||
7 | use ra_prof::profile; | 8 | use ra_prof::profile; |
8 | use ra_syntax::{AstNode, Parse, SyntaxNode}; | 9 | use ra_syntax::{AstNode, Parse, SyntaxNode}; |
9 | 10 | ||
@@ -108,12 +109,10 @@ pub(crate) fn parse_macro( | |||
108 | }) | 109 | }) |
109 | .ok()?; | 110 | .ok()?; |
110 | 111 | ||
111 | match macro_file.macro_file_kind { | 112 | let fragment_kind = match macro_file.macro_file_kind { |
112 | MacroFileKind::Items => { | 113 | MacroFileKind::Items => FragmentKind::Items, |
113 | mbe::token_tree_to_items(&tt).ok().map(|(p, map)| (p.to_syntax(), Arc::new(map))) | 114 | MacroFileKind::Expr => FragmentKind::Expr, |
114 | } | 115 | }; |
115 | MacroFileKind::Expr => { | 116 | let (parse, rev_token_map) = mbe::token_tree_to_syntax_node(&tt, fragment_kind).ok()?; |
116 | mbe::token_tree_to_expr(&tt).ok().map(|(p, map)| (p.to_syntax(), Arc::new(map))) | 117 | Some((parse, Arc::new(rev_token_map))) |
117 | } | ||
118 | } | ||
119 | } | 118 | } |
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index b219b8fbf..151d1d785 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -151,19 +151,21 @@ pub struct ExpansionInfo { | |||
151 | 151 | ||
152 | impl ExpansionInfo { | 152 | impl ExpansionInfo { |
153 | pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { | 153 | pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { |
154 | fn look_in_rev_map(exp_map: &mbe::RevTokenMap, from: TextRange) -> Option<tt::TokenId> { | ||
155 | exp_map.ranges.iter().find(|&it| it.0.is_subrange(&from)).map(|it| it.1) | ||
156 | } | ||
157 | |||
158 | let token_id = look_in_rev_map(&self.exp_map, from)?; | 154 | let token_id = look_in_rev_map(&self.exp_map, from)?; |
159 | let (token_map, file_offset, token_id) = if token_id.0 >= self.shift { | 155 | |
156 | let (token_map, (file_id, start_offset), token_id) = if token_id.0 >= self.shift { | ||
160 | (&self.macro_arg.1, self.arg_start, tt::TokenId(token_id.0 - self.shift).into()) | 157 | (&self.macro_arg.1, self.arg_start, tt::TokenId(token_id.0 - self.shift).into()) |
161 | } else { | 158 | } else { |
162 | (&self.macro_def.1, self.def_start, token_id) | 159 | (&self.macro_def.1, self.def_start, token_id) |
163 | }; | 160 | }; |
164 | 161 | ||
165 | let range = token_map.relative_range_of(token_id)?; | 162 | let range = token_map.relative_range_of(token_id)?; |
166 | Some((file_offset.0, TextRange::offset_len(range.start() + file_offset.1, range.len()))) | 163 | |
164 | return Some((file_id, range + start_offset)); | ||
165 | |||
166 | fn look_in_rev_map(exp_map: &mbe::RevTokenMap, from: TextRange) -> Option<tt::TokenId> { | ||
167 | exp_map.ranges.iter().find(|&it| it.0.is_subrange(&from)).map(|it| it.1) | ||
168 | } | ||
167 | } | 169 | } |
168 | } | 170 | } |
169 | 171 | ||