(&mut self)
| 609 | } |
| 610 | |
| 611 | fn consume_hex_number(&mut self) -> Result<Token, Box<Diagnostic>> { |
| 612 | let start_index = self.index; |
| 613 | while self.is_current_char_func(|c| c == '_' || c.is_ascii_hexdigit()) { |
| 614 | self.advance(); |
| 615 | } |
| 616 | |
| 617 | if start_index == self.index { |
| 618 | return Err( |
| 619 | Diagnostic::error("Missing digits after the integer base prefix") |
| 620 | .add_help("Expect at least one hex digits after the prefix 0x") |
| 621 | .add_help("Hex digit mean 0 to 9 and a to f") |
| 622 | .with_location(self.current_source_location()) |
| 623 | .as_boxed(), |
| 624 | ); |
| 625 | } |
| 626 | |
| 627 | let literal = &self.content[start_index..self.index]; |
| 628 | let string: String = literal.iter().collect(); |
| 629 | let literal_num = string.replace('_', ""); |
| 630 | |
| 631 | const HEX_RADIX: u32 = 16; |
| 632 | match i64::from_str_radix(&literal_num, HEX_RADIX) { |
| 633 | Ok(integer) => { |
| 634 | let location = self.current_source_location(); |
| 635 | Ok(Token::new(TokenKind::Integer(integer), location)) |
| 636 | } |
| 637 | Err(parse_int_error) => Err(Diagnostic::error(&parse_int_error.to_string()) |
| 638 | .add_note(&format!( |
| 639 | "Value must be between {} and {}", |
| 640 | i64::MIN, |
| 641 | i64::MAX |
| 642 | )) |
| 643 | .with_location(self.current_source_location()) |
| 644 | .as_boxed()), |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | fn consume_string_in_single_quotes(&mut self) -> Result<Token, Box<Diagnostic>> { |
| 649 | let buffer = self.consume_string_with_around('\'')?; |
no test coverage detected