aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/subtree_source.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/subtree_source.rs')
-rw-r--r--crates/ra_mbe/src/subtree_source.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs
index 16a053b49..20da1e9f7 100644
--- a/crates/ra_mbe/src/subtree_source.rs
+++ b/crates/ra_mbe/src/subtree_source.rs
@@ -21,6 +21,7 @@ impl<'a> From<&'a [tt::TokenTree]> for TokenSeq<'a> {
21 } 21 }
22} 22}
23 23
24#[derive(Debug)]
24enum DelimToken<'a> { 25enum DelimToken<'a> {
25 Delim(&'a tt::Delimiter, bool), 26 Delim(&'a tt::Delimiter, bool),
26 Token(&'a tt::TokenTree), 27 Token(&'a tt::TokenTree),
@@ -52,10 +53,10 @@ impl<'a> TokenSeq<'a> {
52 } 53 }
53 } 54 }
54 55
55 fn child_slice(&self) -> &[tt::TokenTree] { 56 fn child_slice(&self, pos: usize) -> &[tt::TokenTree] {
56 match self { 57 match self {
57 TokenSeq::Subtree(subtree) => &subtree.token_trees, 58 TokenSeq::Subtree(subtree) => &subtree.token_trees[pos - 1..],
58 TokenSeq::Seq(tokens) => &tokens, 59 TokenSeq::Seq(tokens) => &tokens[pos..],
59 } 60 }
60 } 61 }
61} 62}
@@ -114,7 +115,7 @@ impl<'a> SubTreeWalker<'a> {
114 WalkCursor::Token(0, convert_delim(subtree.delimiter, false)) 115 WalkCursor::Token(0, convert_delim(subtree.delimiter, false))
115 } 116 }
116 tt::TokenTree::Leaf(leaf) => { 117 tt::TokenTree::Leaf(leaf) => {
117 let next_tokens = self.ts.child_slice(); 118 let next_tokens = self.ts.child_slice(0);
118 WalkCursor::Token(0, convert_leaf(&next_tokens, leaf)) 119 WalkCursor::Token(0, convert_leaf(&next_tokens, leaf))
119 } 120 }
120 }, 121 },
@@ -190,8 +191,8 @@ impl<'a> SubTreeWalker<'a> {
190 WalkCursor::Token(new_idx, convert_delim(subtree.delimiter, backward)) 191 WalkCursor::Token(new_idx, convert_delim(subtree.delimiter, backward))
191 } 192 }
192 tt::TokenTree::Leaf(leaf) => { 193 tt::TokenTree::Leaf(leaf) => {
193 let next_tokens = top.child_slice(); 194 let next_tokens = top.child_slice(pos);
194 WalkCursor::Token(pos, convert_leaf(&next_tokens[pos..], leaf)) 195 WalkCursor::Token(pos, convert_leaf(&next_tokens, leaf))
195 } 196 }
196 }, 197 },
197 DelimToken::Delim(delim, is_end) => { 198 DelimToken::Delim(delim, is_end) => {
@@ -429,7 +430,12 @@ fn convert_literal(l: &tt::Literal) -> TtToken {
429} 430}
430 431
431fn convert_ident(ident: &tt::Ident) -> TtToken { 432fn convert_ident(ident: &tt::Ident) -> TtToken {
432 let kind = SyntaxKind::from_keyword(ident.text.as_str()).unwrap_or(IDENT); 433 let kind = if let Some('\'') = ident.text.chars().next() {
434 LIFETIME
435 } else {
436 SyntaxKind::from_keyword(ident.text.as_str()).unwrap_or(IDENT)
437 };
438
433 TtToken { kind, is_joint_to_next: false, text: ident.text.clone(), n_tokens: 1 } 439 TtToken { kind, is_joint_to_next: false, text: ident.text.clone(), n_tokens: 1 }
434} 440}
435 441