diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-15 13:45:58 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-15 13:45:58 +0100 |
commit | ec7d2f64ade9ffa35a64e82ac53e65ad5cbe9efd (patch) | |
tree | b8693ce808a9ca2e7eaae5013644a1082fc7bb17 /crates/ra_mbe/src/syntax_bridge.rs | |
parent | 64ab5ab10d32e7e8ec085af818d3d94211aea39b (diff) | |
parent | 993abedd77cf23ce2281b6c8e60cab49ab4fa97e (diff) |
Merge #1278
1278: Apply T! macro where posible r=matklad a=pasa
apply T! macro implemented in #1248
Co-authored-by: Sergey Parilin <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src/syntax_bridge.rs')
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 45 |
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 @@ | |||
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 | } |