Consumes the label definition at the current position.
(&mut self, first: CharSpan)
| 600 | |
| 601 | /// Consumes the label definition at the current position. |
| 602 | fn consume_label(&mut self, first: CharSpan) -> io::Result<TokenSpan> { |
| 603 | let mut s = String::new(); |
| 604 | |
| 605 | match self.input.peek() { |
| 606 | Some(Ok(ch_span)) => match ch_span.ch { |
| 607 | ch if ch.is_word() && !ch.is_numeric() => s.push(self.input.next().unwrap()?.ch), |
| 608 | _ch => (), |
| 609 | }, |
| 610 | Some(Err(_)) => return Err(self.input.next().unwrap().unwrap_err()), |
| 611 | None => (), |
| 612 | } |
| 613 | if s.is_empty() { |
| 614 | return Ok(TokenSpan::new(Token::Bad("Empty label name".to_owned()), first.pos, 1)); |
| 615 | } |
| 616 | |
| 617 | loop { |
| 618 | match self.input.peek() { |
| 619 | Some(Ok(ch_span)) => match ch_span.ch { |
| 620 | ch if ch.is_word() => s.push(self.input.next().unwrap()?.ch), |
| 621 | ch if ch.is_separator() => break, |
| 622 | ch => { |
| 623 | let msg = format!("Unexpected character in label: {}", ch); |
| 624 | return self.handle_bad_read(msg, first.pos); |
| 625 | } |
| 626 | }, |
| 627 | Some(Err(_)) => return Err(self.input.next().unwrap().unwrap_err()), |
| 628 | None => break, |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | let token_len = s.len() + 1; |
| 633 | Ok(TokenSpan::new(Token::Label(s), first.pos, token_len)) |
| 634 | } |
| 635 | |
| 636 | /// Consumes the remainder of the line and returns the token that was encountered at the end |
| 637 | /// (which may be EOF or end of line). |
no test coverage detected