Improved error recovery for unclosed strings (including f- and t-strings) (#20848)

This commit is contained in:
Micha Reiser 2025-10-15 09:50:56 +02:00 committed by GitHub
parent a93618ed23
commit 4fc7dd300c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
151 changed files with 1370 additions and 566 deletions

View file

@ -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 {