diff options
Diffstat (limited to 'crates/ra_mbe/src/syntax_bridge.rs')
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index b8e2cfc1d..8f65ff125 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -136,11 +136,15 @@ fn convert_doc_comment(token: &ra_syntax::SyntaxToken) -> Option<Vec<tt::TokenTr | |||
136 | } | 136 | } |
137 | 137 | ||
138 | fn mk_punct(c: char) -> tt::TokenTree { | 138 | fn mk_punct(c: char) -> tt::TokenTree { |
139 | tt::TokenTree::from(tt::Leaf::from(tt::Punct { char: c, spacing: tt::Spacing::Alone })) | 139 | tt::TokenTree::from(tt::Leaf::from(tt::Punct { |
140 | char: c, | ||
141 | spacing: tt::Spacing::Alone, | ||
142 | id: tt::TokenId::unspecified(), | ||
143 | })) | ||
140 | } | 144 | } |
141 | 145 | ||
142 | fn mk_doc_literal(comment: &ast::Comment) -> tt::TokenTree { | 146 | fn mk_doc_literal(comment: &ast::Comment) -> tt::TokenTree { |
143 | let lit = tt::Literal { text: doc_comment_text(comment) }; | 147 | let lit = tt::Literal { text: doc_comment_text(comment), id: tt::TokenId::unspecified() }; |
144 | 148 | ||
145 | tt::TokenTree::from(tt::Leaf::from(lit)) | 149 | tt::TokenTree::from(tt::Leaf::from(lit)) |
146 | } | 150 | } |
@@ -223,24 +227,29 @@ impl Convertor { | |||
223 | .take(token.text().len() - 1) | 227 | .take(token.text().len() - 1) |
224 | .chain(std::iter::once(last_spacing)); | 228 | .chain(std::iter::once(last_spacing)); |
225 | for (char, spacing) in token.text().chars().zip(spacing_iter) { | 229 | for (char, spacing) in token.text().chars().zip(spacing_iter) { |
226 | token_trees.push(tt::Leaf::from(tt::Punct { char, spacing }).into()); | 230 | let id = self.alloc(token.text_range()); |
231 | token_trees | ||
232 | .push(tt::Leaf::from(tt::Punct { char, spacing, id }).into()); | ||
227 | } | 233 | } |
228 | } else { | 234 | } else { |
229 | let child: tt::TokenTree = | 235 | let child: tt::TokenTree = if token.kind() == T![true] |
230 | if token.kind() == T![true] || token.kind() == T![false] { | 236 | || token.kind() == T![false] |
231 | tt::Leaf::from(tt::Literal { text: token.text().clone() }).into() | 237 | { |
232 | } else if token.kind().is_keyword() | 238 | let id = self.alloc(token.text_range()); |
233 | || token.kind() == IDENT | 239 | tt::Leaf::from(tt::Literal { text: token.text().clone(), id }).into() |
234 | || token.kind() == LIFETIME | 240 | } else if token.kind().is_keyword() |
235 | { | 241 | || token.kind() == IDENT |
236 | let id = self.alloc(token.text_range()); | 242 | || token.kind() == LIFETIME |
237 | let text = token.text().clone(); | 243 | { |
238 | tt::Leaf::from(tt::Ident { text, id }).into() | 244 | let id = self.alloc(token.text_range()); |
239 | } else if token.kind().is_literal() { | 245 | let text = token.text().clone(); |
240 | tt::Leaf::from(tt::Literal { text: token.text().clone() }).into() | 246 | tt::Leaf::from(tt::Ident { text, id }).into() |
241 | } else { | 247 | } else if token.kind().is_literal() { |
242 | return None; | 248 | let id = self.alloc(token.text_range()); |
243 | }; | 249 | tt::Leaf::from(tt::Literal { text: token.text().clone(), id }).into() |
250 | } else { | ||
251 | return None; | ||
252 | }; | ||
244 | token_trees.push(child); | 253 | token_trees.push(child); |
245 | } | 254 | } |
246 | } | 255 | } |