mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Tokenizer: Emit only a single bogus token (#7425)
**Summary** Instead of emitting a bogus token per char, we now only emit on single last bogus token. This leads to much more concise output. **Test Plan** Updated fixtures
This commit is contained in:
parent
97510c888b
commit
6dade5b9ab
12 changed files with 19 additions and 1739 deletions
|
@ -504,10 +504,12 @@ impl<'a> SimpleTokenizer<'a> {
|
|||
// Emit a single final bogus token
|
||||
let token = SimpleToken {
|
||||
kind: SimpleTokenKind::Bogus,
|
||||
range: TextRange::at(self.offset, first.text_len()),
|
||||
range: TextRange::new(self.offset, self.source.text_len()),
|
||||
};
|
||||
|
||||
self.offset += first.text_len();
|
||||
// Set the cursor to EOF
|
||||
self.cursor = Cursor::new("");
|
||||
self.offset = self.source.text_len();
|
||||
return token;
|
||||
}
|
||||
|
||||
|
@ -786,10 +788,12 @@ impl<'a> BackwardsTokenizer<'a> {
|
|||
if self.bogus {
|
||||
let token = SimpleToken {
|
||||
kind: SimpleTokenKind::Bogus,
|
||||
range: TextRange::at(self.back_offset - last.text_len(), last.text_len()),
|
||||
range: TextRange::up_to(self.back_offset),
|
||||
};
|
||||
|
||||
self.back_offset -= last.text_len();
|
||||
// Set the cursor to EOF
|
||||
self.cursor = Cursor::new("");
|
||||
self.back_offset = TextSize::new(0);
|
||||
return token;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue