aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mbe')
-rw-r--r--crates/mbe/src/tests/expand.rs5
-rw-r--r--crates/mbe/src/token_map.rs8
2 files changed, 6 insertions, 7 deletions
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 3a1d840ea..5f173f513 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -58,9 +58,8 @@ macro_rules! foobar {
58 let (node, token_map) = token_tree_to_syntax_node(&expanded, FragmentKind::Items).unwrap(); 58 let (node, token_map) = token_tree_to_syntax_node(&expanded, FragmentKind::Items).unwrap();
59 let content = node.syntax_node().to_string(); 59 let content = node.syntax_node().to_string();
60 60
61 let get_text = |id, kind| -> String { 61 let get_text =
62 content[token_map.range_by_token(id).unwrap().by_kind(kind).unwrap()].to_string() 62 |id, kind| -> String { content[token_map.range_by_token(id, kind).unwrap()].to_string() };
63 };
64 63
65 assert_eq!(expanded.token_trees.len(), 4); 64 assert_eq!(expanded.token_trees.len(), 4);
66 // {($e:ident) => { fn $e() {} }} 65 // {($e:ident) => { fn $e() {} }}
diff --git a/crates/mbe/src/token_map.rs b/crates/mbe/src/token_map.rs
index 58c9f5aa5..0567475be 100644
--- a/crates/mbe/src/token_map.rs
+++ b/crates/mbe/src/token_map.rs
@@ -2,13 +2,13 @@ use parser::{SyntaxKind, T};
2use syntax::{TextRange, TextSize}; 2use syntax::{TextRange, TextSize};
3 3
4#[derive(Debug, PartialEq, Eq, Clone, Copy)] 4#[derive(Debug, PartialEq, Eq, Clone, Copy)]
5pub enum TokenTextRange { 5enum TokenTextRange {
6 Token(TextRange), 6 Token(TextRange),
7 Delimiter(TextRange), 7 Delimiter(TextRange),
8} 8}
9 9
10impl TokenTextRange { 10impl TokenTextRange {
11 pub fn by_kind(self, kind: SyntaxKind) -> Option<TextRange> { 11 fn by_kind(self, kind: SyntaxKind) -> Option<TextRange> {
12 match self { 12 match self {
13 TokenTextRange::Token(it) => Some(it), 13 TokenTextRange::Token(it) => Some(it),
14 TokenTextRange::Delimiter(it) => match kind { 14 TokenTextRange::Delimiter(it) => match kind {
@@ -42,9 +42,9 @@ impl TokenMap {
42 Some(token_id) 42 Some(token_id)
43 } 43 }
44 44
45 pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TokenTextRange> { 45 pub fn range_by_token(&self, token_id: tt::TokenId, kind: SyntaxKind) -> Option<TextRange> {
46 let &(_, range) = self.entries.iter().find(|(tid, _)| *tid == token_id)?; 46 let &(_, range) = self.entries.iter().find(|(tid, _)| *tid == token_id)?;
47 Some(range) 47 range.by_kind(kind)
48 } 48 }
49 49
50 pub(crate) fn shrink_to_fit(&mut self) { 50 pub(crate) fn shrink_to_fit(&mut self) {