mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-17 22:07:42 +00:00
Improved error recovery for unclosed strings (including f- and t-strings) (#20848)
This commit is contained in:
parent
a93618ed23
commit
4fc7dd300c
151 changed files with 1370 additions and 566 deletions
|
@ -729,7 +729,7 @@ impl fmt::Display for TokenKind {
|
|||
|
||||
bitflags! {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct TokenFlags: u8 {
|
||||
pub(crate) struct TokenFlags: u16 {
|
||||
/// The token is a string with double quotes (`"`).
|
||||
const DOUBLE_QUOTES = 1 << 0;
|
||||
/// The token is a triple-quoted string i.e., it starts and ends with three consecutive
|
||||
|
@ -748,9 +748,12 @@ bitflags! {
|
|||
const RAW_STRING_LOWERCASE = 1 << 6;
|
||||
/// The token is a raw string and the prefix character is in uppercase.
|
||||
const RAW_STRING_UPPERCASE = 1 << 7;
|
||||
/// String without matching closing quote(s)
|
||||
const UNCLOSED_STRING = 1 << 8;
|
||||
|
||||
/// The token is a raw string i.e., prefixed with `r` or `R`
|
||||
const RAW_STRING = Self::RAW_STRING_LOWERCASE.bits() | Self::RAW_STRING_UPPERCASE.bits();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -808,6 +811,10 @@ impl StringFlags for TokenFlags {
|
|||
AnyStringPrefix::Regular(StringLiteralPrefix::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_unclosed(self) -> bool {
|
||||
self.intersects(TokenFlags::UNCLOSED_STRING)
|
||||
}
|
||||
}
|
||||
|
||||
impl TokenFlags {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue