diff options
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/subtree_source.rs | 22 | ||||
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 45 |
2 files changed, 32 insertions, 35 deletions
diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs index 3554dc110..c938acf64 100644 --- a/crates/ra_mbe/src/subtree_source.rs +++ b/crates/ra_mbe/src/subtree_source.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_parser::{TokenSource}; | 1 | use ra_parser::{TokenSource}; |
2 | use ra_syntax::{classify_literal, SmolStr, SyntaxKind, SyntaxKind::*}; | 2 | use ra_syntax::{classify_literal, SmolStr, SyntaxKind, SyntaxKind::*, T}; |
3 | use std::cell::{RefCell}; | 3 | use std::cell::{RefCell}; |
4 | 4 | ||
5 | // A Sequece of Token, | 5 | // A Sequece of Token, |
@@ -284,9 +284,9 @@ impl<'a> TokenSource for SubtreeTokenSource<'a> { | |||
284 | 284 | ||
285 | fn convert_delim(d: tt::Delimiter, closing: bool) -> TtToken { | 285 | fn convert_delim(d: tt::Delimiter, closing: bool) -> TtToken { |
286 | let (kinds, texts) = match d { | 286 | let (kinds, texts) = match d { |
287 | tt::Delimiter::Parenthesis => ([L_PAREN, R_PAREN], "()"), | 287 | tt::Delimiter::Parenthesis => ([T!['('], T![')']], "()"), |
288 | tt::Delimiter::Brace => ([L_CURLY, R_CURLY], "{}"), | 288 | tt::Delimiter::Brace => ([T!['{'], T!['}']], "{}"), |
289 | tt::Delimiter::Bracket => ([L_BRACK, R_BRACK], "[]"), | 289 | tt::Delimiter::Bracket => ([T!['['], T![']']], "[]"), |
290 | tt::Delimiter::None => ([L_DOLLAR, R_DOLLAR], ""), | 290 | tt::Delimiter::None => ([L_DOLLAR, R_DOLLAR], ""), |
291 | }; | 291 | }; |
292 | 292 | ||
@@ -299,8 +299,8 @@ fn convert_delim(d: tt::Delimiter, closing: bool) -> TtToken { | |||
299 | fn convert_literal(l: &tt::Literal) -> TtToken { | 299 | fn convert_literal(l: &tt::Literal) -> TtToken { |
300 | let kind = | 300 | let kind = |
301 | classify_literal(&l.text).map(|tkn| tkn.kind).unwrap_or_else(|| match l.text.as_ref() { | 301 | classify_literal(&l.text).map(|tkn| tkn.kind).unwrap_or_else(|| match l.text.as_ref() { |
302 | "true" => SyntaxKind::TRUE_KW, | 302 | "true" => T![true], |
303 | "false" => SyntaxKind::FALSE_KW, | 303 | "false" => T![false], |
304 | _ => panic!("Fail to convert given literal {:#?}", &l), | 304 | _ => panic!("Fail to convert given literal {:#?}", &l), |
305 | }); | 305 | }); |
306 | 306 | ||
@@ -320,11 +320,11 @@ fn convert_ident(ident: &tt::Ident) -> TtToken { | |||
320 | fn convert_punct(p: &tt::Punct) -> TtToken { | 320 | fn convert_punct(p: &tt::Punct) -> TtToken { |
321 | let kind = match p.char { | 321 | let kind = match p.char { |
322 | // lexer may produce compound tokens for these ones | 322 | // lexer may produce compound tokens for these ones |
323 | '.' => DOT, | 323 | '.' => T![.], |
324 | ':' => COLON, | 324 | ':' => T![:], |
325 | '=' => EQ, | 325 | '=' => T![=], |
326 | '!' => EXCL, | 326 | '!' => T![!], |
327 | '-' => MINUS, | 327 | '-' => T![-], |
328 | c => SyntaxKind::from_char(c).unwrap(), | 328 | c => SyntaxKind::from_char(c).unwrap(), |
329 | }; | 329 | }; |
330 | let text = { | 330 | let text = { |
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 @@ | |||
1 | use ra_parser::{TreeSink, ParseError}; | 1 | use ra_parser::{TreeSink, ParseError}; |
2 | use ra_syntax::{ | 2 | use 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 | ||
7 | use crate::subtree_source::{SubtreeTokenSource, Querier}; | 7 | use 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 | ||
307 | fn is_delimiter(kind: SyntaxKind) -> bool { | 306 | fn 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 | } |