diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index dc3f44a4be24d..d343141aacb39 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -556,9 +556,7 @@ impl<'source> Lexer<'source> { if is_raw_string { flags |= FStringContextFlags::RAW; } - if self.cursor.first() == quote && self.cursor.second() == quote { - self.cursor.bump(); - self.cursor.bump(); + if self.cursor.eat_char2(quote, quote) { flags |= FStringContextFlags::TRIPLE; }; @@ -645,8 +643,8 @@ impl<'source> Lexer<'source> { self.cursor.bump(); normalized .push_str(&self.source[TextRange::new(last_offset, self.offset())]); - self.cursor.bump(); - last_offset = self.offset(); // Skip the second `{` + self.cursor.bump(); // Skip the second `{` + last_offset = self.offset(); } else { break; } @@ -659,8 +657,8 @@ impl<'source> Lexer<'source> { self.cursor.bump(); normalized .push_str(&self.source[TextRange::new(last_offset, self.offset())]); - self.cursor.bump(); - last_offset = self.offset(); // Skip the second `}` + self.cursor.bump(); // Skip the second `}` + last_offset = self.offset(); } else { break; } @@ -695,9 +693,7 @@ impl<'source> Lexer<'source> { // If the next two characters are also the quote character, then we have a triple-quoted // string; consume those two characters and ensure that we require a triple-quote to close - let triple_quoted = if self.cursor.first() == quote && self.cursor.second() == quote { - self.cursor.bump(); - self.cursor.bump(); + let triple_quoted = if self.cursor.eat_char2(quote, quote) { true } else { false @@ -739,9 +735,7 @@ impl<'source> Lexer<'source> { } Some(c) if c == quote => { if triple_quoted { - if self.cursor.first() == quote && self.cursor.second() == quote { - self.cursor.bump(); - self.cursor.bump(); + if self.cursor.eat_char2(quote, quote) { break self.offset() - TextSize::new(3); } } else { @@ -1172,9 +1166,7 @@ impl<'source> Lexer<'source> { '.' => { if self.cursor.first().is_ascii_digit() { self.lex_decimal_number('.')? - } else if self.cursor.first() == '.' && self.cursor.second() == '.' { - self.cursor.bump(); - self.cursor.bump(); + } else if self.cursor.eat_char2('.', '.') { Tok::Ellipsis } else { Tok::Dot diff --git a/crates/ruff_python_parser/src/lexer/cursor.rs b/crates/ruff_python_parser/src/lexer/cursor.rs index f7dd2f5dab5cc..0067f16a64c3e 100644 --- a/crates/ruff_python_parser/src/lexer/cursor.rs +++ b/crates/ruff_python_parser/src/lexer/cursor.rs @@ -85,7 +85,6 @@ impl<'a> Cursor<'a> { } } - #[cfg(feature = "pep-701")] pub(super) fn eat_char2(&mut self, c1: char, c2: char) -> bool { let mut chars = self.chars.clone(); if chars.next() == Some(c1) && chars.next() == Some(c2) {