aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src/syntax_bridge.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-05-02 03:02:17 +0100
committerEdwin Cheng <[email protected]>2019-05-02 03:02:17 +0100
commit6b2985ebc7327756d562d6af153a8b32ffaa8471 (patch)
treecabe40801059eb5283019982c0091ddb454c6e9a /crates/ra_mbe/src/syntax_bridge.rs
parent12629d5e4f2d949eedb707dedad4d75eff09e683 (diff)
Remove unused code and add space bewteen tt
Diffstat (limited to 'crates/ra_mbe/src/syntax_bridge.rs')
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs64
1 files changed, 34 insertions, 30 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index e0f228ce9..3521b382a 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -148,30 +148,21 @@ fn convert_tt(
148 match child { 148 match child {
149 SyntaxElement::Token(token) => { 149 SyntaxElement::Token(token) => {
150 if token.kind().is_punct() { 150 if token.kind().is_punct() {
151 let mut prev = None; 151 assert!(token.text().len() == 1, "Input ast::token punct must be single char.");
152 for char in token.text().chars() { 152 let char = token.text().chars().next().unwrap();
153 if let Some(char) = prev { 153
154 token_trees.push( 154 let spacing = match child_iter.peek() {
155 tt::Leaf::from(tt::Punct { char, spacing: tt::Spacing::Joint }) 155 Some(SyntaxElement::Token(token)) => {
156 .into(), 156 if token.kind().is_punct() {
157 ); 157 tt::Spacing::Joint
158 } 158 } else {
159 prev = Some(char) 159 tt::Spacing::Alone
160 }
161 if let Some(char) = prev {
162 let spacing = match child_iter.peek() {
163 Some(SyntaxElement::Token(token)) => {
164 if token.kind().is_punct() {
165 tt::Spacing::Joint
166 } else {
167 tt::Spacing::Alone
168 }
169 } 160 }
170 _ => tt::Spacing::Alone, 161 }
171 }; 162 _ => tt::Spacing::Alone,
163 };
172 164
173 token_trees.push(tt::Leaf::from(tt::Punct { char, spacing }).into()); 165 token_trees.push(tt::Leaf::from(tt::Punct { char, spacing }).into());
174 }
175 } else { 166 } else {
176 let child: tt::TokenTree = if token.kind() == SyntaxKind::TRUE_KW 167 let child: tt::TokenTree = if token.kind() == SyntaxKind::TRUE_KW
177 || token.kind() == SyntaxKind::FALSE_KW 168 || token.kind() == SyntaxKind::FALSE_KW
@@ -224,6 +215,15 @@ impl<'a, Q: Querier> TtTreeSink<'a, Q> {
224 } 215 }
225} 216}
226 217
218fn is_delimiter(kind: SyntaxKind) -> bool {
219 use SyntaxKind::*;
220
221 match kind {
222 L_PAREN | L_BRACK | L_CURLY | R_PAREN | R_BRACK | R_CURLY => true,
223 _ => false,
224 }
225}
226
227impl<'a, Q: Querier> TreeSink for TtTreeSink<'a, Q> { 227impl<'a, Q: Querier> TreeSink for TtTreeSink<'a, Q> {
228 fn token(&mut self, kind: SyntaxKind, n_tokens: u8) { 228 fn token(&mut self, kind: SyntaxKind, n_tokens: u8) {
229 if kind == L_DOLLAR || kind == R_DOLLAR { 229 if kind == L_DOLLAR || kind == R_DOLLAR {
@@ -240,14 +240,18 @@ impl<'a, Q: Querier> TreeSink for TtTreeSink<'a, Q> {
240 self.buf.clear(); 240 self.buf.clear();
241 self.inner.token(kind, text); 241 self.inner.token(kind, text);
242 242
243 // // Add a white space to token 243 // Add a white space between tokens, only if both are not delimiters
244 // let (last_kind, _, last_joint_to_next ) = self.src_querier.token(self.token_pos-n_tokens as usize); 244 if !is_delimiter(kind) {
245 // if !last_joint_to_next && last_kind.is_punct() { 245 let (last_kind, _, last_joint_to_next) = self.src_querier.token(self.token_pos - 1);
246 // let (cur_kind, _, _ ) = self.src_querier.token(self.token_pos); 246 if !last_joint_to_next && last_kind.is_punct() {
247 // if cur_kind.is_punct() { 247 let (cur_kind, _, _) = self.src_querier.token(self.token_pos);
248 // self.inner.token(WHITESPACE, " ".into()); 248 if !is_delimiter(cur_kind) {
249 // } 249 if cur_kind.is_punct() {
250 // } 250 self.inner.token(WHITESPACE, " ".into());
251 }
252 }
253 }
254 }
251 } 255 }
252 256
253 fn start_node(&mut self, kind: SyntaxKind) { 257 fn start_node(&mut self, kind: SyntaxKind) {