Skip to content

Commit

Permalink
Use eat_char2 wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Aug 29, 2023
1 parent eb9cc75 commit b2f6141
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
24 changes: 8 additions & 16 deletions crates/ruff_python_parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion crates/ruff_python_parser/src/lexer/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b2f6141

Please sign in to comment.