(&mut self)
| 486 | } |
| 487 | |
| 488 | fn consume_number(&mut self) -> Result<Token, Box<Diagnostic>> { |
| 489 | let start_index = self.index; |
| 490 | |
| 491 | while self.is_current_char_func(|c| c == '_' || c.is_numeric()) { |
| 492 | self.advance(); |
| 493 | } |
| 494 | |
| 495 | let mut is_float_value = false; |
| 496 | if self.is_current_char('.') { |
| 497 | self.advance(); |
| 498 | |
| 499 | is_float_value = true; |
| 500 | while self.is_current_char_func(|c| c == '_' || c.is_numeric()) { |
| 501 | self.advance(); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | let literal = &self.content[start_index..self.index]; |
| 506 | let string: String = literal.iter().collect(); |
| 507 | let literal_num = string.replace('_', ""); |
| 508 | let location = self.current_source_location(); |
| 509 | |
| 510 | if is_float_value { |
| 511 | return match literal_num.parse::<f64>() { |
| 512 | Ok(float) => Ok(Token::new(TokenKind::Float(float), location)), |
| 513 | Err(parse_float_error) => Err(Diagnostic::error(&parse_float_error.to_string()) |
| 514 | .add_note(&format!( |
| 515 | "Value must be between {} and {}", |
| 516 | f64::MIN, |
| 517 | f64::MAX |
| 518 | )) |
| 519 | .with_location(self.current_source_location()) |
| 520 | .as_boxed()), |
| 521 | }; |
| 522 | } |
| 523 | |
| 524 | match literal_num.parse::<i64>() { |
| 525 | Ok(integer) => Ok(Token::new(TokenKind::Integer(integer), location)), |
| 526 | Err(parse_int_error) => Err(Diagnostic::error(&parse_int_error.to_string()) |
| 527 | .add_note(&format!( |
| 528 | "Value must be between {} and {}", |
| 529 | i64::MIN, |
| 530 | i64::MAX |
| 531 | )) |
| 532 | .with_location(self.current_source_location()) |
| 533 | .as_boxed()), |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | fn consume_binary_number(&mut self) -> Result<Token, Box<Diagnostic>> { |
| 538 | let start_index = self.index; |
no test coverage detected