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

Method consume_binary_number

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

Source from the content-addressed store, hash-verified

535 }
536
537 fn consume_binary_number(&mut self) -> Result<Token, Box<Diagnostic>> {
538 let start_index = self.index;
539 while self.is_current_char_func(|c| c == '_' || c == '0' || c >= '1') {
540 self.advance();
541 }
542
543 if start_index == self.index {
544 return Err(
545 Diagnostic::error("Missing digits after the integer base prefix")
546 .add_help("Expect at least one binary digits after the prefix 0b")
547 .add_help("Binary digit mean 0 or 1")
548 .with_location(self.current_source_location())
549 .as_boxed(),
550 );
551 }
552
553 let literal = &self.content[start_index..self.index];
554 let string: String = literal.iter().collect();
555 let literal_num = string.replace('_', "");
556
557 const BINARY_RADIX: u32 = 2;
558 match i64::from_str_radix(&literal_num, BINARY_RADIX) {
559 Ok(integer) => {
560 let location = self.current_source_location();
561 Ok(Token::new(TokenKind::Integer(integer), location))
562 }
563 Err(parse_int_error) => Err(Diagnostic::error(&parse_int_error.to_string())
564 .add_note(&format!(
565 "Value must be between {} and {}",
566 i64::MIN,
567 i64::MAX
568 ))
569 .with_location(self.current_source_location())
570 .as_boxed()),
571 }
572 }
573
574 fn consume_octal_number(&mut self) -> Result<Token, Box<Diagnostic>> {
575 let start_index = self.index;

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