type: ignore[codes] and knot: ignore (#15078)

This commit is contained in:
Micha Reiser 2024-12-23 10:52:43 +01:00 committed by GitHub
parent 9eb73cb7e0
commit 2f85749fa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 737 additions and 48 deletions

View file

@ -56,10 +56,8 @@ impl<'a> Cursor<'a> {
self.chars.clone().next_back().unwrap_or(EOF_CHAR)
}
// SAFETY: The `source.text_len` call in `new` would panic if the string length is larger than a `u32`.
#[allow(clippy::cast_possible_truncation)]
pub fn text_len(&self) -> TextSize {
TextSize::new(self.chars.as_str().len() as u32)
self.chars.as_str().text_len()
}
pub fn token_len(&self) -> TextSize {
@ -103,6 +101,16 @@ impl<'a> Cursor<'a> {
}
}
/// Eats the next character if `predicate` returns `true`.
pub fn eat_if(&mut self, mut predicate: impl FnMut(char) -> bool) -> bool {
if predicate(self.first()) && !self.is_eof() {
self.bump();
true
} else {
false
}
}
/// Eats symbols while predicate returns true or until the end of file is reached.
pub fn eat_while(&mut self, mut predicate: impl FnMut(char) -> bool) {
// It was tried making optimized version of this for eg. line comments, but