diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/tokens.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/tokens.rs | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index ec3b4e553..3e5c56b19 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs | |||
@@ -192,7 +192,7 @@ pub enum FormatSpecifier { | |||
192 | } | 192 | } |
193 | 193 | ||
194 | pub trait HasFormatSpecifier: AstToken { | 194 | pub trait HasFormatSpecifier: AstToken { |
195 | fn lex_format_specifier<F>(&self, callback: &mut F) | 195 | fn lex_format_specifier<F>(&self, mut callback: F) |
196 | where | 196 | where |
197 | F: FnMut(TextRange, FormatSpecifier), | 197 | F: FnMut(TextRange, FormatSpecifier), |
198 | { | 198 | { |
@@ -217,21 +217,15 @@ pub trait HasFormatSpecifier: AstToken { | |||
217 | FormatSpecifier::Open, | 217 | FormatSpecifier::Open, |
218 | ); | 218 | ); |
219 | 219 | ||
220 | let next_char = if let Some(c) = chars.clone().next() { | ||
221 | c | ||
222 | } else { | ||
223 | break; | ||
224 | }; | ||
225 | |||
226 | // check for integer/identifier | 220 | // check for integer/identifier |
227 | match next_char { | 221 | match chars.clone().next().unwrap_or_default() { |
228 | '0'..='9' => { | 222 | '0'..='9' => { |
229 | // integer | 223 | // integer |
230 | read_integer(&mut chars, initial_len, callback); | 224 | read_integer(&mut chars, initial_len, &mut callback); |
231 | } | 225 | } |
232 | 'a'..='z' | 'A'..='Z' | '_' => { | 226 | 'a'..='z' | 'A'..='Z' | '_' => { |
233 | // identifier | 227 | // identifier |
234 | read_identifier(&mut chars, initial_len, callback); | 228 | read_identifier(&mut chars, initial_len, &mut callback); |
235 | } | 229 | } |
236 | _ => {} | 230 | _ => {} |
237 | } | 231 | } |
@@ -241,7 +235,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
241 | &mut chars, | 235 | &mut chars, |
242 | initial_len, | 236 | initial_len, |
243 | FormatSpecifier::Colon, | 237 | FormatSpecifier::Colon, |
244 | callback, | 238 | &mut callback, |
245 | ); | 239 | ); |
246 | 240 | ||
247 | // check for fill/align | 241 | // check for fill/align |
@@ -255,13 +249,13 @@ pub trait HasFormatSpecifier: AstToken { | |||
255 | &mut chars, | 249 | &mut chars, |
256 | initial_len, | 250 | initial_len, |
257 | FormatSpecifier::Fill, | 251 | FormatSpecifier::Fill, |
258 | callback, | 252 | &mut callback, |
259 | ); | 253 | ); |
260 | skip_char_and_emit( | 254 | skip_char_and_emit( |
261 | &mut chars, | 255 | &mut chars, |
262 | initial_len, | 256 | initial_len, |
263 | FormatSpecifier::Align, | 257 | FormatSpecifier::Align, |
264 | callback, | 258 | &mut callback, |
265 | ); | 259 | ); |
266 | } | 260 | } |
267 | _ => match first { | 261 | _ => match first { |
@@ -270,7 +264,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
270 | &mut chars, | 264 | &mut chars, |
271 | initial_len, | 265 | initial_len, |
272 | FormatSpecifier::Align, | 266 | FormatSpecifier::Align, |
273 | callback, | 267 | &mut callback, |
274 | ); | 268 | ); |
275 | } | 269 | } |
276 | _ => {} | 270 | _ => {} |
@@ -284,7 +278,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
284 | &mut chars, | 278 | &mut chars, |
285 | initial_len, | 279 | initial_len, |
286 | FormatSpecifier::Sign, | 280 | FormatSpecifier::Sign, |
287 | callback, | 281 | &mut callback, |
288 | ); | 282 | ); |
289 | } | 283 | } |
290 | _ => {} | 284 | _ => {} |
@@ -296,7 +290,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
296 | &mut chars, | 290 | &mut chars, |
297 | initial_len, | 291 | initial_len, |
298 | FormatSpecifier::NumberSign, | 292 | FormatSpecifier::NumberSign, |
299 | callback, | 293 | &mut callback, |
300 | ); | 294 | ); |
301 | } | 295 | } |
302 | 296 | ||
@@ -310,25 +304,25 @@ pub trait HasFormatSpecifier: AstToken { | |||
310 | &mut chars, | 304 | &mut chars, |
311 | initial_len, | 305 | initial_len, |
312 | FormatSpecifier::Zero, | 306 | FormatSpecifier::Zero, |
313 | callback, | 307 | &mut callback, |
314 | ); | 308 | ); |
315 | } | 309 | } |
316 | 310 | ||
317 | // width | 311 | // width |
318 | match chars.clone().next().unwrap_or_default() { | 312 | match chars.clone().next().unwrap_or_default() { |
319 | '0'..='9' => { | 313 | '0'..='9' => { |
320 | read_integer(&mut chars, initial_len, callback); | 314 | read_integer(&mut chars, initial_len, &mut callback); |
321 | if chars.clone().next() == Some('$') { | 315 | if chars.clone().next() == Some('$') { |
322 | skip_char_and_emit( | 316 | skip_char_and_emit( |
323 | &mut chars, | 317 | &mut chars, |
324 | initial_len, | 318 | initial_len, |
325 | FormatSpecifier::DollarSign, | 319 | FormatSpecifier::DollarSign, |
326 | callback, | 320 | &mut callback, |
327 | ); | 321 | ); |
328 | } | 322 | } |
329 | } | 323 | } |
330 | 'a'..='z' | 'A'..='Z' | '_' => { | 324 | 'a'..='z' | 'A'..='Z' | '_' => { |
331 | read_identifier(&mut chars, initial_len, callback); | 325 | read_identifier(&mut chars, initial_len, &mut callback); |
332 | if chars.clone().next() != Some('$') { | 326 | if chars.clone().next() != Some('$') { |
333 | continue; | 327 | continue; |
334 | } | 328 | } |
@@ -336,7 +330,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
336 | &mut chars, | 330 | &mut chars, |
337 | initial_len, | 331 | initial_len, |
338 | FormatSpecifier::DollarSign, | 332 | FormatSpecifier::DollarSign, |
339 | callback, | 333 | &mut callback, |
340 | ); | 334 | ); |
341 | } | 335 | } |
342 | _ => {} | 336 | _ => {} |
@@ -348,7 +342,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
348 | &mut chars, | 342 | &mut chars, |
349 | initial_len, | 343 | initial_len, |
350 | FormatSpecifier::Dot, | 344 | FormatSpecifier::Dot, |
351 | callback, | 345 | &mut callback, |
352 | ); | 346 | ); |
353 | 347 | ||
354 | match chars.clone().next().unwrap_or_default() { | 348 | match chars.clone().next().unwrap_or_default() { |
@@ -357,22 +351,22 @@ pub trait HasFormatSpecifier: AstToken { | |||
357 | &mut chars, | 351 | &mut chars, |
358 | initial_len, | 352 | initial_len, |
359 | FormatSpecifier::Asterisk, | 353 | FormatSpecifier::Asterisk, |
360 | callback, | 354 | &mut callback, |
361 | ); | 355 | ); |
362 | } | 356 | } |
363 | '0'..='9' => { | 357 | '0'..='9' => { |
364 | read_integer(&mut chars, initial_len, callback); | 358 | read_integer(&mut chars, initial_len, &mut callback); |
365 | if chars.clone().next() == Some('$') { | 359 | if chars.clone().next() == Some('$') { |
366 | skip_char_and_emit( | 360 | skip_char_and_emit( |
367 | &mut chars, | 361 | &mut chars, |
368 | initial_len, | 362 | initial_len, |
369 | FormatSpecifier::DollarSign, | 363 | FormatSpecifier::DollarSign, |
370 | callback, | 364 | &mut callback, |
371 | ); | 365 | ); |
372 | } | 366 | } |
373 | } | 367 | } |
374 | 'a'..='z' | 'A'..='Z' | '_' => { | 368 | 'a'..='z' | 'A'..='Z' | '_' => { |
375 | read_identifier(&mut chars, initial_len, callback); | 369 | read_identifier(&mut chars, initial_len, &mut callback); |
376 | if chars.clone().next() != Some('$') { | 370 | if chars.clone().next() != Some('$') { |
377 | continue; | 371 | continue; |
378 | } | 372 | } |
@@ -380,7 +374,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
380 | &mut chars, | 374 | &mut chars, |
381 | initial_len, | 375 | initial_len, |
382 | FormatSpecifier::DollarSign, | 376 | FormatSpecifier::DollarSign, |
383 | callback, | 377 | &mut callback, |
384 | ); | 378 | ); |
385 | } | 379 | } |
386 | _ => { | 380 | _ => { |
@@ -396,11 +390,11 @@ pub trait HasFormatSpecifier: AstToken { | |||
396 | &mut chars, | 390 | &mut chars, |
397 | initial_len, | 391 | initial_len, |
398 | FormatSpecifier::QuestionMark, | 392 | FormatSpecifier::QuestionMark, |
399 | callback, | 393 | &mut callback, |
400 | ); | 394 | ); |
401 | } | 395 | } |
402 | 'a'..='z' | 'A'..='Z' | '_' => { | 396 | 'a'..='z' | 'A'..='Z' | '_' => { |
403 | read_identifier(&mut chars, initial_len, callback); | 397 | read_identifier(&mut chars, initial_len, &mut callback); |
404 | } | 398 | } |
405 | _ => {} | 399 | _ => {} |
406 | } | 400 | } |
@@ -416,7 +410,12 @@ pub trait HasFormatSpecifier: AstToken { | |||
416 | // Escaped format end specifier, `}}` | 410 | // Escaped format end specifier, `}}` |
417 | continue; | 411 | continue; |
418 | } | 412 | } |
419 | skip_char_and_emit(&mut chars, initial_len, FormatSpecifier::Close, callback); | 413 | skip_char_and_emit( |
414 | &mut chars, | ||
415 | initial_len, | ||
416 | FormatSpecifier::Close, | ||
417 | &mut callback, | ||
418 | ); | ||
420 | } | 419 | } |
421 | _ => { | 420 | _ => { |
422 | while let Some(next_char) = chars.clone().next() { | 421 | while let Some(next_char) = chars.clone().next() { |