Consumes the integer at the current position `pos`.
(&mut self, pos: LineCol)
| 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> { |
no test coverage detected