MCPcopy Index your code
hub / github.com/endbasic/endbasic / consume_integer_with_base

Method consume_integer_with_base

core/src/lexer.rs:388–430  ·  view source on GitHub ↗

Consumes the integer at the current position `pos`.

(&mut self, pos: LineCol)

Source from the content-addressed store, hash-verified

386
387 /// Consumes the integer at the current position `pos`.
388 fn consume_integer_with_base(&mut self, pos: LineCol) -> io::Result<TokenSpan> {
389 let mut prefix_len = 1; // Count '&'.
390
391 let base = match self.input.peek() {
392 Some(Ok(ch_span)) => {
393 let base = match ch_span.ch {
394 'b' | 'B' => 2,
395 'd' | 'D' => 10,
396 'o' | 'O' => 8,
397 'x' | 'X' => 16,
398 ch if ch.is_separator() => {
399 return self.handle_bad_read("Missing base in integer literal", pos);
400 }
401 _ => {
402 let ch_span = self.input.next().unwrap()?;
403 return self.handle_bad_read(
404 format!("Unknown base {} in integer literal", ch_span.ch),
405 pos,
406 );
407 }
408 };
409 self.input.next().unwrap()?;
410 base
411 }
412 Some(Err(_)) => return Err(self.input.next().unwrap().unwrap_err()),
413 None => {
414 return self.handle_bad_read("Incomplete integer due to EOF", pos);
415 }
416 };
417 prefix_len += 1; // Count the base.
418
419 match self.input.peek() {
420 Some(Ok(ch_span)) if ch_span.ch == '_' => {
421 self.input.next().unwrap().unwrap();
422 prefix_len += 1; // Count the '_'.
423 }
424 Some(Ok(_ch_span)) => (),
425 Some(Err(_)) => return Err(self.input.next().unwrap().unwrap_err()),
426 None => return self.handle_bad_read("Incomplete integer due to EOF", pos),
427 }
428
429 self.consume_integer(base, pos, prefix_len)
430 }
431
432 /// Consumes the operator at the current position, whose first character is `first`.
433 fn consume_operator(&mut self, first: CharSpan) -> io::Result<TokenSpan> {

Callers 1

readMethod · 0.80

Calls 5

is_separatorMethod · 0.80
handle_bad_readMethod · 0.80
consume_integerMethod · 0.80
peekMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected