Scans numeric literals (integers and floats)
(&mut self)
| 389 | |
| 390 | // Scans numeric literals (integers and floats) |
| 391 | fn scan_number(&mut self) -> Token<'a> { |
| 392 | self.consume_digits(); |
| 393 | // Look for a fractional part. |
| 394 | if self.source[self.current..].len() >= 2 { |
| 395 | let mut next_two_chars = self.source[self.current..self.current + 2].chars(); |
| 396 | let (maybe_dot, maybe_digit) = (next_two_chars.next(), next_two_chars.next()); |
| 397 | if maybe_dot == Some('.') && matches!(maybe_digit, Some(c) if c.is_ascii_digit()) { |
| 398 | // Consume the "." |
| 399 | self.advance(); |
| 400 | |
| 401 | self.consume_digits(); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | self.make_token(TokenType::Number) |
| 406 | } |
| 407 | |
| 408 | // Helper method to consume consecutive digits |
| 409 | fn consume_digits(&mut self) { |
no test coverage detected