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.rs45
1 files changed, 21 insertions, 24 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 5e6a6f2a1..d8e344557 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -1,7 +1,7 @@
1use ra_parser::{TreeSink, ParseError}; 1use ra_parser::{TreeSink, ParseError};
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, SyntaxNode, TextRange, SyntaxKind, SmolStr, SyntaxTreeBuilder, TreeArc, SyntaxElement, 3 AstNode, SyntaxNode, TextRange, SyntaxKind, SmolStr, SyntaxTreeBuilder, TreeArc, SyntaxElement,
4 ast, SyntaxKind::*, TextUnit 4 ast, SyntaxKind::*, TextUnit, T
5}; 5};
6 6
7use crate::subtree_source::{SubtreeTokenSource, Querier}; 7use crate::subtree_source::{SubtreeTokenSource, Querier};
@@ -211,9 +211,9 @@ fn convert_tt(
211 let first_child = tt.first_child_or_token()?; 211 let first_child = tt.first_child_or_token()?;
212 let last_child = tt.last_child_or_token()?; 212 let last_child = tt.last_child_or_token()?;
213 let (delimiter, skip_first) = match (first_child.kind(), last_child.kind()) { 213 let (delimiter, skip_first) = match (first_child.kind(), last_child.kind()) {
214 (L_PAREN, R_PAREN) => (tt::Delimiter::Parenthesis, true), 214 (T!['('], T![')']) => (tt::Delimiter::Parenthesis, true),
215 (L_CURLY, R_CURLY) => (tt::Delimiter::Brace, true), 215 (T!['{'], T!['}']) => (tt::Delimiter::Brace, true),
216 (L_BRACK, R_BRACK) => (tt::Delimiter::Bracket, true), 216 (T!['['], T![']']) => (tt::Delimiter::Bracket, true),
217 _ => (tt::Delimiter::None, false), 217 _ => (tt::Delimiter::None, false),
218 }; 218 };
219 219
@@ -248,23 +248,22 @@ fn convert_tt(
248 248
249 token_trees.push(tt::Leaf::from(tt::Punct { char, spacing }).into()); 249 token_trees.push(tt::Leaf::from(tt::Punct { char, spacing }).into());
250 } else { 250 } else {
251 let child: tt::TokenTree = if token.kind() == SyntaxKind::TRUE_KW 251 let child: tt::TokenTree =
252 || token.kind() == SyntaxKind::FALSE_KW 252 if token.kind() == T![true] || token.kind() == T![false] {
253 { 253 tt::Leaf::from(tt::Literal { text: token.text().clone() }).into()
254 tt::Leaf::from(tt::Literal { text: token.text().clone() }).into() 254 } else if token.kind().is_keyword()
255 } else if token.kind().is_keyword() 255 || token.kind() == IDENT
256 || token.kind() == IDENT 256 || token.kind() == LIFETIME
257 || token.kind() == LIFETIME 257 {
258 { 258 let relative_range = token.range() - global_offset;
259 let relative_range = token.range() - global_offset; 259 let id = token_map.alloc(relative_range);
260 let id = token_map.alloc(relative_range); 260 let text = token.text().clone();
261 let text = token.text().clone(); 261 tt::Leaf::from(tt::Ident { text, id }).into()
262 tt::Leaf::from(tt::Ident { text, id }).into() 262 } else if token.kind().is_literal() {
263 } else if token.kind().is_literal() { 263 tt::Leaf::from(tt::Literal { text: token.text().clone() }).into()
264 tt::Leaf::from(tt::Literal { text: token.text().clone() }).into() 264 } else {
265 } else { 265 return None;
266 return None; 266 };
267 };
268 token_trees.push(child); 267 token_trees.push(child);
269 } 268 }
270 } 269 }
@@ -305,10 +304,8 @@ impl<'a, Q: Querier> TtTreeSink<'a, Q> {
305} 304}
306 305
307fn is_delimiter(kind: SyntaxKind) -> bool { 306fn is_delimiter(kind: SyntaxKind) -> bool {
308 use SyntaxKind::*;
309
310 match kind { 307 match kind {
311 L_PAREN | L_BRACK | L_CURLY | R_PAREN | R_BRACK | R_CURLY => true, 308 T!['('] | T!['['] | T!['{'] | T![')'] | T![']'] | T!['}'] => true,
312 _ => false, 309 _ => false,
313 } 310 }
314} 311}