Consumes the string at the current position, which was has to end with the same opening character as specified by `delim`. This handles quoted characters within the string.
(&mut self, delim: CharSpan)
| 567 | /// |
| 568 | /// This handles quoted characters within the string. |
| 569 | fn consume_text(&mut self, delim: CharSpan) -> io::Result<TokenSpan> { |
| 570 | let mut s = String::new(); |
| 571 | let mut escaping = false; |
| 572 | loop { |
| 573 | match self.input.peek() { |
| 574 | Some(Ok(ch_span)) => { |
| 575 | if escaping { |
| 576 | s.push(self.input.next().unwrap()?.ch); |
| 577 | escaping = false; |
| 578 | } else if ch_span.ch == '\\' { |
| 579 | self.input.next().unwrap()?; |
| 580 | escaping = true; |
| 581 | } else if ch_span.ch == delim.ch { |
| 582 | self.input.next().unwrap()?; |
| 583 | break; |
| 584 | } else { |
| 585 | s.push(self.input.next().unwrap()?.ch); |
| 586 | } |
| 587 | } |
| 588 | Some(Err(_)) => return Err(self.input.next().unwrap().unwrap_err()), |
| 589 | None => { |
| 590 | return self.handle_bad_read( |
| 591 | format!("Incomplete string due to EOF: {}", s), |
| 592 | delim.pos, |
| 593 | ); |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | let token_len = s.len() + 2; |
| 598 | Ok(TokenSpan::new(Token::Text(s), delim.pos, token_len)) |
| 599 | } |
| 600 | |
| 601 | /// Consumes the label definition at the current position. |
| 602 | fn consume_label(&mut self, first: CharSpan) -> io::Result<TokenSpan> { |