mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 16:10:38 +00:00
Simplify formatting of strings by using flags from the AST nodes (#10489)
This commit is contained in:
parent
fc792d1d2e
commit
7caf0d064a
22 changed files with 725 additions and 809 deletions
|
@ -2,11 +2,10 @@
|
|||
|
||||
use bstr::ByteSlice;
|
||||
|
||||
use ruff_python_ast::{self as ast, Expr};
|
||||
use ruff_python_ast::{self as ast, AnyStringKind, Expr};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
|
||||
use crate::lexer::{LexicalError, LexicalErrorType};
|
||||
use crate::string_token_flags::StringKind;
|
||||
use crate::token::Tok;
|
||||
|
||||
pub(crate) enum StringType {
|
||||
|
@ -43,13 +42,13 @@ enum EscapedChar {
|
|||
struct StringParser {
|
||||
source: Box<str>,
|
||||
cursor: usize,
|
||||
kind: StringKind,
|
||||
kind: AnyStringKind,
|
||||
offset: TextSize,
|
||||
range: TextRange,
|
||||
}
|
||||
|
||||
impl StringParser {
|
||||
fn new(source: Box<str>, kind: StringKind, offset: TextSize, range: TextRange) -> Self {
|
||||
fn new(source: Box<str>, kind: AnyStringKind, offset: TextSize, range: TextRange) -> Self {
|
||||
Self {
|
||||
source,
|
||||
cursor: 0,
|
||||
|
@ -425,7 +424,7 @@ impl StringParser {
|
|||
|
||||
pub(crate) fn parse_string_literal(
|
||||
source: Box<str>,
|
||||
kind: StringKind,
|
||||
kind: AnyStringKind,
|
||||
range: TextRange,
|
||||
) -> Result<StringType, LexicalError> {
|
||||
StringParser::new(source, kind, range.start() + kind.opener_len(), range).parse()
|
||||
|
@ -433,7 +432,7 @@ pub(crate) fn parse_string_literal(
|
|||
|
||||
pub(crate) fn parse_fstring_literal_element(
|
||||
source: Box<str>,
|
||||
kind: StringKind,
|
||||
kind: AnyStringKind,
|
||||
range: TextRange,
|
||||
) -> Result<ast::FStringElement, LexicalError> {
|
||||
StringParser::new(source, kind, range.start(), range).parse_fstring_middle()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue