diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs index 8c1756fbc23e1..7dd89e38c0869 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/avoidable_escaped_quote.rs @@ -188,7 +188,7 @@ pub(crate) fn avoidable_escaped_quote( let mut diagnostic = Diagnostic::new(AvoidableEscapedQuote, tok_range); let fixed_contents = format!( "{prefix}{quote}{value}{quote}", - prefix = kind.prefix_str(), + prefix = kind.prefix(), quote = quotes_settings.inline_quotes.opposite().as_char(), value = unescape_string( string_contents, @@ -322,7 +322,7 @@ pub(crate) fn unnecessary_escaped_quote( let mut diagnostic = Diagnostic::new(UnnecessaryEscapedQuote, tok_range); let fixed_contents = format!( "{prefix}{quote}{value}{quote}", - prefix = kind.prefix_str(), + prefix = kind.prefix(), quote = leading.as_char(), value = unescape_string(string_contents, leading.opposite().as_char()) ); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs index 2f56b6a50d984..761b2c9cdc0a4 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs @@ -221,9 +221,9 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) { value: capital_env_var.into_boxed_str(), flags: StringLiteralFlags::default().with_prefix({ if env_var.is_unicode() { - StringLiteralPrefix::UString + StringLiteralPrefix::Unicode } else { - StringLiteralPrefix::None + StringLiteralPrefix::Empty } }), ..ast::StringLiteral::default() diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs index 1db3d6cfe4b62..a7949350939a0 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs @@ -40,7 +40,7 @@ impl AlwaysFixableViolation for UnicodeKindPrefix { /// UP025 pub(crate) fn unicode_kind_prefix(checker: &mut Checker, string: &StringLiteral) { - if string.flags.is_u_string() { + if string.flags.prefix().is_unicode() { let mut diagnostic = Diagnostic::new(UnicodeKindPrefix, string.range); diagnostic.set_fix(Fix::safe_edit(Edit::range_deletion(TextRange::at( string.start(), diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 4644164bb5a52..f951f287f115e 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -1187,10 +1187,53 @@ bitflags! { /// The f-string is triple-quoted: /// it begins and ends with three consecutive quote characters. + /// For example: `f"""{bar}"""`. const TRIPLE_QUOTED = 1 << 1; - /// The f-string has an `r` or `R` prefix, meaning it is a raw f-string. - const R_PREFIX = 1 << 3; + /// The f-string has an `r` prefix, meaning it is a raw f-string + /// with a lowercase 'r'. For example: `rf"{bar}"` + const R_PREFIX_LOWER = 1 << 2; + + /// The f-string has an `R` prefix, meaning it is a raw f-string + /// with an uppercase 'r'. For example: `Rf"{bar}"`. + /// See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#r-strings-and-r-strings + /// for why we track the casing of the `r` prefix, + /// but not for any other prefix + const R_PREFIX_UPPER = 1 << 3; + } +} + +/// Enumeration of the valid prefixes an f-string literal can have. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum FStringPrefix { + /// Just a regular f-string with no other prefixes, e.g. f"{bar}" + Regular, + + /// A "raw" format-string, that has an `r` or `R` prefix, + /// e.g. `rf"{bar}"` or `Rf"{bar}"` + Raw { uppercase_r: bool }, +} + +impl FStringPrefix { + /// Return a `str` representation of the prefix + pub const fn as_str(self) -> &'static str { + match self { + Self::Regular => "f", + Self::Raw { uppercase_r: true } => "Rf", + Self::Raw { uppercase_r: false } => "rf", + } + } + + /// Return true if this prefix indicates a "raw f-string", + /// e.g. `rf"{bar}"` or `Rf"{bar}"` + pub const fn is_raw(self) -> bool { + matches!(self, Self::Raw { .. }) + } +} + +impl fmt::Display for FStringPrefix { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.as_str()) } } @@ -1213,23 +1256,43 @@ impl FStringFlags { } #[must_use] - pub fn with_r_prefix(mut self) -> Self { - self.0 |= FStringFlagsInner::R_PREFIX; - self + pub fn with_prefix(self, prefix: FStringPrefix) -> Self { + let FStringFlags(flags) = self; + match prefix { + FStringPrefix::Regular => { + Self(flags - FStringFlagsInner::R_PREFIX_LOWER - FStringFlagsInner::R_PREFIX_UPPER) + } + FStringPrefix::Raw { uppercase_r: true } => Self( + (flags | FStringFlagsInner::R_PREFIX_UPPER) - FStringFlagsInner::R_PREFIX_LOWER, + ), + FStringPrefix::Raw { uppercase_r: false } => Self( + (flags | FStringFlagsInner::R_PREFIX_LOWER) - FStringFlagsInner::R_PREFIX_UPPER, + ), + } } - /// Does the f-string have an `r` or `R` prefix? - pub const fn is_raw(self) -> bool { - self.0.contains(FStringFlagsInner::R_PREFIX) + pub const fn prefix(self) -> FStringPrefix { + if self.0.contains(FStringFlagsInner::R_PREFIX_LOWER) { + debug_assert!(!self.0.contains(FStringFlagsInner::R_PREFIX_UPPER)); + FStringPrefix::Raw { uppercase_r: false } + } else if self.0.contains(FStringFlagsInner::R_PREFIX_UPPER) { + FStringPrefix::Raw { uppercase_r: true } + } else { + FStringPrefix::Regular + } } - /// Is the f-string triple-quoted, i.e., - /// does it begin and end with three consecutive quote characters? + /// Return `true` if the f-string is triple-quoted, i.e., + /// it begins and ends with three consecutive quote characters. + /// For example: `f"""{bar}"""` pub const fn is_triple_quoted(self) -> bool { self.0.contains(FStringFlagsInner::TRIPLE_QUOTED) } - /// Does the f-string use single or double quotes in its opener and closer? + /// Return the quoting style (single or double quotes) + /// used by the f-string's opener and closer: + /// - `f"{"a"}"` -> `QuoteStyle::Double` + /// - `f'{"a"}'` -> `QuoteStyle::Single` pub const fn quote_style(self) -> Quote { if self.0.contains(FStringFlagsInner::DOUBLE) { Quote::Double @@ -1243,7 +1306,7 @@ impl fmt::Debug for FStringFlags { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("FStringFlags") .field("quote_style", &self.quote_style()) - .field("raw", &self.is_raw()) + .field("prefix", &self.prefix()) .field("triple_quoted", &self.is_triple_quoted()) .finish() } @@ -1367,7 +1430,7 @@ impl StringLiteralValue { pub fn is_unicode(&self) -> bool { self.iter() .next() - .map_or(false, |part| part.flags.is_u_string()) + .map_or(false, |part| part.flags.prefix().is_unicode()) } /// Returns a slice of all the [`StringLiteral`] parts contained in this value. @@ -1483,24 +1546,32 @@ impl Default for StringLiteralValueInner { bitflags! { #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)] struct StringLiteralFlagsInner: u8 { - /// The string uses double quotes (`"`). - /// If this flag is not set, the string uses single quotes (`'`). + /// The string uses double quotes (e.g. `"foo"`). + /// If this flag is not set, the string uses single quotes (`'foo'`). const DOUBLE = 1 << 0; - /// The string is triple-quoted: + /// The string is triple-quoted (`"""foo"""`): /// it begins and ends with three consecutive quote characters. const TRIPLE_QUOTED = 1 << 1; - /// The string has a `u` or `U` prefix. + /// The string has a `u` or `U` prefix, e.g. `u"foo"`. /// While this prefix is a no-op at runtime, /// strings with this prefix can have no other prefixes set; /// it is therefore invalid for this flag to be set /// if `R_PREFIX` is also set. const U_PREFIX = 1 << 2; - /// The string has an `r` or `R` prefix, meaning it is a raw string. + /// The string has an `r` prefix, meaning it is a raw string + /// with a lowercase 'r' (e.g. `r"foo\."`). /// It is invalid to set this flag if `U_PREFIX` is also set. - const R_PREFIX = 1 << 3; + const R_PREFIX_LOWER = 1 << 3; + + /// The string has an `R` prefix, meaning it is a raw string + /// with an uppercase 'R' (e.g. `R'foo\d'`). + /// See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#r-strings-and-r-strings + /// for why we track the casing of the `r` prefix, + /// but not for any other prefix + const R_PREFIX_UPPER = 1 << 4; } } @@ -1523,27 +1594,54 @@ impl StringLiteralFlags { } #[must_use] - pub fn with_prefix(mut self, prefix: StringLiteralPrefix) -> Self { + pub fn with_prefix(self, prefix: StringLiteralPrefix) -> Self { + let StringLiteralFlags(flags) = self; match prefix { - StringLiteralPrefix::None => {} - StringLiteralPrefix::RString => self.0 |= StringLiteralFlagsInner::R_PREFIX, - StringLiteralPrefix::UString => self.0 |= StringLiteralFlagsInner::U_PREFIX, - }; - self + StringLiteralPrefix::Empty => Self( + flags + - StringLiteralFlagsInner::R_PREFIX_LOWER + - StringLiteralFlagsInner::R_PREFIX_UPPER + - StringLiteralFlagsInner::U_PREFIX, + ), + StringLiteralPrefix::Raw { uppercase: false } => Self( + (flags | StringLiteralFlagsInner::R_PREFIX_LOWER) + - StringLiteralFlagsInner::R_PREFIX_UPPER + - StringLiteralFlagsInner::U_PREFIX, + ), + StringLiteralPrefix::Raw { uppercase: true } => Self( + (flags | StringLiteralFlagsInner::R_PREFIX_UPPER) + - StringLiteralFlagsInner::R_PREFIX_LOWER + - StringLiteralFlagsInner::U_PREFIX, + ), + StringLiteralPrefix::Unicode => Self( + (flags | StringLiteralFlagsInner::U_PREFIX) + - StringLiteralFlagsInner::R_PREFIX_LOWER + - StringLiteralFlagsInner::R_PREFIX_UPPER, + ), + } } - pub const fn prefix(self) -> &'static str { + pub const fn prefix(self) -> StringLiteralPrefix { if self.0.contains(StringLiteralFlagsInner::U_PREFIX) { - debug_assert!(!self.0.contains(StringLiteralFlagsInner::R_PREFIX)); - "u" - } else if self.0.contains(StringLiteralFlagsInner::R_PREFIX) { - "r" + debug_assert!(!self.0.intersects( + StringLiteralFlagsInner::R_PREFIX_LOWER + .union(StringLiteralFlagsInner::R_PREFIX_UPPER) + )); + StringLiteralPrefix::Unicode + } else if self.0.contains(StringLiteralFlagsInner::R_PREFIX_LOWER) { + debug_assert!(!self.0.contains(StringLiteralFlagsInner::R_PREFIX_UPPER)); + StringLiteralPrefix::Raw { uppercase: false } + } else if self.0.contains(StringLiteralFlagsInner::R_PREFIX_UPPER) { + StringLiteralPrefix::Raw { uppercase: true } } else { - "" + StringLiteralPrefix::Empty } } - /// Does the string use single or double quotes in its opener and closer? + /// Return the quoting style (single or double quotes) + /// used by the string's opener and closer: + /// - `"a"` -> `QuoteStyle::Double` + /// - `'a'` -> `QuoteStyle::Single` pub const fn quote_style(self) -> Quote { if self.0.contains(StringLiteralFlagsInner::DOUBLE) { Quote::Double @@ -1552,21 +1650,12 @@ impl StringLiteralFlags { } } - /// Is the string triple-quoted, i.e., - /// does it begin and end with three consecutive quote characters? + /// Return `true` if the string is triple-quoted, i.e., + /// it begins and ends with three consecutive quote characters. + /// For example: `"""bar"""` pub const fn is_triple_quoted(self) -> bool { self.0.contains(StringLiteralFlagsInner::TRIPLE_QUOTED) } - - /// Does the string have a `u` or `U` prefix? - pub const fn is_u_string(&self) -> bool { - self.0.contains(StringLiteralFlagsInner::U_PREFIX) - } - - /// Does the string have an `r` or `R` prefix? - pub const fn is_r_string(&self) -> bool { - self.0.contains(StringLiteralFlagsInner::R_PREFIX) - } } impl fmt::Debug for StringLiteralFlags { @@ -1583,19 +1672,41 @@ impl fmt::Debug for StringLiteralFlags { /// /// Bytestrings and f-strings are excluded from this enumeration, /// as they are represented by different AST nodes. -#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, is_macro::Is)] pub enum StringLiteralPrefix { /// Just a regular string with no prefixes - #[default] - None, + Empty, - /// A string with a `u` or `U` prefix. - /// This is a no-op at runtime, - /// but is mutually exclusive with a string having an `r` prefix. - UString, + /// A string with a `u` or `U` prefix, e.g. `u"foo"`. + /// Note that, despite this variant's name, + /// it is in fact a no-op at runtime to use the `u` or `U` prefix + /// in Python. All Python-3 strings are unicode strings; + /// this prefix is only allowed in Python 3 for backwards compatibility + /// with Python 2. However, using this prefix in a Python string + /// is mutually exclusive with an `r` or `R` prefix. + Unicode, - /// A "raw" string, that has an `r` or `R` prefix - RString, + /// A "raw" string, that has an `r` or `R` prefix, + /// e.g. `r"foo\."` or `R'bar\d'`. + Raw { uppercase: bool }, +} + +impl StringLiteralPrefix { + /// Return a `str` representation of the prefix + pub const fn as_str(self) -> &'static str { + match self { + Self::Empty => "", + Self::Unicode => "u", + Self::Raw { uppercase: true } => "R", + Self::Raw { uppercase: false } => "r", + } + } +} + +impl fmt::Display for StringLiteralPrefix { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.as_str()) + } } /// An AST node that represents a single string literal which is part of an @@ -1824,16 +1935,57 @@ impl Default for BytesLiteralValueInner { bitflags! { #[derive(Default, Copy, Clone, PartialEq, Eq, Hash)] struct BytesLiteralFlagsInner: u8 { - /// The bytestring uses double quotes (`"`). - /// If this flag is not set, the bytestring uses single quotes (`'`). + /// The bytestring uses double quotes (e.g. `b"foo"`). + /// If this flag is not set, the bytestring uses single quotes (e.g. `b'foo'`). const DOUBLE = 1 << 0; - /// The bytestring is triple-quoted: + /// The bytestring is triple-quoted (e.g. `b"""foo"""`): /// it begins and ends with three consecutive quote characters. const TRIPLE_QUOTED = 1 << 1; - /// The bytestring has an `r` or `R` prefix, meaning it is a raw bytestring. - const R_PREFIX = 1 << 3; + /// The bytestring has an `r` prefix (e.g. `rb"foo"`), + /// meaning it is a raw bytestring with a lowercase 'r'. + const R_PREFIX_LOWER = 1 << 2; + + /// The bytestring has an `R` prefix (e.g. `Rb"foo"`), + /// meaning it is a raw bytestring with an uppercase 'R'. + /// See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#r-strings-and-r-strings + /// for why we track the casing of the `r` prefix, but not for any other prefix + const R_PREFIX_UPPER = 1 << 3; + } +} + +/// Enumeration of the valid prefixes a bytestring literal can have. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum ByteStringPrefix { + /// Just a regular bytestring with no other prefixes, e.g. `b"foo"` + Regular, + + /// A "raw" bytestring, that has an `r` or `R` prefix, + /// e.g. `Rb"foo"` or `rb"foo"` + Raw { uppercase_r: bool }, +} + +impl ByteStringPrefix { + /// Return a `str` representation of the prefix + pub const fn as_str(self) -> &'static str { + match self { + Self::Regular => "b", + Self::Raw { uppercase_r: true } => "Rb", + Self::Raw { uppercase_r: false } => "rb", + } + } + + /// Return true if this prefix indicates a "raw bytestring", + /// e.g. `rb"foo"` or `Rb"foo"` + pub const fn is_raw(self) -> bool { + matches!(self, Self::Raw { .. }) + } +} + +impl fmt::Display for ByteStringPrefix { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.as_str()) } } @@ -1856,23 +2008,47 @@ impl BytesLiteralFlags { } #[must_use] - pub fn with_r_prefix(mut self) -> Self { - self.0 |= BytesLiteralFlagsInner::R_PREFIX; - self + pub fn with_prefix(self, prefix: ByteStringPrefix) -> Self { + let BytesLiteralFlags(flags) = self; + match prefix { + ByteStringPrefix::Regular => Self( + flags + - BytesLiteralFlagsInner::R_PREFIX_LOWER + - BytesLiteralFlagsInner::R_PREFIX_UPPER, + ), + ByteStringPrefix::Raw { uppercase_r: true } => Self( + (flags | BytesLiteralFlagsInner::R_PREFIX_UPPER) + - BytesLiteralFlagsInner::R_PREFIX_LOWER, + ), + ByteStringPrefix::Raw { uppercase_r: false } => Self( + (flags | BytesLiteralFlagsInner::R_PREFIX_LOWER) + - BytesLiteralFlagsInner::R_PREFIX_UPPER, + ), + } } - /// Does the bytestring have an `r` or `R` prefix? - pub const fn is_raw(self) -> bool { - self.0.contains(BytesLiteralFlagsInner::R_PREFIX) + pub const fn prefix(self) -> ByteStringPrefix { + if self.0.contains(BytesLiteralFlagsInner::R_PREFIX_LOWER) { + debug_assert!(!self.0.contains(BytesLiteralFlagsInner::R_PREFIX_UPPER)); + ByteStringPrefix::Raw { uppercase_r: false } + } else if self.0.contains(BytesLiteralFlagsInner::R_PREFIX_UPPER) { + ByteStringPrefix::Raw { uppercase_r: true } + } else { + ByteStringPrefix::Regular + } } - /// Is the bytestring triple-quoted, i.e., - /// does it begin and end with three consecutive quote characters? + /// Return `true` if the bytestring is triple-quoted, i.e., + /// it begins and ends with three consecutive quote characters. + /// For example: `b"""{bar}"""` pub const fn is_triple_quoted(self) -> bool { self.0.contains(BytesLiteralFlagsInner::TRIPLE_QUOTED) } - /// Does the bytestring use single or double quotes in its opener and closer? + /// Return the quoting style (single or double quotes) + /// used by the bytestring's opener and closer: + /// - `b"a"` -> `QuoteStyle::Double` + /// - `b'a'` -> `QuoteStyle::Single` pub const fn quote_style(self) -> Quote { if self.0.contains(BytesLiteralFlagsInner::DOUBLE) { Quote::Double @@ -1886,7 +2062,7 @@ impl fmt::Debug for BytesLiteralFlags { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("BytesLiteralFlags") .field("quote_style", &self.quote_style()) - .field("raw", &self.is_raw()) + .field("prefix", &self.prefix()) .field("triple_quoted", &self.is_triple_quoted()) .finish() } diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index 01f7449a3aa87..1577c8ec3e794 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -1268,10 +1268,11 @@ impl<'a> Generator<'a> { } fn unparse_string_literal(&mut self, string_literal: &ast::StringLiteral) { - if string_literal.flags.is_u_string() { + let ast::StringLiteral { value, flags, .. } = string_literal; + if flags.prefix().is_unicode() { self.p("u"); } - self.p_str_repr(&string_literal.value); + self.p_str_repr(value); } fn unparse_string_literal_value(&mut self, value: &ast::StringLiteralValue) { diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index e803c0263b108..394fdd9e92626 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -34,7 +34,7 @@ use std::{char, cmp::Ordering, str::FromStr}; use unicode_ident::{is_xid_continue, is_xid_start}; use unicode_normalization::UnicodeNormalization; -use ruff_python_ast::{Int, IpyEscapeKind}; +use ruff_python_ast::{FStringPrefix, Int, IpyEscapeKind}; use ruff_text_size::{TextLen, TextRange, TextSize}; use crate::lexer::cursor::{Cursor, EOF_CHAR}; @@ -175,24 +175,29 @@ impl<'source> Lexer<'source> { match (first, self.cursor.first()) { ('f' | 'F', quote @ ('\'' | '"')) => { self.cursor.bump(); - return Ok(self.lex_fstring_start(quote, false)); + return Ok(self.lex_fstring_start(quote, FStringPrefix::Regular)); } - ('r' | 'R', 'f' | 'F') | ('f' | 'F', 'r' | 'R') if is_quote(self.cursor.second()) => { + ('r', 'f' | 'F') | ('f' | 'F', 'r') if is_quote(self.cursor.second()) => { self.cursor.bump(); let quote = self.cursor.bump().unwrap(); - return Ok(self.lex_fstring_start(quote, true)); + return Ok(self.lex_fstring_start(quote, FStringPrefix::Raw { uppercase_r: false })); + } + ('R', 'f' | 'F') | ('f' | 'F', 'R') if is_quote(self.cursor.second()) => { + self.cursor.bump(); + let quote = self.cursor.bump().unwrap(); + return Ok(self.lex_fstring_start(quote, FStringPrefix::Raw { uppercase_r: true })); } (_, quote @ ('\'' | '"')) => { if let Ok(prefix) = StringPrefix::try_from(first) { self.cursor.bump(); - return self.lex_string(Some(prefix), quote); + return self.lex_string(prefix, quote); } } (_, second @ ('r' | 'R' | 'b' | 'B')) if is_quote(self.cursor.second()) => { self.cursor.bump(); if let Ok(prefix) = StringPrefix::try_from([first, second]) { let quote = self.cursor.bump().unwrap(); - return self.lex_string(Some(prefix), quote); + return self.lex_string(prefix, quote); } } _ => {} @@ -551,15 +556,11 @@ impl<'source> Lexer<'source> { } /// Lex a f-string start token. - fn lex_fstring_start(&mut self, quote: char, is_raw_string: bool) -> Tok { + fn lex_fstring_start(&mut self, quote: char, prefix: FStringPrefix) -> Tok { #[cfg(debug_assertions)] debug_assert_eq!(self.cursor.previous(), quote); - let mut kind = StringKind::from_prefix(Some(if is_raw_string { - StringPrefix::RawFormat - } else { - StringPrefix::Format - })); + let mut kind = StringKind::from_prefix(StringPrefix::Format(prefix)); if quote == '"' { kind = kind.with_double_quotes(); @@ -707,11 +708,7 @@ impl<'source> Lexer<'source> { } /// Lex a string literal. - fn lex_string( - &mut self, - prefix: Option, - quote: char, - ) -> Result { + fn lex_string(&mut self, prefix: StringPrefix, quote: char) -> Result { #[cfg(debug_assertions)] debug_assert_eq!(self.cursor.previous(), quote); @@ -1085,7 +1082,7 @@ impl<'source> Lexer<'source> { c if is_ascii_identifier_start(c) => self.lex_identifier(c)?, '0'..='9' => self.lex_number(c)?, '#' => return Ok((self.lex_comment(), self.token_range())), - '\'' | '"' => self.lex_string(None, c)?, + '\'' | '"' => self.lex_string(StringPrefix::default(), c)?, '=' => { if self.cursor.eat_char('=') { Tok::EqEqual diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_attribute_weird.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_attribute_weird.snap index e4975f27ea270..9e23886b10669 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_attribute_weird.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__invalid__tests__ok_attribute_weird.snap @@ -21,7 +21,7 @@ Ok( value: "foo", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__empty_fstrings.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__empty_fstrings.snap index bd913b784a280..8b7abba7e5ec4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__empty_fstrings.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__empty_fstrings.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -21,7 +23,9 @@ expression: lex_source(source) String { value: "", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Double, }, @@ -31,7 +35,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -45,7 +51,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -60,7 +68,9 @@ expression: lex_source(source) String { value: "", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -70,7 +80,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, @@ -84,7 +96,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__escape_unicode_name.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__escape_unicode_name.snap index fb7c25cd948f7..8e8181ef80a7a 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__escape_unicode_name.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__escape_unicode_name.snap @@ -7,7 +7,9 @@ expression: lex_source(source) String { value: "\\N{EN SPACE}", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring.snap index 3c2f1745d06d1..1769b90c55f26 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "normal ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -42,7 +46,9 @@ expression: lex_source(source) FStringMiddle { value: " {another} ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -67,7 +73,9 @@ expression: lex_source(source) FStringMiddle { value: " {", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -92,7 +100,9 @@ expression: lex_source(source) FStringMiddle { value: "}", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_comments.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_comments.snap index 91c55d709b8de..6272e36cd830e 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_comments.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_comments.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "\n# not a comment ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, @@ -56,7 +60,9 @@ expression: lex_source(source) FStringMiddle { value: " # not a comment\n", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_conversion.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_conversion.snap index e5cc4829864ed..ae1978f024ed5 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_conversion.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_conversion.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -41,7 +43,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -80,7 +84,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -105,7 +111,9 @@ expression: lex_source(source) FStringMiddle { value: ".3f!r", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -120,7 +128,9 @@ expression: lex_source(source) FStringMiddle { value: " {x!r}", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape.snap index 8103344dbc0b6..767ba14063ceb 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "\\", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -42,7 +46,9 @@ expression: lex_source(source) FStringMiddle { value: "\\\"\\", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -71,7 +77,9 @@ expression: lex_source(source) FStringMiddle { value: " \\\"\\\"\\\n end", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_braces.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_braces.snap index 831b6f0f66db3..00f19d10d7fbe 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_braces.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_braces.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "\\", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -45,7 +49,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -56,7 +62,9 @@ expression: lex_source(source) FStringMiddle { value: "\\\\", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -84,7 +92,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -95,7 +105,9 @@ expression: lex_source(source) FStringMiddle { value: "\\{foo}", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -109,7 +121,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -120,7 +134,9 @@ expression: lex_source(source) FStringMiddle { value: "\\\\{foo}", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_raw.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_raw.snap index 9719bcab531ef..1509bb438f102 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_raw.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_escape_raw.snap @@ -6,7 +6,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +21,11 @@ expression: lex_source(source) FStringMiddle { value: "\\", kind: StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -42,7 +50,11 @@ expression: lex_source(source) FStringMiddle { value: "\\\"\\", kind: StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -71,7 +83,11 @@ expression: lex_source(source) FStringMiddle { value: " \\\"\\\"\\\n end", kind: StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_expression_multiline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_expression_multiline.snap index c2547d4bcf9c6..10197b0dcf5b7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_expression_multiline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_expression_multiline.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "first ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -68,7 +72,9 @@ expression: lex_source(source) FStringMiddle { value: " second", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_multiline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_multiline.snap index a0cf64ad35a4c..ec8588dafbab4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_multiline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_multiline.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "\nhello\n world\n", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, @@ -31,7 +35,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -42,7 +48,9 @@ expression: lex_source(source) FStringMiddle { value: "\n world\nhello\n", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -56,7 +64,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -67,7 +77,9 @@ expression: lex_source(source) FStringMiddle { value: "some ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -81,7 +93,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, @@ -92,7 +106,9 @@ expression: lex_source(source) FStringMiddle { value: "multiline\nallowed ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Double, }, @@ -125,7 +141,9 @@ expression: lex_source(source) FStringMiddle { value: " string", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode.snap index 3eee751588c13..ce956328040f7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "\\N{BULLET} normal \\Nope \\N", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode_raw.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode_raw.snap index 41f34656524a9..e0d7821cce768 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode_raw.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_named_unicode_raw.snap @@ -6,7 +6,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +21,11 @@ expression: lex_source(source) FStringMiddle { value: "\\N", kind: StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -42,7 +50,11 @@ expression: lex_source(source) FStringMiddle { value: " normal", kind: StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_nested.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_nested.snap index 88e7e917279b6..2754c15c01303 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_nested.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_nested.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "foo ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -31,7 +35,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -42,7 +48,9 @@ expression: lex_source(source) FStringMiddle { value: "bar ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -66,7 +74,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -107,7 +117,9 @@ expression: lex_source(source) FStringMiddle { value: " baz", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -121,7 +133,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -132,7 +146,9 @@ expression: lex_source(source) FStringMiddle { value: "foo ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -146,7 +162,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -157,7 +175,9 @@ expression: lex_source(source) FStringMiddle { value: "bar", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -176,7 +196,9 @@ expression: lex_source(source) FStringMiddle { value: " some ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -190,7 +212,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -201,7 +225,9 @@ expression: lex_source(source) FStringMiddle { value: "another", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_parentheses.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_parentheses.snap index 2a7152c4817c4..685a7a446bf1f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_parentheses.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_parentheses.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -28,7 +30,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -39,7 +43,9 @@ expression: lex_source(source) FStringMiddle { value: "{}", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -53,7 +59,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -64,7 +72,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -86,7 +96,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -97,7 +109,9 @@ expression: lex_source(source) FStringMiddle { value: "{", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -116,7 +130,9 @@ expression: lex_source(source) FStringMiddle { value: "}", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -130,7 +146,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -141,7 +159,9 @@ expression: lex_source(source) FStringMiddle { value: "{{}}", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -155,7 +175,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -166,7 +188,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -185,7 +209,9 @@ expression: lex_source(source) FStringMiddle { value: " {} {", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -204,7 +230,9 @@ expression: lex_source(source) FStringMiddle { value: "} {{}} ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_prefix.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_prefix.snap index efe6ec7a809a5..491f601bbc37e 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_prefix.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_prefix.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -20,7 +22,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -34,7 +38,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -48,7 +56,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -62,7 +74,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: true, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -76,7 +92,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: true, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -90,7 +110,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -104,7 +128,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: false, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -118,7 +146,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: true, + }, + ), triple_quoted: false, quote_style: Double, }, @@ -132,7 +164,11 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "rf", + prefix: Format( + Raw { + uppercase_r: true, + }, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_mac_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_mac_eol.snap index 2f738516c42dd..8153e585247ea 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_mac_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_mac_eol.snap @@ -6,7 +6,9 @@ expression: fstring_single_quote_escape_eol(MAC_EOL) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -17,7 +19,9 @@ expression: fstring_single_quote_escape_eol(MAC_EOL) FStringMiddle { value: "text \\\r more text", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_unix_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_unix_eol.snap index cae87bc58b346..24914e45042f8 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_unix_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_unix_eol.snap @@ -6,7 +6,9 @@ expression: fstring_single_quote_escape_eol(UNIX_EOL) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -17,7 +19,9 @@ expression: fstring_single_quote_escape_eol(UNIX_EOL) FStringMiddle { value: "text \\\n more text", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_windows_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_windows_eol.snap index 398bd95a83695..6a3fd963a25ab 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_windows_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_single_quote_escape_windows_eol.snap @@ -6,7 +6,9 @@ expression: fstring_single_quote_escape_eol(WINDOWS_EOL) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -17,7 +19,9 @@ expression: fstring_single_quote_escape_eol(WINDOWS_EOL) FStringMiddle { value: "text \\\r\n more text", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_format_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_format_spec.snap index 54b8661cf3892..601361fd712ee 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_format_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_format_spec.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -35,7 +37,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -74,7 +78,9 @@ expression: lex_source(source) FStringMiddle { value: ".3f", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -89,7 +95,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -114,7 +122,9 @@ expression: lex_source(source) FStringMiddle { value: ".", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -139,7 +149,9 @@ expression: lex_source(source) FStringMiddle { value: "f", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -154,7 +166,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -169,7 +183,9 @@ expression: lex_source(source) String { value: "", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -184,7 +200,9 @@ expression: lex_source(source) FStringMiddle { value: "*^", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -231,7 +249,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_ipy_escape_command.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_ipy_escape_command.snap index 7febad410fe4d..e3f69d7750784 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_ipy_escape_command.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_ipy_escape_command.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "foo ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -46,7 +50,9 @@ expression: lex_source(source) FStringMiddle { value: " bar", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_lambda_expression.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_lambda_expression.snap index 7f87c19b8a388..8bb9158ef9f37 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_lambda_expression.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_lambda_expression.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -60,7 +62,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_multiline_format_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_multiline_format_spec.snap index 89218543c73d9..717750f3bc9e5 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_multiline_format_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_multiline_format_spec.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -46,7 +50,9 @@ expression: lex_source(source) FStringMiddle { value: "d\n", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -61,7 +67,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -79,7 +87,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -90,7 +100,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -119,7 +131,9 @@ expression: lex_source(source) FStringMiddle { value: "a\n b\n c\n", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -134,7 +148,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: true, quote_style: Single, }, @@ -152,7 +168,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -163,7 +181,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -192,7 +212,9 @@ expression: lex_source(source) FStringMiddle { value: "d", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -211,7 +233,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -229,7 +253,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -240,7 +266,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -269,7 +297,9 @@ expression: lex_source(source) FStringMiddle { value: "a", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -298,7 +328,9 @@ expression: lex_source(source) FStringMiddle { value: "__", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_named_expression.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_named_expression.snap index 481658f8e56e6..a717a3c496a3c 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_named_expression.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_named_expression.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -31,7 +33,9 @@ expression: lex_source(source) FStringMiddle { value: "=10", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -46,7 +50,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -89,7 +95,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, @@ -142,7 +150,9 @@ expression: lex_source(source) FStringMiddle { value: " ", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_nul_char.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_nul_char.snap index 6dbff7ba0fe12..e33d5901e8356 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_nul_char.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__fstring_with_nul_char.snap @@ -6,7 +6,9 @@ expression: lex_source(source) ( FStringStart( StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, @@ -17,7 +19,9 @@ expression: lex_source(source) FStringMiddle { value: "\\0", kind: StringKind { - prefix: "f", + prefix: Format( + Regular, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__non_logical_newline_in_string_continuation.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__non_logical_newline_in_string_continuation.snap index 06cc99fc6898d..f42745342c529 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__non_logical_newline_in_string_continuation.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__non_logical_newline_in_string_continuation.snap @@ -15,7 +15,9 @@ expression: lex_source(source) String { value: "a", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -30,7 +32,9 @@ expression: lex_source(source) String { value: "b", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -49,7 +53,9 @@ expression: lex_source(source) String { value: "c", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -60,7 +66,9 @@ expression: lex_source(source) String { value: "d", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string.snap index 240c378ff62a3..f8888fc51266d 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string.snap @@ -7,7 +7,9 @@ expression: lex_source(source) String { value: "double", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Double, }, @@ -18,7 +20,9 @@ expression: lex_source(source) String { value: "single", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -29,7 +33,9 @@ expression: lex_source(source) String { value: "can\\'t", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -40,7 +46,9 @@ expression: lex_source(source) String { value: "\\\\\\\"", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Double, }, @@ -51,7 +59,9 @@ expression: lex_source(source) String { value: "\\t\\r\\n", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -62,7 +72,9 @@ expression: lex_source(source) String { value: "\\g", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -73,7 +85,11 @@ expression: lex_source(source) String { value: "raw\\'", kind: StringKind { - prefix: "r", + prefix: Regular( + Raw { + uppercase: false, + }, + ), triple_quoted: false, quote_style: Single, }, @@ -84,7 +100,9 @@ expression: lex_source(source) String { value: "\\420", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, @@ -95,7 +113,9 @@ expression: lex_source(source) String { value: "\\200\\0a", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Single, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_mac_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_mac_eol.snap index ee44900edc5b2..45d1599078716 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_mac_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_mac_eol.snap @@ -7,7 +7,9 @@ expression: string_continuation_with_eol(MAC_EOL) String { value: "abc\\\rdef", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_unix_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_unix_eol.snap index 15700a49caeb3..528e9b5feaa55 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_unix_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_unix_eol.snap @@ -7,7 +7,9 @@ expression: string_continuation_with_eol(UNIX_EOL) String { value: "abc\\\ndef", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_windows_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_windows_eol.snap index b2bf88eafa3a9..6d44e0edbe2d3 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_windows_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__string_continuation_with_windows_eol.snap @@ -7,7 +7,9 @@ expression: string_continuation_with_eol(WINDOWS_EOL) String { value: "abc\\\r\ndef", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: false, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_mac_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_mac_eol.snap index 370d76143072f..454b34700c73b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_mac_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_mac_eol.snap @@ -7,7 +7,9 @@ expression: triple_quoted_eol(MAC_EOL) String { value: "\r test string\r ", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: true, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_unix_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_unix_eol.snap index c719e6dab4dec..d8f18846ada25 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_unix_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_unix_eol.snap @@ -7,7 +7,9 @@ expression: triple_quoted_eol(UNIX_EOL) String { value: "\n test string\n ", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: true, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_windows_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_windows_eol.snap index c5647db40bf14..44f17acbf75b2 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_windows_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__triple_quoted_windows_eol.snap @@ -7,7 +7,9 @@ expression: triple_quoted_eol(WINDOWS_EOL) String { value: "\r\n test string\r\n ", kind: StringKind { - prefix: "", + prefix: Regular( + Empty, + ), triple_quoted: true, quote_style: Double, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__dict_unpacking.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__dict_unpacking.snap index a7634cd78dd5a..c78b2f8fe93bd 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__dict_unpacking.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__dict_unpacking.snap @@ -17,7 +17,7 @@ Dict( value: "a", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -38,7 +38,7 @@ Dict( value: "d", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -59,7 +59,7 @@ Dict( value: "b", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -84,7 +84,7 @@ Dict( value: "e", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap index 7ce209f6441d8..92f4961fad6d7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings.snap @@ -28,7 +28,7 @@ expression: parse_ast value: " f", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -44,7 +44,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -85,7 +85,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -136,7 +136,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -201,7 +201,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -254,7 +254,7 @@ expression: parse_ast value: "}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -281,7 +281,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -334,7 +334,7 @@ expression: parse_ast value: "{", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -361,7 +361,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -407,7 +407,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -465,7 +465,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -511,7 +511,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -575,7 +575,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -646,7 +646,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -675,7 +675,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -706,7 +706,7 @@ expression: parse_ast value: "foo ", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -758,7 +758,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -769,7 +769,7 @@ expression: parse_ast value: "baz", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -821,7 +821,7 @@ expression: parse_ast value: "one", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -857,7 +857,7 @@ expression: parse_ast value: "implicitly ", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -866,7 +866,7 @@ expression: parse_ast value: "concatenated", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -960,7 +960,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -992,7 +992,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -1045,7 +1045,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: true, }, }, @@ -1091,7 +1091,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings_with_unicode.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings_with_unicode.snap index eb393e1022da3..4e90969031abe 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings_with_unicode.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__fstrings_with_unicode.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "foo", flags: StringLiteralFlags { quote_style: Double, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -45,7 +45,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -56,7 +56,7 @@ expression: parse_ast value: "baz", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -67,7 +67,7 @@ expression: parse_ast value: " some", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -94,7 +94,7 @@ expression: parse_ast value: "foo", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -121,7 +121,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -132,7 +132,7 @@ expression: parse_ast value: "baz", flags: StringLiteralFlags { quote_style: Double, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -143,7 +143,7 @@ expression: parse_ast value: " some", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -170,7 +170,7 @@ expression: parse_ast value: "foo", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -197,7 +197,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -208,7 +208,7 @@ expression: parse_ast value: "baz", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -219,7 +219,7 @@ expression: parse_ast value: " some", flags: StringLiteralFlags { quote_style: Double, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -246,7 +246,7 @@ expression: parse_ast value: "foo", flags: StringLiteralFlags { quote_style: Double, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -285,7 +285,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -296,7 +296,7 @@ expression: parse_ast value: "bar", flags: StringLiteralFlags { quote_style: Double, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -307,7 +307,7 @@ expression: parse_ast value: "no", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap index eaf91a2f4393d..10031be8bd9c3 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__generator_expression_argument.snap @@ -18,7 +18,7 @@ Call( value: " ", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -83,7 +83,7 @@ Call( value: "LIMIT %d", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -131,7 +131,7 @@ Call( value: "OFFSET %d", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap index fdc241ecf302a..f3a23fad398ca 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__match.snap @@ -21,7 +21,7 @@ expression: parse_ast value: "test", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -114,7 +114,7 @@ expression: parse_ast value: "label", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -135,7 +135,7 @@ expression: parse_ast value: "test", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -163,7 +163,7 @@ expression: parse_ast value: "label", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap index 243986c06e4ac..2bf1f84ada4be 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_class.snap @@ -123,7 +123,7 @@ expression: parse_suite(source).unwrap() value: "default", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_f_string.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_f_string.snap index 28b8019ec58bd..4ece08bdaeec4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_f_string.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_f_string.snap @@ -24,7 +24,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_kwargs.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_kwargs.snap index eca1e8e42af6d..47b635c56c1b9 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_kwargs.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_kwargs.snap @@ -29,7 +29,7 @@ expression: parse_ast value: "positional", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_2.snap index 75eee3eabee36..aa2b2e62b4b6d 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_2.snap @@ -29,7 +29,7 @@ expression: parse_ast value: "Hello world", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_hello.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_hello.snap index bd7da28da69c8..0c1a836f1f3f1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_hello.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_print_hello.snap @@ -29,7 +29,7 @@ expression: parse_ast value: "Hello world", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_string.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_string.snap index 378b921e7da49..ddf2de815eca7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_string.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_string.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "Hello world", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap index 334031e15809c..fa99a71304d64 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__parse_type_declaration.snap @@ -88,7 +88,7 @@ expression: parse_suite(source).unwrap() value: "ForwardRefY", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap index 437afbe82f136..04c6984481eaf 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__patma.snap @@ -508,7 +508,7 @@ expression: parse_ast value: "seq", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -547,7 +547,7 @@ expression: parse_ast value: "map", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -848,7 +848,7 @@ expression: parse_ast value: "X", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -1588,7 +1588,7 @@ expression: parse_ast value: "foo", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -2518,7 +2518,7 @@ expression: parse_ast value: "", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -2572,7 +2572,7 @@ expression: parse_ast value: "", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -3200,7 +3200,7 @@ expression: parse_ast value: "X", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try.snap index 4e59c5417b746..b01b083778b3b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try.snap @@ -129,7 +129,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -234,7 +234,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try_star.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try_star.snap index 81fb630c48d09..c40a3d53dd3e7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try_star.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__try_star.snap @@ -34,7 +34,7 @@ expression: parse_ast value: "eg", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -282,7 +282,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -418,7 +418,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap index 7817e74b102fa..8468f2c175fdf 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap @@ -25,7 +25,7 @@ expression: parse_ast value: "\u{8}another cool trick", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap index 7d0a7988daeee..0de05e40c1739 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\u{8}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap index 7d3385dbf60e1..1908b77a61e40 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\u{7}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap index 5643a57101ab2..2768101d4e242 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\r", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap index 1c9db07f057b3..5541c02008cf6 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\u{89}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap index a2a337628bd47..ae82c459bf271 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\u{7f}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap index bf4770ec9aec7..afa779ea6dbc7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap @@ -25,7 +25,7 @@ expression: parse_ast value: "\u{3}8[1m", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap index 15e9e712c710c..57a9e8453df3c 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap @@ -273,7 +273,7 @@ expression: parse_ast ], flags: BytesLiteralFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap index e55bb662ef26b..5d12fcf17a4a2 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\u{1b}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap index cbcd679322737..0938c2e966b0e 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap @@ -27,7 +27,7 @@ expression: parse_ast ], flags: BytesLiteralFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap index 22e91fcd9b055..b1d9bc5d1dfc0 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap @@ -22,7 +22,7 @@ expression: parse_ast ], flags: BytesLiteralFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap index e09b82760c212..169580478a201 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\u{c}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap index f6bb8e033dc1f..c4c27935f6aa9 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap @@ -66,7 +66,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap index 53d54e1135fae..430790e6db494 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap @@ -39,7 +39,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap index 0315e679cfb95..60f99a5cdf406 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap @@ -39,7 +39,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap index 9c03ea5377d21..fc2a429ff0989 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap @@ -39,7 +39,9 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: true, + prefix: Raw { + uppercase_r: false, + }, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap index 21851a76fe597..e464a815eaeed 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap @@ -38,7 +38,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap index 289bafdc4a066..01a3d6f58a5fc 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap @@ -70,7 +70,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap index 3ddfc6813eb4f..47713a069b541 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap @@ -50,7 +50,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap index fcfe220f98edb..a98031a67ce51 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap @@ -39,7 +39,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: true, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap index 01ec26bd1b8c9..53588d5dc85cf 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "\u{88}", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap index 83fa0ccebc571..5b96c7e0fad37 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap @@ -17,7 +17,7 @@ expression: "parse_suite(r#\"f\"\"\"#).unwrap()" elements: [], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap index a817b6ed7fe30..e5a9defe32cec 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -36,7 +36,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap index a817b6ed7fe30..e5a9defe32cec 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -36,7 +36,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap index fbde21d33c5ce..80271443bf2a7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -46,7 +46,7 @@ expression: parse_ast value: "!", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -62,7 +62,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap index 482a37ceb8da8..db9e2af4d59a1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -46,7 +46,7 @@ expression: parse_ast value: "!", flags: StringLiteralFlags { quote_style: Double, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -62,7 +62,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -73,7 +73,7 @@ expression: parse_ast value: "again!", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap index 0c6eaeb7585c5..92ff6491c8273 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap @@ -54,7 +54,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap index 10fb6da59af9c..e543128f90b63 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap @@ -52,7 +52,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap index 964140273b86d..6a524b9a69c62 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap @@ -46,7 +46,7 @@ expression: parse_ast value: "", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -55,7 +55,7 @@ expression: parse_ast value: "", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -79,7 +79,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap index ef4d892e3ec55..90f01e11808a7 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap @@ -54,7 +54,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap index 40e8713f78c95..cffbb7ddc0efc 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap @@ -44,7 +44,7 @@ expression: parse_ast value: "", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -65,7 +65,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap index 9a28852a046c1..217f80fa04e35 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap @@ -52,7 +52,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap index 8f03db0947697..77879b89dac8f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap @@ -45,7 +45,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap index 0ae5d9f93328a..11c92c78045c0 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap @@ -38,7 +38,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap index 4302bb8ed9d02..6ea7dcb6ed331 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap @@ -38,7 +38,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap index 449d9cf41b172..6f08477802bf6 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap @@ -32,7 +32,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap index 3eaac03bedbc1..916b964cc8497 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -27,7 +27,7 @@ expression: parse_ast value: "world", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap index e135378e94e43..03698da5d6afc 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "Hello, world!", flags: StringLiteralFlags { quote_style: Single, - prefix: "u", + prefix: Unicode, triple_quoted: true, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap index 8755adae0aad2..cdea22b209b4c 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -36,7 +36,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap index 6da0704b6703b..d4f17c4620678 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -36,7 +36,7 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, @@ -47,7 +47,7 @@ expression: parse_ast value: "!", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap index 1efa03806bda0..2630c0747f0af 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, @@ -27,7 +27,7 @@ expression: parse_ast value: "world", flags: StringLiteralFlags { quote_style: Single, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap index fe1957c619d26..6aebfcab16a3d 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap @@ -18,7 +18,7 @@ expression: parse_ast value: "Hello ", flags: StringLiteralFlags { quote_style: Single, - prefix: "u", + prefix: Unicode, triple_quoted: false, }, }, @@ -27,7 +27,7 @@ expression: parse_ast value: "world", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap index 391f3050563b1..a69618db665db 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap @@ -21,7 +21,9 @@ expression: parse_ast ], flags: BytesLiteralFlags { quote_style: Single, - raw: true, + prefix: Raw { + uppercase_r: true, + }, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap index 514a08a7ac922..09e09ac8bb6a4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap @@ -19,7 +19,9 @@ expression: parse_ast ], flags: BytesLiteralFlags { quote_style: Single, - raw: true, + prefix: Raw { + uppercase_r: true, + }, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap index 89963be68b8ee..5349caaa761cf 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap @@ -33,7 +33,9 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: true, + prefix: Raw { + uppercase_r: false, + }, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap index d7209da8a0dcd..38f8bd2264f1c 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap @@ -273,7 +273,7 @@ expression: parse_ast ], flags: BytesLiteralFlags { quote_style: Single, - raw: false, + prefix: Regular, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap index 54a14f27d43b3..15a9ecaf44d12 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "text more text", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap index 54a14f27d43b3..15a9ecaf44d12 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "text more text", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap index 3d546a70b83c4..81cb221ae59d4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap @@ -16,7 +16,7 @@ expression: parse_ast value: "text more text", flags: StringLiteralFlags { quote_style: Single, - prefix: "", + prefix: Empty, triple_quoted: false, }, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap index dd6fd6fceff01..00ad084ed6c2a 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap @@ -33,7 +33,9 @@ expression: parse_ast ], flags: FStringFlags { quote_style: Double, - raw: true, + prefix: Raw { + uppercase_r: false, + }, triple_quoted: true, }, }, diff --git a/crates/ruff_python_parser/src/string_token_flags.rs b/crates/ruff_python_parser/src/string_token_flags.rs index e0454e898b397..faf2f675d40ae 100644 --- a/crates/ruff_python_parser/src/string_token_flags.rs +++ b/crates/ruff_python_parser/src/string_token_flags.rs @@ -2,7 +2,7 @@ use std::fmt; use bitflags::bitflags; -use ruff_python_ast::{str::Quote, StringLiteralPrefix}; +use ruff_python_ast::{str::Quote, ByteStringPrefix, FStringPrefix, StringLiteralPrefix}; use ruff_text_size::{TextLen, TextSize}; bitflags! { @@ -41,11 +41,18 @@ bitflags! { /// but can have no other prefixes. const F_PREFIX = 1 << 4; - /// The string has an `r` or `R` prefix, meaning it is a raw string. + /// The string has an `r` prefix, meaning it is a raw string. /// F-strings and byte-strings can be raw, /// as can strings with no other prefixes. /// U-strings cannot be raw. - const R_PREFIX = 1 << 5; + const R_PREFIX_LOWER = 1 << 5; + + /// The string has an `R` prefix, meaning it is a raw string. + /// The casing of the `r`/`R` has no semantic significance at runtime; + /// see https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#r-strings-and-r-strings + /// for why we track the casing of the `r` prefix, + /// but not for any other prefix + const R_PREFIX_UPPER = 1 << 6; } } @@ -61,41 +68,15 @@ bitflags! { /// [String and Bytes literals]: https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals /// [PEP 701]: https://peps.python.org/pep-0701/ #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub(crate) enum StringPrefix { - /// The string has a `u` or `U` prefix. - /// While this prefix is a no-op at runtime, - /// strings with this prefix can have no other prefixes set. - Unicode, - - /// The string has an `r` or `R` prefix, meaning it is a raw string. - /// F-strings and byte-strings can be raw, - /// as can strings with no other prefixes. - /// U-strings cannot be raw. - Raw, - - /// The string has a `f` or `F` prefix, meaning it is an f-string. - /// F-strings can also be raw strings, - /// but can have no other prefixes. - Format, - - /// The string has a `b` or `B` prefix. - /// This means that the string is a sequence of `int`s at runtime, - /// rather than a sequence of `str`s. - /// Bytestrings can also be raw strings, - /// but can have no other prefixes. - Bytes, - - /// A string that has has any one of the prefixes - /// `{"rf", "rF", "Rf", "RF", "fr", "fR", "Fr", "FR"}` - /// Semantically, these all have the same meaning: - /// the string is both an f-string and a raw-string - RawFormat, - - /// A string that has has any one of the prefixes - /// `{"rb", "rB", "Rb", "RB", "br", "bR", "Br", "BR"}` - /// Semantically, these all have the same meaning: - /// the string is both an bytestring and a raw-string - RawBytes, +pub enum StringPrefix { + /// Prefixes that indicate the string is a bytestring + Bytes(ByteStringPrefix), + + /// Prefixes that indicate the string is an f-string + Format(FStringPrefix), + + /// All other prefixes + Regular(StringLiteralPrefix), } impl TryFrom for StringPrefix { @@ -103,10 +84,11 @@ impl TryFrom for StringPrefix { fn try_from(value: char) -> Result { let result = match value { - 'r' | 'R' => Self::Raw, - 'u' | 'U' => Self::Unicode, - 'b' | 'B' => Self::Bytes, - 'f' | 'F' => Self::Format, + 'r' => Self::Regular(StringLiteralPrefix::Raw { uppercase: false }), + 'R' => Self::Regular(StringLiteralPrefix::Raw { uppercase: true }), + 'u' | 'U' => Self::Regular(StringLiteralPrefix::Unicode), + 'b' | 'B' => Self::Bytes(ByteStringPrefix::Regular), + 'f' | 'F' => Self::Format(FStringPrefix::Regular), _ => return Err(format!("Unexpected prefix '{value}'")), }; Ok(result) @@ -117,37 +99,127 @@ impl TryFrom<[char; 2]> for StringPrefix { type Error = String; fn try_from(value: [char; 2]) -> Result { - match value { - ['r' | 'R', 'f' | 'F'] | ['f' | 'F', 'r' | 'R'] => Ok(Self::RawFormat), - ['r' | 'R', 'b' | 'B'] | ['b' | 'B', 'r' | 'R'] => Ok(Self::RawBytes), - _ => Err(format!("Unexpected prefix '{}{}'", value[0], value[1])), - } + let result = match value { + ['r', 'f' | 'F'] | ['f' | 'F', 'r'] => { + Self::Format(FStringPrefix::Raw { uppercase_r: false }) + } + ['R', 'f' | 'F'] | ['f' | 'F', 'R'] => { + Self::Format(FStringPrefix::Raw { uppercase_r: true }) + } + ['r', 'b' | 'B'] | ['b' | 'B', 'r'] => { + Self::Bytes(ByteStringPrefix::Raw { uppercase_r: false }) + } + ['R', 'b' | 'B'] | ['b' | 'B', 'R'] => { + Self::Bytes(ByteStringPrefix::Raw { uppercase_r: true }) + } + _ => return Err(format!("Unexpected prefix '{}{}'", value[0], value[1])), + }; + Ok(result) } } impl StringPrefix { const fn as_flags(self) -> StringFlags { match self { - Self::Bytes => StringFlags::B_PREFIX, - Self::Format => StringFlags::F_PREFIX, - Self::Raw => StringFlags::R_PREFIX, - Self::RawBytes => StringFlags::R_PREFIX.union(StringFlags::B_PREFIX), - Self::RawFormat => StringFlags::R_PREFIX.union(StringFlags::F_PREFIX), - Self::Unicode => StringFlags::U_PREFIX, + // regular strings + Self::Regular(StringLiteralPrefix::Empty) => StringFlags::empty(), + Self::Regular(StringLiteralPrefix::Unicode) => StringFlags::U_PREFIX, + Self::Regular(StringLiteralPrefix::Raw { uppercase: false }) => { + StringFlags::R_PREFIX_LOWER + } + Self::Regular(StringLiteralPrefix::Raw { uppercase: true }) => { + StringFlags::R_PREFIX_UPPER + } + + // bytestrings + Self::Bytes(ByteStringPrefix::Regular) => StringFlags::B_PREFIX, + Self::Bytes(ByteStringPrefix::Raw { uppercase_r: false }) => { + StringFlags::B_PREFIX.union(StringFlags::R_PREFIX_LOWER) + } + Self::Bytes(ByteStringPrefix::Raw { uppercase_r: true }) => { + StringFlags::B_PREFIX.union(StringFlags::R_PREFIX_UPPER) + } + + // f-strings + Self::Format(FStringPrefix::Regular) => StringFlags::F_PREFIX, + Self::Format(FStringPrefix::Raw { uppercase_r: false }) => { + StringFlags::F_PREFIX.union(StringFlags::R_PREFIX_LOWER) + } + Self::Format(FStringPrefix::Raw { uppercase_r: true }) => { + StringFlags::F_PREFIX.union(StringFlags::R_PREFIX_UPPER) + } + } + } + + const fn from_kind(kind: StringKind) -> Self { + let StringKind(flags) = kind; + + // f-strings + if flags.contains(StringFlags::F_PREFIX) { + if flags.contains(StringFlags::R_PREFIX_LOWER) { + return Self::Format(FStringPrefix::Raw { uppercase_r: false }); + } + if flags.contains(StringFlags::R_PREFIX_UPPER) { + return Self::Format(FStringPrefix::Raw { uppercase_r: true }); + } + return Self::Format(FStringPrefix::Regular); + } + + // bytestrings + if flags.contains(StringFlags::B_PREFIX) { + if flags.contains(StringFlags::R_PREFIX_LOWER) { + return Self::Bytes(ByteStringPrefix::Raw { uppercase_r: true }); + } + if flags.contains(StringFlags::R_PREFIX_LOWER) { + return Self::Bytes(ByteStringPrefix::Raw { uppercase_r: false }); + } + return Self::Bytes(ByteStringPrefix::Regular); + } + + // all other strings + if flags.contains(StringFlags::R_PREFIX_LOWER) { + return Self::Regular(StringLiteralPrefix::Raw { uppercase: false }); + } + if flags.contains(StringFlags::R_PREFIX_UPPER) { + return Self::Regular(StringLiteralPrefix::Raw { uppercase: true }); + } + if flags.contains(StringFlags::U_PREFIX) { + return Self::Regular(StringLiteralPrefix::Unicode); + } + Self::Regular(StringLiteralPrefix::Empty) + } + + const fn as_str(self) -> &'static str { + match self { + Self::Regular(regular_prefix) => regular_prefix.as_str(), + Self::Bytes(bytestring_prefix) => bytestring_prefix.as_str(), + Self::Format(fstring_prefix) => fstring_prefix.as_str(), } } } +impl fmt::Display for StringPrefix { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.as_str()) + } +} + +impl Default for StringPrefix { + fn default() -> Self { + Self::Regular(StringLiteralPrefix::Empty) + } +} + #[derive(Default, Clone, Copy, PartialEq, Eq, Hash)] pub struct StringKind(StringFlags); impl StringKind { - pub(crate) const fn from_prefix(prefix: Option) -> Self { - if let Some(prefix) = prefix { - Self(prefix.as_flags()) - } else { - Self(StringFlags::empty()) - } + pub(crate) const fn from_prefix(prefix: StringPrefix) -> Self { + Self(prefix.as_flags()) + } + + pub const fn prefix(self) -> StringPrefix { + StringPrefix::from_kind(self) } /// Does the string have a `u` or `U` prefix? @@ -157,7 +229,8 @@ impl StringKind { /// Does the string have an `r` or `R` prefix? pub const fn is_raw_string(self) -> bool { - self.0.contains(StringFlags::R_PREFIX) + self.0 + .intersects(StringFlags::R_PREFIX_LOWER.union(StringFlags::R_PREFIX_UPPER)) } /// Does the string have an `f` or `F` prefix? @@ -201,33 +274,9 @@ impl StringKind { } } - /// A `str` representation of the prefixes used (if any) - /// in the string's opener. - pub const fn prefix_str(self) -> &'static str { - if self.0.contains(StringFlags::F_PREFIX) { - if self.0.contains(StringFlags::R_PREFIX) { - return "rf"; - } - return "f"; - } - if self.0.contains(StringFlags::B_PREFIX) { - if self.0.contains(StringFlags::R_PREFIX) { - return "rb"; - } - return "b"; - } - if self.0.contains(StringFlags::R_PREFIX) { - return "r"; - } - if self.0.contains(StringFlags::U_PREFIX) { - return "u"; - } - "" - } - /// The length of the prefixes used (if any) in the string's opener. pub fn prefix_len(self) -> TextSize { - self.prefix_str().text_len() + self.prefix().as_str().text_len() } /// The length of the quotes used to start and close the string. @@ -258,7 +307,7 @@ impl StringKind { pub fn format_string_contents(self, contents: &str) -> String { format!( "{}{}{}{}", - self.prefix_str(), + self.prefix(), self.quote_str(), contents, self.quote_str() @@ -281,7 +330,7 @@ impl StringKind { impl fmt::Debug for StringKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("StringKind") - .field("prefix", &self.prefix_str()) + .field("prefix", &self.prefix()) .field("triple_quoted", &self.is_triple_quoted()) .field("quote_style", &self.quote_style()) .finish() @@ -290,9 +339,6 @@ impl fmt::Debug for StringKind { impl From for ruff_python_ast::StringLiteralFlags { fn from(value: StringKind) -> ruff_python_ast::StringLiteralFlags { - debug_assert!(!value.is_f_string()); - debug_assert!(!value.is_byte_string()); - let mut new = ruff_python_ast::StringLiteralFlags::default(); if value.quote_style().is_double() { new = new.with_double_quotes(); @@ -300,25 +346,18 @@ impl From for ruff_python_ast::StringLiteralFlags { if value.is_triple_quoted() { new = new.with_triple_quotes(); } - new.with_prefix({ - if value.is_u_string() { - debug_assert!(!value.is_raw_string()); - StringLiteralPrefix::UString - } else if value.is_raw_string() { - StringLiteralPrefix::RString - } else { - StringLiteralPrefix::None - } - }) + let StringPrefix::Regular(prefix) = value.prefix() else { + unreachable!( + "Should never attempt to convert {} into a regular string", + value.prefix() + ) + }; + new.with_prefix(prefix) } } impl From for ruff_python_ast::BytesLiteralFlags { fn from(value: StringKind) -> ruff_python_ast::BytesLiteralFlags { - debug_assert!(value.is_byte_string()); - debug_assert!(!value.is_f_string()); - debug_assert!(!value.is_u_string()); - let mut new = ruff_python_ast::BytesLiteralFlags::default(); if value.quote_style().is_double() { new = new.with_double_quotes(); @@ -326,19 +365,18 @@ impl From for ruff_python_ast::BytesLiteralFlags { if value.is_triple_quoted() { new = new.with_triple_quotes(); } - if value.is_raw_string() { - new = new.with_r_prefix(); - } - new + let StringPrefix::Bytes(bytestring_prefix) = value.prefix() else { + unreachable!( + "Should never attempt to convert {} into a bytestring", + value.prefix() + ) + }; + new.with_prefix(bytestring_prefix) } } impl From for ruff_python_ast::FStringFlags { fn from(value: StringKind) -> ruff_python_ast::FStringFlags { - debug_assert!(value.is_f_string()); - debug_assert!(!value.is_byte_string()); - debug_assert!(!value.is_u_string()); - let mut new = ruff_python_ast::FStringFlags::default(); if value.quote_style().is_double() { new = new.with_double_quotes(); @@ -346,9 +384,12 @@ impl From for ruff_python_ast::FStringFlags { if value.is_triple_quoted() { new = new.with_triple_quotes(); } - if value.is_raw_string() { - new = new.with_r_prefix(); - } - new + let StringPrefix::Format(fstring_prefix) = value.prefix() else { + unreachable!( + "Should never attempt to convert {} into an f-string", + value.prefix() + ) + }; + new.with_prefix(fstring_prefix) } }