aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-18 12:09:24 +0000
committerGitHub <[email protected]>2019-11-18 12:09:24 +0000
commit157beb8b3fd162b2be735274d5da42870e90cb01 (patch)
tree3985535b59ac5061f3c6fb7ce9c109b454dc2c1e /crates/ra_mbe
parent32e72ecd66fede0b39e8f34ca3e1b92128e1d91a (diff)
parentb79d6789236bb53c5818949cc2960b5c4991cbeb (diff)
Merge #2300
2300: Token-based reverse-mapping r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 8398c9ac7..fe3b70b8d 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -20,7 +20,7 @@ pub struct TokenMap {
20/// Maps relative range of the expanded syntax node to `tt::TokenId` 20/// Maps relative range of the expanded syntax node to `tt::TokenId`
21#[derive(Debug, PartialEq, Eq, Default)] 21#[derive(Debug, PartialEq, Eq, Default)]
22pub struct RevTokenMap { 22pub struct RevTokenMap {
23 pub ranges: Vec<(TextRange, tt::TokenId)>, 23 ranges: Vec<(TextRange, tt::TokenId)>,
24} 24}
25 25
26/// Convert the syntax tree (what user has written) to a `TokenTree` (what macro 26/// Convert the syntax tree (what user has written) to a `TokenTree` (what macro
@@ -96,6 +96,10 @@ impl TokenMap {
96} 96}
97 97
98impl RevTokenMap { 98impl RevTokenMap {
99 pub fn token_by_range(&self, relative_range: TextRange) -> Option<tt::TokenId> {
100 self.ranges.iter().find(|&it| it.0 == relative_range).map(|it| it.1)
101 }
102
99 pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TextRange> { 103 pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TextRange> {
100 let &(r, _) = self.ranges.iter().find(|(_, tid)| *tid == token_id)?; 104 let &(r, _) = self.ranges.iter().find(|(_, tid)| *tid == token_id)?;
101 Some(r) 105 Some(r)