aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/syntax_bridge.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src/syntax_bridge.rs')
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs34
1 files changed, 16 insertions, 18 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 66c1f0337..b8e2cfc1d 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -51,7 +51,7 @@ pub fn token_tree_to_syntax_node(
51) -> Result<(Parse<SyntaxNode>, TokenMap), ExpandError> { 51) -> Result<(Parse<SyntaxNode>, TokenMap), ExpandError> {
52 let tmp; 52 let tmp;
53 let tokens = match tt { 53 let tokens = match tt {
54 tt::Subtree { delimiter: tt::Delimiter::None, token_trees } => token_trees.as_slice(), 54 tt::Subtree { delimiter: None, token_trees } => token_trees.as_slice(),
55 _ => { 55 _ => {
56 tmp = [tt.clone().into()]; 56 tmp = [tt.clone().into()];
57 &tmp[..] 57 &tmp[..]
@@ -121,7 +121,7 @@ fn convert_doc_comment(token: &ra_syntax::SyntaxToken) -> Option<Vec<tt::TokenTr
121 token_trees.push(mk_punct('!')); 121 token_trees.push(mk_punct('!'));
122 } 122 }
123 token_trees.push(tt::TokenTree::from(tt::Subtree { 123 token_trees.push(tt::TokenTree::from(tt::Subtree {
124 delimiter: tt::Delimiter::Bracket, 124 delimiter: Some(tt::Delimiter::Bracket),
125 token_trees: meta_tkns, 125 token_trees: meta_tkns,
126 })); 126 }));
127 127
@@ -156,7 +156,7 @@ impl Convertor {
156 fn go(&mut self, tt: &SyntaxNode) -> Option<tt::Subtree> { 156 fn go(&mut self, tt: &SyntaxNode) -> Option<tt::Subtree> {
157 // This tree is empty 157 // This tree is empty
158 if tt.first_child_or_token().is_none() { 158 if tt.first_child_or_token().is_none() {
159 return Some(tt::Subtree { token_trees: vec![], delimiter: tt::Delimiter::None }); 159 return Some(tt::Subtree { token_trees: vec![], delimiter: None });
160 } 160 }
161 161
162 let first_child = tt.first_child_or_token()?; 162 let first_child = tt.first_child_or_token()?;
@@ -173,7 +173,7 @@ impl Convertor {
173 .last() 173 .last()
174 .unwrap(); 174 .unwrap();
175 if first_child.kind().is_trivia() { 175 if first_child.kind().is_trivia() {
176 return Some(tt::Subtree { token_trees: vec![], delimiter: tt::Delimiter::None }); 176 return Some(tt::Subtree { token_trees: vec![], delimiter: None });
177 } 177 }
178 178
179 let last_child = successors(Some(last_child), |it| { 179 let last_child = successors(Some(last_child), |it| {
@@ -187,10 +187,10 @@ impl Convertor {
187 .unwrap(); 187 .unwrap();
188 188
189 let (delimiter, skip_first) = match (first_child.kind(), last_child.kind()) { 189 let (delimiter, skip_first) = match (first_child.kind(), last_child.kind()) {
190 (T!['('], T![')']) => (tt::Delimiter::Parenthesis, true), 190 (T!['('], T![')']) => (Some(tt::Delimiter::Parenthesis), true),
191 (T!['{'], T!['}']) => (tt::Delimiter::Brace, true), 191 (T!['{'], T!['}']) => (Some(tt::Delimiter::Brace), true),
192 (T!['['], T![']']) => (tt::Delimiter::Bracket, true), 192 (T!['['], T![']']) => (Some(tt::Delimiter::Bracket), true),
193 _ => (tt::Delimiter::None, false), 193 _ => (None, false),
194 }; 194 };
195 195
196 let mut token_trees = Vec::new(); 196 let mut token_trees = Vec::new();
@@ -246,9 +246,7 @@ impl Convertor {
246 } 246 }
247 NodeOrToken::Node(node) => { 247 NodeOrToken::Node(node) => {
248 let child_subtree = self.go(&node)?; 248 let child_subtree = self.go(&node)?;
249 if child_subtree.delimiter == tt::Delimiter::None 249 if child_subtree.delimiter.is_none() && node.kind() != SyntaxKind::TOKEN_TREE {
250 && node.kind() != SyntaxKind::TOKEN_TREE
251 {
252 token_trees.extend(child_subtree.token_trees); 250 token_trees.extend(child_subtree.token_trees);
253 } else { 251 } else {
254 token_trees.push(child_subtree.into()); 252 token_trees.push(child_subtree.into());
@@ -299,16 +297,16 @@ impl<'a> TtTreeSink<'a> {
299 } 297 }
300} 298}
301 299
302fn delim_to_str(d: tt::Delimiter, closing: bool) -> SmolStr { 300fn delim_to_str(d: Option<tt::Delimiter>, closing: bool) -> SmolStr {
303 let texts = match d { 301 let texts = match d {
304 tt::Delimiter::Parenthesis => "()", 302 Some(tt::Delimiter::Parenthesis) => "()",
305 tt::Delimiter::Brace => "{}", 303 Some(tt::Delimiter::Brace) => "{}",
306 tt::Delimiter::Bracket => "[]", 304 Some(tt::Delimiter::Bracket) => "[]",
307 tt::Delimiter::None => "", 305 None => return "".into(),
308 }; 306 };
309 307
310 let idx = closing as usize; 308 let idx = closing as usize;
311 let text = if !texts.is_empty() { &texts[idx..texts.len() - (1 - idx)] } else { "" }; 309 let text = &texts[idx..texts.len() - (1 - idx)];
312 text.into() 310 text.into()
313} 311}
314 312
@@ -497,7 +495,7 @@ mod tests {
497 let token_tree = ast::TokenTree::cast(token_tree).unwrap(); 495 let token_tree = ast::TokenTree::cast(token_tree).unwrap();
498 let tt = ast_to_token_tree(&token_tree).unwrap().0; 496 let tt = ast_to_token_tree(&token_tree).unwrap().0;
499 497
500 assert_eq!(tt.delimiter, tt::Delimiter::Brace); 498 assert_eq!(tt.delimiter, Some(tt::Delimiter::Brace));
501 } 499 }
502 500
503 #[test] 501 #[test]