MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / scan_string

Method scan_string

aiscript-lexer/src/lib.rs:702–727  ·  view source on GitHub ↗

Scan a string literal, handling escape sequences

(&mut self)

Source from the content-addressed store, hash-verified

700
701 // Scan a string literal, handling escape sequences
702 fn scan_string(&mut self) -> Token<'a> {
703 let start_content = self.current; // Skip opening quote
704
705 while let Some((end_pos, ch)) = self.iter.peek().copied() {
706 match ch {
707 '\\' => {
708 self.advance(); // consume backslash
709 self.advance(); // consume the following char
710 }
711 '"' => {
712 let content = &self.source[start_content..end_pos];
713 self.advance(); // consume closing quote
714 return Token::new(TokenType::String, content, self.line);
715 }
716 '\n' => {
717 self.line += 1;
718 self.advance();
719 }
720 _ => {
721 self.advance();
722 }
723 }
724 }
725
726 Token::new(TokenType::Invalid, "Unterminated string.", self.line)
727 }
728}
729
730impl Lexer<'_> {

Callers 1

scan_tokenMethod · 0.80

Calls 2

advanceMethod · 0.80
peekMethod · 0.45

Tested by

no test coverage detected