aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/lib.rs')
-rw-r--r--crates/ra_mbe/src/lib.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs
index bbddebe67..2c6ae5658 100644
--- a/crates/ra_mbe/src/lib.rs
+++ b/crates/ra_mbe/src/lib.rs
@@ -67,7 +67,15 @@ impl Shift {
67 .token_trees 67 .token_trees
68 .iter() 68 .iter()
69 .filter_map(|tt| match tt { 69 .filter_map(|tt| match tt {
70 tt::TokenTree::Subtree(subtree) => max_id(subtree), 70 tt::TokenTree::Subtree(subtree) => {
71 let tree_id = max_id(subtree);
72 match subtree.delimiter {
73 Some(it) if it.id != tt::TokenId::unspecified() => {
74 Some(tree_id.map_or(it.id.0, |t| t.max(it.id.0)))
75 }
76 _ => tree_id,
77 }
78 }
71 tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) 79 tt::TokenTree::Leaf(tt::Leaf::Ident(ident))
72 if ident.id != tt::TokenId::unspecified() => 80 if ident.id != tt::TokenId::unspecified() =>
73 { 81 {
@@ -85,9 +93,15 @@ impl Shift {
85 match t { 93 match t {
86 tt::TokenTree::Leaf(leaf) => match leaf { 94 tt::TokenTree::Leaf(leaf) => match leaf {
87 tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id), 95 tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id),
88 _ => (), 96 tt::Leaf::Punct(punct) => punct.id = self.shift(punct.id),
97 tt::Leaf::Literal(lit) => lit.id = self.shift(lit.id),
89 }, 98 },
90 tt::TokenTree::Subtree(tt) => self.shift_all(tt), 99 tt::TokenTree::Subtree(tt) => {
100 if let Some(it) = tt.delimiter.as_mut() {
101 it.id = self.shift(it.id);
102 };
103 self.shift_all(tt)
104 }
91 } 105 }
92 } 106 }
93 } 107 }
@@ -104,6 +118,7 @@ impl Shift {
104 } 118 }
105} 119}
106 120
121#[derive(Debug, Eq, PartialEq)]
107pub enum Origin { 122pub enum Origin {
108 Def, 123 Def,
109 Call, 124 Call,
@@ -159,14 +174,14 @@ impl Rule {
159 .expect_subtree() 174 .expect_subtree()
160 .map_err(|()| ParseError::Expected("expected subtree".to_string()))? 175 .map_err(|()| ParseError::Expected("expected subtree".to_string()))?
161 .clone(); 176 .clone();
162 lhs.delimiter = tt::Delimiter::None; 177 lhs.delimiter = None;
163 src.expect_char('=').map_err(|()| ParseError::Expected("expected `=`".to_string()))?; 178 src.expect_char('=').map_err(|()| ParseError::Expected("expected `=`".to_string()))?;
164 src.expect_char('>').map_err(|()| ParseError::Expected("expected `>`".to_string()))?; 179 src.expect_char('>').map_err(|()| ParseError::Expected("expected `>`".to_string()))?;
165 let mut rhs = src 180 let mut rhs = src
166 .expect_subtree() 181 .expect_subtree()
167 .map_err(|()| ParseError::Expected("expected subtree".to_string()))? 182 .map_err(|()| ParseError::Expected("expected subtree".to_string()))?
168 .clone(); 183 .clone();
169 rhs.delimiter = tt::Delimiter::None; 184 rhs.delimiter = None;
170 Ok(crate::Rule { lhs, rhs }) 185 Ok(crate::Rule { lhs, rhs })
171 } 186 }
172} 187}