MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / consume_hex_number

Method consume_hex_number

crates/gitql-parser/src/tokenizer.rs:611–646  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

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('\'')?;

Callers 1

tokenize_charactersMethod · 0.80

Calls 7

is_current_char_funcMethod · 0.80
advanceMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80
add_helpMethod · 0.80
add_noteMethod · 0.80

Tested by

no test coverage detected