Read a string literal token.
(&mut self, quote: u8)
| 438 | |
| 439 | /// Read a string literal token. |
| 440 | fn read_string(&mut self, quote: u8) -> Token<'a> { |
| 441 | let start = self.position; |
| 442 | self.advance(); // consume opening quote |
| 443 | |
| 444 | while let Some(b) = self.peek() { |
| 445 | if b == quote { |
| 446 | self.advance(); // consume closing quote |
| 447 | break; |
| 448 | } else if b == b'\\' { |
| 449 | self.advance(); // consume backslash |
| 450 | self.advance(); // consume escaped char |
| 451 | } else if Self::is_newline(b) { |
| 452 | // Unterminated string - stop at newline |
| 453 | break; |
| 454 | } else { |
| 455 | self.advance(); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | Token::new( |
| 460 | &self.content[start..self.position], |
| 461 | TokenKind::String, |
| 462 | start, |
| 463 | ) |
| 464 | } |
| 465 | |
| 466 | /// Read a single-line comment token. |
| 467 | fn read_comment(&mut self) -> Token<'a> { |