aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/syntax_bridge.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-04-24 16:01:32 +0100
committerEdwin Cheng <[email protected]>2019-04-25 19:03:55 +0100
commit299d97b6d98cec673ff056c188ac45a17febc7d4 (patch)
treecaec1cdbcd6350d26ebe984b3eca177079aa02b3 /crates/ra_mbe/src/syntax_bridge.rs
parentdfab545d5df974d4a50325695a25f763b7613baf (diff)
Add handling `token` seperator in mbe
Diffstat (limited to 'crates/ra_mbe/src/syntax_bridge.rs')
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 38a481029..9cca19dbb 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -133,7 +133,9 @@ fn convert_tt(
133 }; 133 };
134 134
135 let mut token_trees = Vec::new(); 135 let mut token_trees = Vec::new();
136 for child in tt.children_with_tokens().skip(skip_first as usize) { 136 let mut child_iter = tt.children_with_tokens().skip(skip_first as usize).peekable();
137
138 while let Some(child) = child_iter.next() {
137 if (skip_first && (child == first_child || child == last_child)) || child.kind().is_trivia() 139 if (skip_first && (child == first_child || child == last_child)) || child.kind().is_trivia()
138 { 140 {
139 continue; 141 continue;
@@ -152,12 +154,25 @@ fn convert_tt(
152 prev = Some(char) 154 prev = Some(char)
153 } 155 }
154 if let Some(char) = prev { 156 if let Some(char) = prev {
155 token_trees.push( 157 let spacing = match child_iter.peek() {
156 tt::Leaf::from(tt::Punct { char, spacing: tt::Spacing::Alone }).into(), 158 Some(SyntaxElement::Token(token)) => {
157 ); 159 if token.kind().is_punct() {
160 tt::Spacing::Joint
161 } else {
162 tt::Spacing::Alone
163 }
164 }
165 _ => tt::Spacing::Alone,
166 };
167
168 token_trees.push(tt::Leaf::from(tt::Punct { char, spacing }).into());
158 } 169 }
159 } else { 170 } else {
160 let child: tt::TokenTree = if token.kind().is_keyword() 171 let child: tt::TokenTree = if token.kind() == SyntaxKind::TRUE_KW
172 || token.kind() == SyntaxKind::FALSE_KW
173 {
174 tt::Leaf::from(tt::Literal { text: token.text().clone() }).into()
175 } else if token.kind().is_keyword()
161 || token.kind() == IDENT 176 || token.kind() == IDENT
162 || token.kind() == LIFETIME 177 || token.kind() == LIFETIME
163 { 178 {