mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-31 08:54:10 +00:00
Disallow implicit concatenation of t-strings and other string types (#19485)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
As of [this cpython PR](https://github.com/python/cpython/pull/135996), it is not allowed to concatenate t-strings with non-t-strings, implicitly or explicitly. Expressions such as `"foo" t"{bar}"` are now syntax errors. This PR updates some AST nodes and parsing to reflect this change. The structural change is that `TStringPart` is no longer needed, since, as in the case of `BytesStringLiteral`, the only possibilities are that we have a single `TString` or a vector of such (representing an implicit concatenation of t-strings). This removes a level of nesting from many AST expressions (which is what all the snapshot changes reflect), and simplifies some logic in the implementation of visitors, for example. The other change of note is in the parser. When we meet an implicit concatenation of string-like literals, we now count the number of t-string literals. If these do not exhaust the total number of implicitly concatenated pieces, then we emit a syntax error. To recover from this syntax error, we encode any t-string pieces as _invalid_ string literals (which means we flag them as invalid, record their range, and record the value as `""`). Note that if at least one of the pieces is an f-string we prefer to parse the entire string as an f-string; otherwise we parse it as a string. This logic is exactly the same as how we currently treat `BytesStringLiteral` parsing and error recovery - and carries with it the same pros and cons. Finally, note that I have not implemented any changes in the implementation of the formatter. As far as I can tell, none are needed. I did change a few of the fixtures so that we are always concatenating t-strings with t-strings.
This commit is contained in:
parent
df5eba7583
commit
008bbfdf5a
75 changed files with 4509 additions and 6294 deletions
|
@ -25,5 +25,5 @@ def my_func():
|
|||
|
||||
# t-strings - all ok
|
||||
t"0.0.0.0"
|
||||
"0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
"0.0.0.0" f"0.0.0.0{expr}0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
t"0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
t"0.0.0.0" t"0.0.0.0{expr}0.0.0.0" t"0.0.0.0{expr}0.0.0.0"
|
||||
|
|
|
@ -708,23 +708,10 @@ pub struct ComparableTString<'a> {
|
|||
}
|
||||
|
||||
impl<'a> From<&'a ast::TStringValue> for ComparableTString<'a> {
|
||||
// The approach taken below necessarily deviates from the
|
||||
// corresponding implementation for [`ast::FStringValue`].
|
||||
// The reason is that a t-string value is composed of _three_
|
||||
// non-comparable parts: literals, f-string expressions, and
|
||||
// t-string interpolations. Since we have merged the AST nodes
|
||||
// that capture f-string expressions and t-string interpolations
|
||||
// into the shared [`ast::InterpolatedElement`], we must
|
||||
// be careful to distinguish between them here.
|
||||
// We model a [`ComparableTString`] on the actual
|
||||
// [CPython implementation] of a `string.templatelib.Template` object.
|
||||
//
|
||||
// Consequently, we model a [`ComparableTString`] on the actual
|
||||
// [CPython implementation] of a `string.templatelib.Template` object:
|
||||
// it is composed of `strings` and `interpolations`. In CPython,
|
||||
// the `strings` field is a tuple of honest strings (since f-strings
|
||||
// are evaluated). Our `strings` field will house both f-string
|
||||
// expressions and string literals.
|
||||
//
|
||||
// Finally, as in CPython, we must be careful to ensure that the length
|
||||
// As in CPython, we must be careful to ensure that the length
|
||||
// of `strings` is always one more than the length of `interpolations` -
|
||||
// that way we can recover the original reading order by interleaving
|
||||
// starting with `strings`. This is how we can tell the
|
||||
|
@ -768,19 +755,6 @@ impl<'a> From<&'a ast::TStringValue> for ComparableTString<'a> {
|
|||
.push(ComparableInterpolatedStringElement::Literal("".into()));
|
||||
}
|
||||
|
||||
fn push_fstring_expression(&mut self, expression: &'a ast::InterpolatedElement) {
|
||||
if let Some(ComparableInterpolatedStringElement::Literal(last_literal)) =
|
||||
self.strings.last()
|
||||
{
|
||||
// Recall that we insert empty strings after
|
||||
// each interpolation. If we encounter an f-string
|
||||
// expression, we replace the empty string with it.
|
||||
if last_literal.is_empty() {
|
||||
self.strings.pop();
|
||||
}
|
||||
}
|
||||
self.strings.push(expression.into());
|
||||
}
|
||||
fn push_tstring_interpolation(&mut self, expression: &'a ast::InterpolatedElement) {
|
||||
self.interpolations.push(expression.into());
|
||||
self.start_new_literal();
|
||||
|
@ -789,34 +763,13 @@ impl<'a> From<&'a ast::TStringValue> for ComparableTString<'a> {
|
|||
|
||||
let mut collector = Collector::default();
|
||||
|
||||
for part in value {
|
||||
match part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
collector.push_literal(&string_literal.value);
|
||||
for element in value.elements() {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Literal(literal) => {
|
||||
collector.push_literal(&literal.value);
|
||||
}
|
||||
ast::TStringPart::TString(fstring) => {
|
||||
for element in &fstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Literal(literal) => {
|
||||
collector.push_literal(&literal.value);
|
||||
}
|
||||
ast::InterpolatedStringElement::Interpolation(interpolation) => {
|
||||
collector.push_tstring_interpolation(interpolation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::TStringPart::FString(fstring) => {
|
||||
for element in &fstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Literal(literal) => {
|
||||
collector.push_literal(&literal.value);
|
||||
}
|
||||
ast::InterpolatedStringElement::Interpolation(expression) => {
|
||||
collector.push_fstring_expression(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::InterpolatedStringElement::Interpolation(interpolation) => {
|
||||
collector.push_tstring_interpolation(interpolation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,7 +320,7 @@ pub enum StringLikePartIter<'a> {
|
|||
String(std::slice::Iter<'a, ast::StringLiteral>),
|
||||
Bytes(std::slice::Iter<'a, ast::BytesLiteral>),
|
||||
FString(std::slice::Iter<'a, ast::FStringPart>),
|
||||
TString(std::slice::Iter<'a, ast::TStringPart>),
|
||||
TString(std::slice::Iter<'a, ast::TString>),
|
||||
}
|
||||
|
||||
impl<'a> Iterator for StringLikePartIter<'a> {
|
||||
|
@ -339,16 +339,7 @@ impl<'a> Iterator for StringLikePartIter<'a> {
|
|||
ast::FStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => {
|
||||
let part = inner.next()?;
|
||||
match part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
StringLikePart::String(string_literal)
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => StringLikePart::TString(t_string),
|
||||
ast::TStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => StringLikePart::TString(inner.next()?),
|
||||
};
|
||||
|
||||
Some(part)
|
||||
|
@ -378,16 +369,7 @@ impl DoubleEndedIterator for StringLikePartIter<'_> {
|
|||
ast::FStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => {
|
||||
let part = inner.next_back()?;
|
||||
match part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
StringLikePart::String(string_literal)
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => StringLikePart::TString(t_string),
|
||||
ast::TStringPart::FString(f_string) => StringLikePart::FString(f_string),
|
||||
}
|
||||
}
|
||||
StringLikePartIter::TString(inner) => StringLikePart::TString(inner.next_back()?),
|
||||
};
|
||||
|
||||
Some(part)
|
||||
|
|
|
@ -1274,6 +1274,7 @@ impl Truthiness {
|
|||
Self::Unknown
|
||||
}
|
||||
}
|
||||
Expr::TString(_) => Self::Truthy,
|
||||
Expr::List(ast::ExprList { elts, .. })
|
||||
| Expr::Set(ast::ExprSet { elts, .. })
|
||||
| Expr::Tuple(ast::ExprTuple { elts, .. }) => {
|
||||
|
@ -1362,6 +1363,7 @@ fn is_non_empty_f_string(expr: &ast::ExprFString) -> bool {
|
|||
Expr::EllipsisLiteral(_) => true,
|
||||
Expr::List(_) => true,
|
||||
Expr::Tuple(_) => true,
|
||||
Expr::TString(_) => true,
|
||||
|
||||
// These expressions must resolve to the inner expression.
|
||||
Expr::If(ast::ExprIf { body, orelse, .. }) => inner(body) && inner(orelse),
|
||||
|
@ -1386,7 +1388,6 @@ fn is_non_empty_f_string(expr: &ast::ExprFString) -> bool {
|
|||
// These literals may or may not be empty.
|
||||
Expr::FString(f_string) => is_non_empty_f_string(f_string),
|
||||
// These literals may or may not be empty.
|
||||
Expr::TString(f_string) => is_non_empty_t_string(f_string),
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => !value.is_empty(),
|
||||
Expr::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => !value.is_empty(),
|
||||
}
|
||||
|
@ -1403,76 +1404,6 @@ fn is_non_empty_f_string(expr: &ast::ExprFString) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns `true` if the expression definitely resolves to a non-empty string, when used as an
|
||||
/// f-string expression, or `false` if the expression may resolve to an empty string.
|
||||
fn is_non_empty_t_string(expr: &ast::ExprTString) -> bool {
|
||||
fn inner(expr: &Expr) -> bool {
|
||||
match expr {
|
||||
// When stringified, these expressions are always non-empty.
|
||||
Expr::Lambda(_) => true,
|
||||
Expr::Dict(_) => true,
|
||||
Expr::Set(_) => true,
|
||||
Expr::ListComp(_) => true,
|
||||
Expr::SetComp(_) => true,
|
||||
Expr::DictComp(_) => true,
|
||||
Expr::Compare(_) => true,
|
||||
Expr::NumberLiteral(_) => true,
|
||||
Expr::BooleanLiteral(_) => true,
|
||||
Expr::NoneLiteral(_) => true,
|
||||
Expr::EllipsisLiteral(_) => true,
|
||||
Expr::List(_) => true,
|
||||
Expr::Tuple(_) => true,
|
||||
|
||||
// These expressions must resolve to the inner expression.
|
||||
Expr::If(ast::ExprIf { body, orelse, .. }) => inner(body) && inner(orelse),
|
||||
Expr::Named(ast::ExprNamed { value, .. }) => inner(value),
|
||||
|
||||
// These expressions are complex. We can't determine whether they're empty or not.
|
||||
Expr::BoolOp(ast::ExprBoolOp { .. }) => false,
|
||||
Expr::BinOp(ast::ExprBinOp { .. }) => false,
|
||||
Expr::UnaryOp(ast::ExprUnaryOp { .. }) => false,
|
||||
Expr::Generator(_) => false,
|
||||
Expr::Await(_) => false,
|
||||
Expr::Yield(_) => false,
|
||||
Expr::YieldFrom(_) => false,
|
||||
Expr::Call(_) => false,
|
||||
Expr::Attribute(_) => false,
|
||||
Expr::Subscript(_) => false,
|
||||
Expr::Starred(_) => false,
|
||||
Expr::Name(_) => false,
|
||||
Expr::Slice(_) => false,
|
||||
Expr::IpyEscapeCommand(_) => false,
|
||||
|
||||
// These literals may or may not be empty.
|
||||
Expr::FString(f_string) => is_non_empty_f_string(f_string),
|
||||
// These literals may or may not be empty.
|
||||
Expr::TString(t_string) => is_non_empty_t_string(t_string),
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => !value.is_empty(),
|
||||
Expr::BytesLiteral(ast::ExprBytesLiteral { value, .. }) => !value.is_empty(),
|
||||
}
|
||||
}
|
||||
|
||||
expr.value.iter().any(|part| match part {
|
||||
ast::TStringPart::Literal(string_literal) => !string_literal.is_empty(),
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
t_string.elements.iter().all(|element| match element {
|
||||
ast::InterpolatedStringElement::Literal(string_literal) => {
|
||||
!string_literal.is_empty()
|
||||
}
|
||||
ast::InterpolatedStringElement::Interpolation(t_string) => {
|
||||
inner(&t_string.expression)
|
||||
}
|
||||
})
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
f_string.elements.iter().all(|element| match element {
|
||||
InterpolatedStringElement::Literal(string_literal) => !string_literal.is_empty(),
|
||||
InterpolatedStringElement::Interpolation(f_string) => inner(&f_string.expression),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns `true` if the expression definitely resolves to the empty string, when used as an f-string
|
||||
/// expression.
|
||||
fn is_empty_f_string(expr: &ast::ExprFString) -> bool {
|
||||
|
|
|
@ -171,18 +171,8 @@ impl ast::ExprTString {
|
|||
node_index: _,
|
||||
} = self;
|
||||
|
||||
for t_string_part in value {
|
||||
match t_string_part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
visitor.visit_string_literal(string_literal);
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
visitor.visit_f_string(f_string);
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
for t_string in value {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -597,8 +597,8 @@ impl ExprTString {
|
|||
/// otherwise.
|
||||
pub const fn as_single_part_tstring(&self) -> Option<&TString> {
|
||||
match &self.value.inner {
|
||||
TStringValueInner::Single(TStringPart::TString(tstring)) => Some(tstring),
|
||||
_ => None,
|
||||
TStringValueInner::Single(tstring) => Some(tstring),
|
||||
TStringValueInner::Concatenated(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -614,7 +614,7 @@ impl TStringValue {
|
|||
/// Creates a new t-string literal with a single [`TString`] part.
|
||||
pub fn single(value: TString) -> Self {
|
||||
Self {
|
||||
inner: TStringValueInner::Single(TStringPart::TString(value)),
|
||||
inner: TStringValueInner::Single(value),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -625,7 +625,7 @@ impl TStringValue {
|
|||
///
|
||||
/// Panics if `values` has less than 2 elements.
|
||||
/// Use [`TStringValue::single`] instead.
|
||||
pub fn concatenated(values: Vec<TStringPart>) -> Self {
|
||||
pub fn concatenated(values: Vec<TString>) -> Self {
|
||||
assert!(
|
||||
values.len() > 1,
|
||||
"Use `TStringValue::single` to create single-part t-strings"
|
||||
|
@ -640,78 +640,52 @@ impl TStringValue {
|
|||
matches!(self.inner, TStringValueInner::Concatenated(_))
|
||||
}
|
||||
|
||||
/// Returns a slice of all the [`TStringPart`]s contained in this value.
|
||||
pub fn as_slice(&self) -> &[TStringPart] {
|
||||
/// Returns a slice of all the [`TString`]s contained in this value.
|
||||
pub fn as_slice(&self) -> &[TString] {
|
||||
match &self.inner {
|
||||
TStringValueInner::Single(part) => std::slice::from_ref(part),
|
||||
TStringValueInner::Concatenated(parts) => parts,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a mutable slice of all the [`TStringPart`]s contained in this value.
|
||||
fn as_mut_slice(&mut self) -> &mut [TStringPart] {
|
||||
/// Returns a mutable slice of all the [`TString`]s contained in this value.
|
||||
fn as_mut_slice(&mut self) -> &mut [TString] {
|
||||
match &mut self.inner {
|
||||
TStringValueInner::Single(part) => std::slice::from_mut(part),
|
||||
TStringValueInner::Concatenated(parts) => parts,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the [`TStringPart`]s contained in this value.
|
||||
pub fn iter(&self) -> Iter<TStringPart> {
|
||||
/// Returns an iterator over all the [`TString`]s contained in this value.
|
||||
pub fn iter(&self) -> Iter<TString> {
|
||||
self.as_slice().iter()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the [`TStringPart`]s contained in this value
|
||||
/// Returns an iterator over all the [`TString`]s contained in this value
|
||||
/// that allows modification.
|
||||
pub fn iter_mut(&mut self) -> IterMut<TStringPart> {
|
||||
pub fn iter_mut(&mut self) -> IterMut<TString> {
|
||||
self.as_mut_slice().iter_mut()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the [`StringLiteral`] parts contained in this value.
|
||||
///
|
||||
/// Note that this doesn't recurse into the t-string parts. For example,
|
||||
///
|
||||
/// ```python
|
||||
/// "foo" t"bar {x}" "baz" t"qux"
|
||||
/// ```
|
||||
///
|
||||
/// Here, the string literal parts returned would be `"foo"` and `"baz"`.
|
||||
pub fn literals(&self) -> impl Iterator<Item = &StringLiteral> {
|
||||
self.iter().filter_map(|part| part.as_literal())
|
||||
}
|
||||
|
||||
/// Returns an iterator over the [`TString`] parts contained in this value.
|
||||
///
|
||||
/// Note that this doesn't recurse into the t-string parts. For example,
|
||||
///
|
||||
/// ```python
|
||||
/// "foo" t"bar {x}" "baz" t"qux"
|
||||
/// ```
|
||||
///
|
||||
/// Here, the t-string parts returned would be `f"bar {x}"` and `f"qux"`.
|
||||
pub fn t_strings(&self) -> impl Iterator<Item = &TString> {
|
||||
self.iter().filter_map(|part| part.as_t_string())
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the [`InterpolatedStringElement`] contained in this value.
|
||||
///
|
||||
/// An t-string element is what makes up an [`TString`] i.e., it is either a
|
||||
/// An interpolated string element is what makes up an [`TString`] i.e., it is either a
|
||||
/// string literal or an interpolation. In the following example,
|
||||
///
|
||||
/// ```python
|
||||
/// "foo" t"bar {x}" "baz" t"qux"
|
||||
/// t"foo" t"bar {x}" t"baz" t"qux"
|
||||
/// ```
|
||||
///
|
||||
/// The t-string elements returned would be string literal (`"bar "`),
|
||||
/// The interpolated string elements returned would be string literal (`"bar "`),
|
||||
/// interpolation (`x`) and string literal (`"qux"`).
|
||||
pub fn elements(&self) -> impl Iterator<Item = &InterpolatedStringElement> {
|
||||
self.t_strings().flat_map(|fstring| fstring.elements.iter())
|
||||
self.iter().flat_map(|tstring| tstring.elements.iter())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a TStringValue {
|
||||
type Item = &'a TStringPart;
|
||||
type IntoIter = Iter<'a, TStringPart>;
|
||||
type Item = &'a TString;
|
||||
type IntoIter = Iter<'a, TString>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
|
@ -719,8 +693,8 @@ impl<'a> IntoIterator for &'a TStringValue {
|
|||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a mut TStringValue {
|
||||
type Item = &'a mut TStringPart;
|
||||
type IntoIter = IterMut<'a, TStringPart>;
|
||||
type Item = &'a mut TString;
|
||||
type IntoIter = IterMut<'a, TString>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter_mut()
|
||||
}
|
||||
|
@ -731,43 +705,10 @@ impl<'a> IntoIterator for &'a mut TStringValue {
|
|||
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
|
||||
enum TStringValueInner {
|
||||
/// A single t-string i.e., `t"foo"`.
|
||||
///
|
||||
/// This is always going to be `TStringPart::TString` variant which is
|
||||
/// maintained by the `TStringValue::single` constructor.
|
||||
Single(TStringPart),
|
||||
Single(TString),
|
||||
|
||||
/// An implicitly concatenated t-string i.e., `"foo" t"bar {x}"`.
|
||||
Concatenated(Vec<TStringPart>),
|
||||
}
|
||||
|
||||
/// An t-string part which is either a string literal, an f-string,
|
||||
/// or a t-string.
|
||||
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
|
||||
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
|
||||
pub enum TStringPart {
|
||||
Literal(StringLiteral),
|
||||
FString(FString),
|
||||
TString(TString),
|
||||
}
|
||||
|
||||
impl TStringPart {
|
||||
pub fn quote_style(&self) -> Quote {
|
||||
match self {
|
||||
Self::Literal(string_literal) => string_literal.flags.quote_style(),
|
||||
Self::FString(f_string) => f_string.flags.quote_style(),
|
||||
Self::TString(t_string) => t_string.flags.quote_style(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for TStringPart {
|
||||
fn range(&self) -> TextRange {
|
||||
match self {
|
||||
TStringPart::Literal(string_literal) => string_literal.range(),
|
||||
TStringPart::FString(f_string) => f_string.range(),
|
||||
TStringPart::TString(t_string) => t_string.range(),
|
||||
}
|
||||
}
|
||||
/// An implicitly concatenated t-string i.e., `t"foo" t"bar {x}"`.
|
||||
Concatenated(Vec<TString>),
|
||||
}
|
||||
|
||||
pub trait StringFlags: Copy {
|
||||
|
@ -1237,6 +1178,12 @@ pub struct TString {
|
|||
pub flags: TStringFlags,
|
||||
}
|
||||
|
||||
impl TString {
|
||||
pub fn quote_style(&self) -> Quote {
|
||||
self.flags.quote_style()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TString> for Expr {
|
||||
fn from(payload: TString) -> Self {
|
||||
ExprTString {
|
||||
|
|
|
@ -7,8 +7,8 @@ use crate::{
|
|||
self as ast, Alias, AnyParameterRef, Arguments, BoolOp, BytesLiteral, CmpOp, Comprehension,
|
||||
Decorator, ElifElseClause, ExceptHandler, Expr, ExprContext, FString, FStringPart,
|
||||
InterpolatedStringElement, Keyword, MatchCase, Operator, Parameter, Parameters, Pattern,
|
||||
PatternArguments, PatternKeyword, Stmt, StringLiteral, TString, TStringPart, TypeParam,
|
||||
TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem,
|
||||
PatternArguments, PatternKeyword, Stmt, StringLiteral, TString, TypeParam, TypeParamParamSpec,
|
||||
TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem,
|
||||
};
|
||||
|
||||
/// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order.
|
||||
|
@ -547,14 +547,8 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
|
|||
}
|
||||
}
|
||||
Expr::TString(ast::ExprTString { value, .. }) => {
|
||||
for part in value {
|
||||
match part {
|
||||
TStringPart::Literal(string_literal) => {
|
||||
visitor.visit_string_literal(string_literal);
|
||||
}
|
||||
TStringPart::FString(f_string) => visitor.visit_f_string(f_string),
|
||||
TStringPart::TString(t_string) => visitor.visit_t_string(t_string),
|
||||
}
|
||||
for t_string in value {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
|
||||
|
|
|
@ -533,18 +533,8 @@ pub fn walk_expr<V: Transformer + ?Sized>(visitor: &V, expr: &mut Expr) {
|
|||
}
|
||||
}
|
||||
Expr::TString(ast::ExprTString { value, .. }) => {
|
||||
for t_string_part in value.iter_mut() {
|
||||
match t_string_part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
visitor.visit_string_literal(string_literal);
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
visitor.visit_f_string(f_string);
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
for t_string in value.iter_mut() {
|
||||
visitor.visit_t_string(t_string);
|
||||
}
|
||||
}
|
||||
Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => {
|
||||
|
|
|
@ -51,28 +51,12 @@ fn concatenated_fstrings_compare_equal() -> Result<(), ParseError> {
|
|||
|
||||
#[test]
|
||||
fn concatenated_tstrings_compare_equal() -> Result<(), ParseError> {
|
||||
let split_contents = r#"t"{foo!r} this" r"\n raw" t" and {bar!s} that""#;
|
||||
let split_contents = r#"t"{foo!r} this" rt"\n raw" t" and {bar!s} that""#;
|
||||
let value_contents = r#"t"{foo!r} this\\n raw and {bar!s} that""#;
|
||||
|
||||
assert_comparable(split_contents, value_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concatenated_f_and_t_strings_interwoven_compare_equal() -> Result<(), ParseError> {
|
||||
let split_contents = r#"f"{foo} this " t"{bar}" "baz""#;
|
||||
let value_contents = r#"f"{foo}" t" this {bar}" "baz""#;
|
||||
|
||||
assert_comparable(split_contents, value_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concatenated_f_and_t_strings_compare_unequal_when_swapped() -> Result<(), ParseError> {
|
||||
let f_then_t_contents = r#"f"{foo!r} this" r"\n raw" t" and {bar!s} that""#;
|
||||
let t_then_f_contents = r#"t"{foo!r} this" r"\n raw" f" and {bar!s} that""#;
|
||||
|
||||
assert_noncomparable(f_then_t_contents, t_then_f_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_strings_literal_order_matters_compare_unequal() -> Result<(), ParseError> {
|
||||
let interp_then_literal_contents = r#"t"{foo}bar""#;
|
||||
|
@ -80,11 +64,3 @@ fn t_strings_literal_order_matters_compare_unequal() -> Result<(), ParseError> {
|
|||
|
||||
assert_noncomparable(interp_then_literal_contents, literal_then_interp_contents)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn t_strings_empty_concat_equal() -> Result<(), ParseError> {
|
||||
let empty_literal = r#""" t"hey{foo}""#;
|
||||
let empty_f_string = r#"f""t"hey{foo}""#;
|
||||
|
||||
assert_comparable(empty_literal, empty_f_string)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ expression: trace
|
|||
- ModModule
|
||||
- StmtExpr
|
||||
- ExprTString
|
||||
- StringLiteral
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- InterpolatedElement
|
||||
|
|
|
@ -4,7 +4,8 @@ expression: trace
|
|||
---
|
||||
- StmtExpr
|
||||
- ExprTString
|
||||
- StringLiteral
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- TString
|
||||
- InterpolatedStringLiteralElement
|
||||
- InterpolatedElement
|
||||
|
|
|
@ -148,7 +148,7 @@ fn f_strings() {
|
|||
|
||||
#[test]
|
||||
fn t_strings() {
|
||||
let source = r"'pre' t'foo {bar:.{x}f} baz'";
|
||||
let source = r"t'pre' t'foo {bar:.{x}f} baz'";
|
||||
|
||||
let trace = trace_source_order_visitation(source);
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ fn f_strings() {
|
|||
|
||||
#[test]
|
||||
fn t_strings() {
|
||||
let source = r"'pre' t'foo {bar:.{x}f} baz'";
|
||||
let source = r"t'pre' t'foo {bar:.{x}f} baz'";
|
||||
|
||||
let trace = trace_visitation(source);
|
||||
|
||||
|
|
|
@ -1538,19 +1538,9 @@ impl<'a> Generator<'a> {
|
|||
|
||||
fn unparse_t_string_value(&mut self, value: &ast::TStringValue) {
|
||||
let mut first = true;
|
||||
for t_string_part in value {
|
||||
for t_string in value {
|
||||
self.p_delim(&mut first, " ");
|
||||
match t_string_part {
|
||||
ast::TStringPart::Literal(string_literal) => {
|
||||
self.unparse_string_literal(string_literal);
|
||||
}
|
||||
ast::TStringPart::FString(f_string) => {
|
||||
self.unparse_interpolated_string(&f_string.elements, f_string.flags.into());
|
||||
}
|
||||
ast::TStringPart::TString(t_string) => {
|
||||
self.unparse_interpolated_string(&t_string.elements, t_string.flags.into());
|
||||
}
|
||||
}
|
||||
self.unparse_interpolated_string(&t_string.elements, t_string.flags.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,16 +104,13 @@ f"{10 + len('bar')=}" f'{10 + len("bar")=}'
|
|||
# T-strings
|
||||
##############################################################################
|
||||
|
||||
# Escape `{` and `}` when merging a t-string with a string
|
||||
"a {not_a_variable}" t"b {10}" "c"
|
||||
|
||||
# Join, and break expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{
|
||||
expression
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
# Join, but don't break the expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
t"test{
|
||||
expression
|
||||
|
@ -171,22 +168,11 @@ t"test" tR"test"
|
|||
|
||||
"single" f""""single"""
|
||||
|
||||
"single" t""""single"""
|
||||
t"single" t""""single"""
|
||||
|
||||
b"single" b"""triple"""
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Don't join t-strings and f-strings
|
||||
##############################################################################
|
||||
|
||||
t"{interp}" f"{expr}"
|
||||
|
||||
f"{expr}" t"{interp}"
|
||||
|
||||
f"{expr}" "string" t"{interp}"
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Join strings in with statements
|
||||
##############################################################################
|
||||
|
|
|
@ -345,7 +345,7 @@ a[
|
|||
b
|
||||
] = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Same but starting with a joined string. They should both result in the same formatting.
|
||||
|
@ -361,7 +361,7 @@ a[
|
|||
aaaaaaa,
|
||||
b
|
||||
] = t"ccccc{
|
||||
expression}ccccccccccc" "ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
|
||||
|
||||
# Split an overlong target, but join the string if it fits
|
||||
|
@ -370,7 +370,7 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Split both if necessary and keep multiline
|
||||
|
@ -379,66 +379,66 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}cccccccccccccccccccccccccccccccc" "ccccccccccccccccccccccccccccccc" # comment
|
||||
expression}cccccccccccccccccccccccccccccccc" t"ccccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain expressions that are guaranteed to split, e.b. because of a magic trailing comma
|
||||
aaaaaaaaaaaaaaaaaa = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain commented expressions
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings with multiline debug expressions:
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a +
|
||||
b=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
b=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
|
||||
|
@ -499,7 +499,7 @@ a = (
|
|||
)
|
||||
|
||||
logger.error(
|
||||
f"Failed to run task {task} for job"
|
||||
f"Failed to run task {task} for job"
|
||||
f"with id {str(job.id)}" # type: ignore[union-attr]
|
||||
)
|
||||
|
||||
|
|
|
@ -8,21 +8,21 @@ rt"Not-so-tricky \"quote"
|
|||
|
||||
# Regression test for tstrings dropping comments
|
||||
result_f = (
|
||||
'Traceback (most recent call last):\n'
|
||||
t'Traceback (most recent call last):\n'
|
||||
t' File "{__file__}", line {lineno_f+5}, in _check_recursive_traceback_display\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
# XXX: The following line changes depending on whether the tests
|
||||
# are run through the interactive interpreter or with -m
|
||||
# It also varies depending on the platform (stack size)
|
||||
# Fortunately, we don't care about exactness here, so we use regex
|
||||
r' \[Previous line repeated (\d+) more times\]' '\n'
|
||||
'RecursionError: maximum recursion depth exceeded\n'
|
||||
rt' \[Previous line repeated (\d+) more times\]' t'\n'
|
||||
t'RecursionError: maximum recursion depth exceeded\n'
|
||||
)
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ result_f = (
|
|||
(
|
||||
t'{1}'
|
||||
# comment 1
|
||||
''
|
||||
t''
|
||||
)
|
||||
|
||||
(
|
||||
|
@ -655,7 +655,7 @@ hello {
|
|||
|
||||
# Implicit concatenated t-string containing quotes
|
||||
_ = (
|
||||
'This string should change its quotes to double quotes'
|
||||
t'This string should change its quotes to double quotes'
|
||||
t'This string uses double quotes in an expression {"it's a quote"}'
|
||||
t'This t-string does not use any quotes.'
|
||||
)
|
||||
|
|
|
@ -110,16 +110,13 @@ f"{10 + len('bar')=}" f'{10 + len("bar")=}'
|
|||
# T-strings
|
||||
##############################################################################
|
||||
|
||||
# Escape `{` and `}` when merging a t-string with a string
|
||||
"a {not_a_variable}" t"b {10}" "c"
|
||||
|
||||
# Join, and break expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{
|
||||
expression
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
# Join, but don't break the expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" "more"
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{expression}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" t"cccccccccccccccccccc {20999}" t"more"
|
||||
|
||||
t"test{
|
||||
expression
|
||||
|
@ -177,22 +174,11 @@ t"test" tR"test"
|
|||
|
||||
"single" f""""single"""
|
||||
|
||||
"single" t""""single"""
|
||||
t"single" t""""single"""
|
||||
|
||||
b"single" b"""triple"""
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Don't join t-strings and f-strings
|
||||
##############################################################################
|
||||
|
||||
t"{interp}" f"{expr}"
|
||||
|
||||
f"{expr}" t"{interp}"
|
||||
|
||||
f"{expr}" "string" t"{interp}"
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Join strings in with statements
|
||||
##############################################################################
|
||||
|
@ -521,9 +507,6 @@ f"{10 + len('bar')=}" f'{10 + len("bar")=}'
|
|||
# T-strings
|
||||
##############################################################################
|
||||
|
||||
# Escape `{` and `}` when merging a t-string with a string
|
||||
t"a {{not_a_variable}}b {10}c"
|
||||
|
||||
# Join, and break expressions
|
||||
t"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{
|
||||
expression
|
||||
|
@ -583,22 +566,11 @@ t"test" Rt"test"
|
|||
|
||||
"single" f""""single"""
|
||||
|
||||
"single" t""""single"""
|
||||
t"single" t""""single"""
|
||||
|
||||
b"single" b"""triple"""
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Don't join t-strings and f-strings
|
||||
##############################################################################
|
||||
|
||||
t"{interp}" f"{expr}"
|
||||
|
||||
f"{expr}" t"{interp}"
|
||||
|
||||
f"{expr}" "string" t"{interp}"
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Join strings in with statements
|
||||
##############################################################################
|
||||
|
@ -905,7 +877,7 @@ f"aaaaaaaaaaaaaaaa \
|
|||
```diff
|
||||
--- Stable
|
||||
+++ Preview
|
||||
@@ -302,9 +302,12 @@
|
||||
@@ -288,9 +288,12 @@
|
||||
##############################################################################
|
||||
# Use can_omit_optional_parentheses layout to avoid an instability where the formatter
|
||||
# picks the can_omit_optional_parentheses layout when the strings are joined.
|
||||
|
|
|
@ -351,7 +351,7 @@ a[
|
|||
b
|
||||
] = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Same but starting with a joined string. They should both result in the same formatting.
|
||||
|
@ -367,7 +367,7 @@ a[
|
|||
aaaaaaa,
|
||||
b
|
||||
] = t"ccccc{
|
||||
expression}ccccccccccc" "ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"ccccccccccccccccccccccccccccccccccccccccccc" # comment
|
||||
|
||||
|
||||
# Split an overlong target, but join the string if it fits
|
||||
|
@ -376,7 +376,7 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}ccccccccccc" "cccccccccccccccccccccccccccccc" # comment
|
||||
expression}ccccccccccc" t"cccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Split both if necessary and keep multiline
|
||||
|
@ -385,66 +385,66 @@ a[
|
|||
b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{
|
||||
expression}cccccccccccccccccccccccccccccccc" "ccccccccccccccccccccccccccccccc" # comment
|
||||
expression}cccccccccccccccccccccccccccccccc" t"ccccccccccccccccccccccccccccccc" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain expressions that are guaranteed to split, e.b. because of a magic trailing comma
|
||||
aaaaaaaaaaaaaaaaaa = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (t"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
[a,]
|
||||
}" "moreeeeeeeeeeeeeeeeeeee" "test" # comment
|
||||
}" t"moreeeeeeeeeeeeeeeeeeee" t"test" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain commented expressions
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{[
|
||||
a # comment
|
||||
]}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
]}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings with multiline debug expressions:
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a +
|
||||
b=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
b=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
a=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}" "moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
=}" t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
|
||||
|
@ -505,7 +505,7 @@ a = (
|
|||
)
|
||||
|
||||
logger.error(
|
||||
f"Failed to run task {task} for job"
|
||||
f"Failed to run task {task} for job"
|
||||
f"with id {str(job.id)}" # type: ignore[union-attr]
|
||||
)
|
||||
|
||||
|
@ -909,7 +909,7 @@ a[aaaaaaa, b] = t"ccccc{expression}ccccccccccccccccccccccccccccccccccc" # comme
|
|||
# The string gets parenthesized because it, with the inlined comment, exceeds the line length limit.
|
||||
a[aaaaaaa, b] = (
|
||||
t"ccccc{expression}ccccccccccc"
|
||||
"ccccccccccccccccccccccccccccccccccccccccccc"
|
||||
t"ccccccccccccccccccccccccccccccccccccccccccc"
|
||||
) # comment
|
||||
|
||||
|
||||
|
@ -925,7 +925,7 @@ a[
|
|||
aaaaaaa, b
|
||||
].bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = (
|
||||
t"ccccc{expression}cccccccccccccccccccccccccccccccc"
|
||||
"ccccccccccccccccccccccccccccccc"
|
||||
t"ccccccccccccccccccccccccccccccc"
|
||||
) # comment
|
||||
|
||||
# Don't inline t-strings that contain expressions that are guaranteed to split, e.b. because of a magic trailing comma
|
||||
|
@ -935,8 +935,8 @@ aaaaaaaaaaaaaaaaaa = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test"
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test"
|
||||
) # comment
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
|
@ -945,8 +945,8 @@ aaaaaaaaaaaaaaaaaa = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
|
@ -955,8 +955,8 @@ aaaaa[aaaaaaaaaaa] = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test"
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test"
|
||||
) # comment
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
|
@ -965,8 +965,8 @@ aaaaa[aaaaaaaaaaa] = (
|
|||
a,
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeeee"
|
||||
"test" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeeee"
|
||||
t"test" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings that contain commented expressions
|
||||
|
@ -976,7 +976,7 @@ aaaaaaaaaaaaaaaaaa = (
|
|||
a # comment
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
|
@ -985,38 +985,38 @@ aaaaa[aaaaaaaaaaa] = (
|
|||
a # comment
|
||||
]
|
||||
}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
# Don't inline t-strings with multiline debug expressions:
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a +
|
||||
b=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaaaaaaa = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{
|
||||
a=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
aaaaa[aaaaaaaaaaa] = (
|
||||
t"testeeeeeeeeeeeeeeeeeeeeeeeee{a
|
||||
=}"
|
||||
"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
t"moreeeeeeeeeeeeeeeeeetest" # comment
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -14,21 +14,21 @@ rt"Not-so-tricky \"quote"
|
|||
|
||||
# Regression test for tstrings dropping comments
|
||||
result_f = (
|
||||
'Traceback (most recent call last):\n'
|
||||
t'Traceback (most recent call last):\n'
|
||||
t' File "{__file__}", line {lineno_f+5}, in _check_recursive_traceback_display\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
t' File "{__file__}", line {lineno_f+1}, in f\n'
|
||||
' f()\n'
|
||||
t' f()\n'
|
||||
# XXX: The following line changes depending on whether the tests
|
||||
# are run through the interactive interpreter or with -m
|
||||
# It also varies depending on the platform (stack size)
|
||||
# Fortunately, we don't care about exactness here, so we use regex
|
||||
r' \[Previous line repeated (\d+) more times\]' '\n'
|
||||
'RecursionError: maximum recursion depth exceeded\n'
|
||||
rt' \[Previous line repeated (\d+) more times\]' t'\n'
|
||||
t'RecursionError: maximum recursion depth exceeded\n'
|
||||
)
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ result_f = (
|
|||
(
|
||||
t'{1}'
|
||||
# comment 1
|
||||
''
|
||||
t''
|
||||
)
|
||||
|
||||
(
|
||||
|
@ -661,7 +661,7 @@ hello {
|
|||
|
||||
# Implicit concatenated t-string containing quotes
|
||||
_ = (
|
||||
'This string should change its quotes to double quotes'
|
||||
t'This string should change its quotes to double quotes'
|
||||
t'This string uses double quotes in an expression {"it's a quote"}'
|
||||
t'This t-string does not use any quotes.'
|
||||
)
|
||||
|
@ -761,22 +761,22 @@ rt"Not-so-tricky \"quote"
|
|||
|
||||
# Regression test for tstrings dropping comments
|
||||
result_f = (
|
||||
"Traceback (most recent call last):\n"
|
||||
t"Traceback (most recent call last):\n"
|
||||
t' File "{__file__}", line {lineno_f + 5}, in _check_recursive_traceback_display\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
t' File "{__file__}", line {lineno_f + 1}, in f\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
t' File "{__file__}", line {lineno_f + 1}, in f\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
t' File "{__file__}", line {lineno_f + 1}, in f\n'
|
||||
" f()\n"
|
||||
t" f()\n"
|
||||
# XXX: The following line changes depending on whether the tests
|
||||
# are run through the interactive interpreter or with -m
|
||||
# It also varies depending on the platform (stack size)
|
||||
# Fortunately, we don't care about exactness here, so we use regex
|
||||
r" \[Previous line repeated (\d+) more times\]"
|
||||
"\n"
|
||||
"RecursionError: maximum recursion depth exceeded\n"
|
||||
rt" \[Previous line repeated (\d+) more times\]"
|
||||
t"\n"
|
||||
t"RecursionError: maximum recursion depth exceeded\n"
|
||||
)
|
||||
|
||||
|
||||
|
@ -785,7 +785,7 @@ result_f = (
|
|||
(
|
||||
t"{1}"
|
||||
# comment 1
|
||||
""
|
||||
t""
|
||||
)
|
||||
|
||||
(
|
||||
|
@ -1463,7 +1463,7 @@ hello {
|
|||
|
||||
# Implicit concatenated t-string containing quotes
|
||||
_ = (
|
||||
"This string should change its quotes to double quotes"
|
||||
t"This string should change its quotes to double quotes"
|
||||
t"This string uses double quotes in an expression {"it's a quote"}"
|
||||
t"This t-string does not use any quotes."
|
||||
)
|
||||
|
|
|
@ -3,4 +3,3 @@ t"{hey}"
|
|||
t'{there}'
|
||||
t"""what's
|
||||
happening?"""
|
||||
"implicitly"t"concatenated"
|
||||
|
|
|
@ -3,4 +3,3 @@ t"{hey}"
|
|||
t'{there}'
|
||||
t"""what's
|
||||
happening?"""
|
||||
"implicitly"t"concatenated"
|
||||
|
|
|
@ -17,7 +17,7 @@ t"{ foo = !s }"
|
|||
t"{ 1, 2 = }"
|
||||
t'{t"{3.1415=:.1f}":*^20}'
|
||||
|
||||
{"foo " t"bar {x + y} " "baz": 10}
|
||||
{t"foo " t"bar {x + y} " t"baz": 10}
|
||||
match foo:
|
||||
case "one":
|
||||
pass
|
||||
|
@ -44,31 +44,18 @@ t"{x=!a}"
|
|||
t"{x:.3f!r =}"
|
||||
t"{x = !r :.3f}"
|
||||
t"{x:.3f=!r}"
|
||||
"hello" t"{x}"
|
||||
t"hello" t"{x}"
|
||||
t"{x}" t"{y}"
|
||||
t"{x}" "world"
|
||||
t"{x}" t"world"
|
||||
t"Invalid args in command: {command, *args}"
|
||||
"foo" t"{x}" "bar"
|
||||
t"foo" t"{x}" t"bar"
|
||||
(
|
||||
t"a"
|
||||
t"b"
|
||||
"c"
|
||||
t"c"
|
||||
rt"d"
|
||||
fr"e"
|
||||
tr"e"
|
||||
)
|
||||
|
||||
# With unicode strings
|
||||
u"foo" t"{bar}" "baz" " some"
|
||||
"foo" t"{bar}" u"baz" " some"
|
||||
"foo" t"{bar}" "baz" u" some"
|
||||
u"foo" t"bar {baz} really" u"bar" "no"
|
||||
|
||||
|
||||
# With f-strings
|
||||
f"{this}" t"{that}"
|
||||
t"{this}"f"{that}"
|
||||
t"{this}" "that" f"{other}"
|
||||
f"one {this} two" "that" t"three {other} four"
|
||||
|
||||
# Nesting
|
||||
t"{f"{t"{this}"}"}"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::cmp::Ordering;
|
||||
use std::ops::Deref;
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
@ -1256,7 +1255,6 @@ impl<'src> Parser<'src> {
|
|||
// t'{there}'
|
||||
// t"""what's
|
||||
// happening?"""
|
||||
// "implicitly"t"concatenated"
|
||||
|
||||
// test_err template_strings_py313
|
||||
// # parse_options: {"target-version": "3.13"}
|
||||
|
@ -1264,7 +1262,6 @@ impl<'src> Parser<'src> {
|
|||
// t'{there}'
|
||||
// t"""what's
|
||||
// happening?"""
|
||||
// "implicitly"t"concatenated"
|
||||
let string_type = StringType::TString(
|
||||
self.parse_interpolated_string(InterpolatedStringKind::TString)
|
||||
.into(),
|
||||
|
@ -1281,7 +1278,7 @@ impl<'src> Parser<'src> {
|
|||
|
||||
match strings.len() {
|
||||
// This is not possible as the function was called by matching against a
|
||||
// `String` or `FStringStart` token.
|
||||
// `String`, `FStringStart`, or `TStringStart` token.
|
||||
0 => unreachable!("Expected to parse at least one string"),
|
||||
// We need a owned value, hence the `pop` here.
|
||||
1 => match strings.pop().unwrap() {
|
||||
|
@ -1322,58 +1319,84 @@ impl<'src> Parser<'src> {
|
|||
) -> Expr {
|
||||
assert!(strings.len() > 1);
|
||||
|
||||
let mut has_tstring = false;
|
||||
let mut has_fstring = false;
|
||||
let mut byte_literal_count = 0;
|
||||
let mut tstring_count = 0;
|
||||
for string in &strings {
|
||||
match string {
|
||||
StringType::FString(_) => has_fstring = true,
|
||||
StringType::TString(_) => has_tstring = true,
|
||||
StringType::TString(_) => tstring_count += 1,
|
||||
StringType::Bytes(_) => byte_literal_count += 1,
|
||||
StringType::Str(_) => {}
|
||||
}
|
||||
}
|
||||
let has_bytes = byte_literal_count > 0;
|
||||
let has_tstring = tstring_count > 0;
|
||||
|
||||
if has_bytes {
|
||||
match byte_literal_count.cmp(&strings.len()) {
|
||||
Ordering::Less => {
|
||||
// TODO(dhruvmanila): This is not an ideal recovery because the parser
|
||||
// replaces the byte literals with an invalid string literal node. Any
|
||||
// downstream tools can extract the raw bytes from the range.
|
||||
//
|
||||
// We could convert the node into a string and mark it as invalid
|
||||
// and would be clever to mark the type which is fewer in quantity.
|
||||
if byte_literal_count < strings.len() {
|
||||
// TODO(dhruvmanila): This is not an ideal recovery because the parser
|
||||
// replaces the byte literals with an invalid string literal node. Any
|
||||
// downstream tools can extract the raw bytes from the range.
|
||||
//
|
||||
// We could convert the node into a string and mark it as invalid
|
||||
// and would be clever to mark the type which is fewer in quantity.
|
||||
|
||||
// test_err mixed_bytes_and_non_bytes_literals
|
||||
// 'first' b'second'
|
||||
// f'first' b'second'
|
||||
// 'first' f'second' b'third'
|
||||
self.add_error(
|
||||
ParseErrorType::OtherError(
|
||||
"Bytes literal cannot be mixed with non-bytes literals".to_string(),
|
||||
),
|
||||
range,
|
||||
);
|
||||
}
|
||||
// Only construct a byte expression if all the literals are bytes
|
||||
// otherwise, we'll try either string, t-string, or f-string. This is to retain
|
||||
// as much information as possible.
|
||||
Ordering::Equal => {
|
||||
let mut values = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
values.push(match string {
|
||||
StringType::Bytes(value) => value,
|
||||
_ => unreachable!("Expected `StringType::Bytes`"),
|
||||
});
|
||||
}
|
||||
return Expr::from(ast::ExprBytesLiteral {
|
||||
value: ast::BytesLiteralValue::concatenated(values),
|
||||
range,
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
// test_err mixed_bytes_and_non_bytes_literals
|
||||
// 'first' b'second'
|
||||
// f'first' b'second'
|
||||
// 'first' f'second' b'third'
|
||||
self.add_error(
|
||||
ParseErrorType::OtherError(
|
||||
"Bytes literal cannot be mixed with non-bytes literals".to_string(),
|
||||
),
|
||||
range,
|
||||
);
|
||||
}
|
||||
// Only construct a byte expression if all the literals are bytes
|
||||
// otherwise, we'll try either string, t-string, or f-string. This is to retain
|
||||
// as much information as possible.
|
||||
else {
|
||||
let mut values = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
values.push(match string {
|
||||
StringType::Bytes(value) => value,
|
||||
_ => unreachable!("Expected `StringType::Bytes`"),
|
||||
});
|
||||
}
|
||||
Ordering::Greater => unreachable!(),
|
||||
return Expr::from(ast::ExprBytesLiteral {
|
||||
value: ast::BytesLiteralValue::concatenated(values),
|
||||
range,
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if has_tstring {
|
||||
if tstring_count < strings.len() {
|
||||
self.add_error(
|
||||
ParseErrorType::OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals".to_string(),
|
||||
),
|
||||
range,
|
||||
);
|
||||
}
|
||||
// Only construct a t-string expression if all the literals are t-strings
|
||||
// otherwise, we'll try either string or f-string. This is to retain
|
||||
// as much information as possible.
|
||||
else {
|
||||
let mut values = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
values.push(match string {
|
||||
StringType::TString(value) => value,
|
||||
_ => unreachable!("Expected `StringType::TString`"),
|
||||
});
|
||||
}
|
||||
return Expr::from(ast::ExprTString {
|
||||
value: ast::TStringValue::concatenated(values),
|
||||
range,
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1414,36 +1437,17 @@ impl<'src> Parser<'src> {
|
|||
});
|
||||
}
|
||||
|
||||
if has_tstring {
|
||||
let mut parts = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
match string {
|
||||
StringType::TString(tstring) => parts.push(ast::TStringPart::TString(tstring)),
|
||||
StringType::FString(fstring) => {
|
||||
parts.push(ruff_python_ast::TStringPart::FString(fstring));
|
||||
}
|
||||
StringType::Str(string) => parts.push(ast::TStringPart::Literal(string)),
|
||||
StringType::Bytes(bytes) => parts.push(ast::TStringPart::Literal(
|
||||
ast::StringLiteral::invalid(bytes.range()),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
return Expr::from(ast::ExprTString {
|
||||
value: ast::TStringValue::concatenated(parts),
|
||||
range,
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
});
|
||||
}
|
||||
|
||||
let mut parts = Vec::with_capacity(strings.len());
|
||||
for string in strings {
|
||||
match string {
|
||||
StringType::FString(fstring) => parts.push(ast::FStringPart::FString(fstring)),
|
||||
StringType::TString(_) => {
|
||||
unreachable!("expected no tstring parts by this point")
|
||||
}
|
||||
StringType::Str(string) => parts.push(ast::FStringPart::Literal(string)),
|
||||
// Bytes and Template strings are invalid at this point
|
||||
// and stored as invalid string literal parts in the
|
||||
// f-string
|
||||
StringType::TString(tstring) => parts.push(ast::FStringPart::Literal(
|
||||
ast::StringLiteral::invalid(tstring.range()),
|
||||
)),
|
||||
StringType::Bytes(bytes) => parts.push(ast::FStringPart::Literal(
|
||||
ast::StringLiteral::invalid(bytes.range()),
|
||||
)),
|
||||
|
|
|
@ -13,18 +13,16 @@ expression: suite
|
|||
range: 0..3,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..3,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..3,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
FString(
|
||||
FString {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: FStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..18,
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
FString(
|
||||
FString {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: FStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 19..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..22,
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..17,
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..17,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..17,
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 16..21,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 17..20,
|
||||
value: StringLiteralValue {
|
||||
inner: Single(
|
||||
StringLiteral {
|
||||
range: 17..20,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..22,
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..31,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..31,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 9..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 11..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 16..21,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 17..20,
|
||||
value: StringLiteralValue {
|
||||
inner: Single(
|
||||
StringLiteral {
|
||||
range: 17..20,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 23..31,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "again!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..31,
|
||||
}
|
|
@ -13,60 +13,58 @@ expression: suite
|
|||
range: 0..18,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
id: Name("a"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 7..8,
|
||||
id: Name("b"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 10..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "{foo}",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
id: Name("a"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 7..8,
|
||||
id: Name("b"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 10..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "{foo}",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,57 +13,55 @@ expression: suite
|
|||
range: 0..13,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Compare(
|
||||
ExprCompare {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..11,
|
||||
left: NumberLiteral(
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Compare(
|
||||
ExprCompare {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..11,
|
||||
left: NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..5,
|
||||
value: Int(
|
||||
42,
|
||||
),
|
||||
},
|
||||
),
|
||||
ops: [
|
||||
Eq,
|
||||
],
|
||||
comparators: [
|
||||
NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..5,
|
||||
range: 9..11,
|
||||
value: Int(
|
||||
42,
|
||||
),
|
||||
},
|
||||
),
|
||||
ops: [
|
||||
Eq,
|
||||
],
|
||||
comparators: [
|
||||
NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 9..11,
|
||||
value: Int(
|
||||
42,
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,87 +13,85 @@ expression: suite
|
|||
range: 0..16,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..15,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 7..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 8..13,
|
||||
value: StringLiteralValue {
|
||||
inner: Concatenated(
|
||||
ConcatenatedStringLiteral {
|
||||
strings: [
|
||||
StringLiteral {
|
||||
range: 8..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..16,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..15,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 7..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 8..13,
|
||||
value: StringLiteralValue {
|
||||
inner: Concatenated(
|
||||
ConcatenatedStringLiteral {
|
||||
strings: [
|
||||
StringLiteral {
|
||||
range: 8..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
StringLiteral {
|
||||
range: 11..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
StringLiteral {
|
||||
range: 11..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
],
|
||||
value: "",
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
],
|
||||
value: "",
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,60 +13,58 @@ expression: suite
|
|||
range: 0..15,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..15,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 7..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 8..12,
|
||||
id: Name("spec"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..15,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 7..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 8..12,
|
||||
id: Name("spec"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,72 +13,70 @@ expression: suite
|
|||
range: 0..13,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 8..10,
|
||||
value: StringLiteralValue {
|
||||
inner: Single(
|
||||
StringLiteral {
|
||||
range: 8..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: StringLiteral(
|
||||
ExprStringLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 8..10,
|
||||
value: StringLiteralValue {
|
||||
inner: Single(
|
||||
StringLiteral {
|
||||
range: 8..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,57 +13,55 @@ expression: suite
|
|||
range: 0..11,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Compare(
|
||||
ExprCompare {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..9,
|
||||
left: NumberLiteral(
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Compare(
|
||||
ExprCompare {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..9,
|
||||
left: NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
value: Int(
|
||||
1,
|
||||
),
|
||||
},
|
||||
),
|
||||
ops: [
|
||||
NotEq,
|
||||
],
|
||||
comparators: [
|
||||
NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
range: 8..9,
|
||||
value: Int(
|
||||
1,
|
||||
2,
|
||||
),
|
||||
},
|
||||
),
|
||||
ops: [
|
||||
NotEq,
|
||||
],
|
||||
comparators: [
|
||||
NumberLiteral(
|
||||
ExprNumberLiteral {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 8..9,
|
||||
value: Int(
|
||||
2,
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,50 +13,48 @@ expression: suite
|
|||
range: 0..13,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "spec",
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..6,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 7..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "spec",
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,41 +13,39 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: " =",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: " =",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,41 +13,39 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "= ",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..4,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "= ",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,35 +13,33 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Yield(
|
||||
ExprYield {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..8,
|
||||
value: None,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Yield(
|
||||
ExprYield {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..8,
|
||||
value: None,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..18,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Unicode,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..18,
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
[
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "Hello ",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Unicode,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 10..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 12..17,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "world",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 19..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "!",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Single,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/string.rs
|
||||
expression: suite
|
||||
---
|
||||
ParseError {
|
||||
error: OtherError(
|
||||
"cannot mix t-string literals with string or bytes literals",
|
||||
),
|
||||
location: 0..22,
|
||||
}
|
|
@ -13,38 +13,36 @@ expression: suite
|
|||
range: 0..7,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..7,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 3..6,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 4..5,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Raw {
|
||||
uppercase_r: false,
|
||||
TString {
|
||||
range: 0..7,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 3..6,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 4..5,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
triple_quoted: false,
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Raw {
|
||||
uppercase_r: false,
|
||||
},
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,38 +13,36 @@ expression: suite
|
|||
range: 0..11,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..7,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Raw {
|
||||
uppercase_r: false,
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..7,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
triple_quoted: true,
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Raw {
|
||||
uppercase_r: false,
|
||||
},
|
||||
triple_quoted: true,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,74 +13,72 @@ expression: suite
|
|||
range: 0..22,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "aaa",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..9,
|
||||
id: Name("bbb"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 10..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "ccc",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 13..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 14..17,
|
||||
id: Name("ddd"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 18..21,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "eee",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..22,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "aaa",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..9,
|
||||
id: Name("bbb"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 10..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "ccc",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 13..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 14..17,
|
||||
id: Name("ddd"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 18..21,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "eee",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,43 +13,41 @@ expression: suite
|
|||
range: 0..8,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..4,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\\",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 4..7,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 5..6,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..4,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\\",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 4..7,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 5..6,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,43 +13,41 @@ expression: suite
|
|||
range: 0..8,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..4,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\n",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 4..7,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 5..6,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..4,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\n",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 4..7,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 5..6,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,45 +13,43 @@ expression: suite
|
|||
range: 0..9,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 3..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\\\n",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..7,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Raw {
|
||||
uppercase_r: false,
|
||||
TString {
|
||||
range: 0..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 3..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\\\n",
|
||||
},
|
||||
triple_quoted: false,
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..7,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Raw {
|
||||
uppercase_r: false,
|
||||
},
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,41 +13,39 @@ expression: suite
|
|||
range: 0..10,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..7,
|
||||
id: Name("user"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..10,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..9,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..7,
|
||||
id: Name("user"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,77 +13,75 @@ expression: suite
|
|||
range: 0..38,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..38,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..6,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "mix ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 6..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 7..11,
|
||||
id: Name("user"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 13..28,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: " with text and ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 28..37,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 29..35,
|
||||
id: Name("second"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..38,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 2..6,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "mix ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 6..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 7..11,
|
||||
id: Name("user"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 13..28,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: " with text and ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 28..37,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 29..35,
|
||||
id: Name("second"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,55 +13,53 @@ expression: suite
|
|||
range: 0..14,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..7,
|
||||
id: Name("user"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 9..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 9..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: ">10",
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 0..14,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 2..13,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 3..7,
|
||||
id: Name("user"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 9..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 9..12,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: ">10",
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,43 +13,41 @@ expression: suite
|
|||
range: 0..11,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 4..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\n",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..7,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
TString {
|
||||
range: 0..11,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 4..5,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "\n",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 5..8,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 6..7,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -850,58 +850,58 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_1() {
|
||||
fn test_parse_t_string_concat_1_error() {
|
||||
let source = "'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_2() {
|
||||
fn test_parse_t_string_concat_2_error() {
|
||||
let source = "'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_3() {
|
||||
fn test_parse_t_string_concat_3_error() {
|
||||
let source = "'Hello ' t'world{\"!\"}'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_t_string_concat_4() {
|
||||
fn test_parse_t_string_concat_4_error() {
|
||||
let source = "'Hello ' t'world{\"!\"}' 'again!'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_u_t_string_concat_1() {
|
||||
fn test_parse_u_t_string_concat_1_error() {
|
||||
let source = "u'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_u_t_string_concat_2() {
|
||||
fn test_parse_u_t_string_concat_2_error() {
|
||||
let source = "u'Hello ' t'world' '!'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_f_t_string_concat_1() {
|
||||
fn test_parse_f_t_string_concat_1_error() {
|
||||
let source = "f'Hello ' t'world'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_f_t_string_concat_2() {
|
||||
fn test_parse_f_t_string_concat_2_error() {
|
||||
let source = "f'Hello ' t'world' '!'";
|
||||
let suite = parse_suite(source).unwrap();
|
||||
let suite = parse_suite(source).unwrap_err();
|
||||
insta::assert_debug_snapshot!(suite);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,36 +66,34 @@ Module(
|
|||
range: 10..19,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 10..19,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 12..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 13..14,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: Str,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 10..19,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 12..18,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 13..14,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: Str,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,36 +20,34 @@ Module(
|
|||
range: 44..49,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..49,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..48,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..47,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 44..49,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..48,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..47,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -66,36 +64,34 @@ Module(
|
|||
range: 50..57,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 50..57,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 52..56,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 53..53,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 50..57,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 52..56,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 53..53,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,36 +20,34 @@ Module(
|
|||
range: 44..52,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..51,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..48,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..51,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..48,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,36 +20,34 @@ Module(
|
|||
range: 44..54,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..54,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..53,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..48,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 44..54,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..53,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..48,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -66,36 +64,34 @@ Module(
|
|||
range: 55..65,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 55..65,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 57..64,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 58..59,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 55..65,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 57..64,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 58..59,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,43 +20,41 @@ Module(
|
|||
range: 121..127,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 121..127,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 123..126,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Starred(
|
||||
ExprStarred {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 124..125,
|
||||
value: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 125..125,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 121..127,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 123..126,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Starred(
|
||||
ExprStarred {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 124..125,
|
||||
value: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 125..125,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -73,60 +71,58 @@ Module(
|
|||
range: 128..141,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 128..141,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 130..140,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Starred(
|
||||
ExprStarred {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 131..139,
|
||||
value: BoolOp(
|
||||
ExprBoolOp {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 132..139,
|
||||
op: And,
|
||||
values: [
|
||||
Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 132..133,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 138..139,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 128..141,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 130..140,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Starred(
|
||||
ExprStarred {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 131..139,
|
||||
value: BoolOp(
|
||||
ExprBoolOp {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 132..139,
|
||||
op: And,
|
||||
values: [
|
||||
Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 132..133,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 138..139,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -143,51 +139,49 @@ Module(
|
|||
range: 142..155,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 142..155,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 144..154,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Starred(
|
||||
ExprStarred {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 145..153,
|
||||
value: Yield(
|
||||
ExprYield {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 146..153,
|
||||
value: Some(
|
||||
Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 152..153,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
TString {
|
||||
range: 142..155,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 144..154,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Starred(
|
||||
ExprStarred {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 145..153,
|
||||
value: Yield(
|
||||
ExprYield {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 146..153,
|
||||
value: Some(
|
||||
Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 152..153,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,78 +20,76 @@ Module(
|
|||
range: 44..60,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..60,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..56,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Lambda(
|
||||
ExprLambda {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..56,
|
||||
parameters: Some(
|
||||
Parameters {
|
||||
range: 54..55,
|
||||
node_index: AtomicNodeIndex(
|
||||
0,
|
||||
),
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
ParameterWithDefault {
|
||||
TString {
|
||||
range: 44..60,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..56,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Lambda(
|
||||
ExprLambda {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..56,
|
||||
parameters: Some(
|
||||
Parameters {
|
||||
range: 54..55,
|
||||
node_index: AtomicNodeIndex(
|
||||
0,
|
||||
),
|
||||
posonlyargs: [],
|
||||
args: [
|
||||
ParameterWithDefault {
|
||||
range: 54..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
parameter: Parameter {
|
||||
range: 54..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
parameter: Parameter {
|
||||
name: Identifier {
|
||||
id: Name("x"),
|
||||
range: 54..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
name: Identifier {
|
||||
id: Name("x"),
|
||||
range: 54..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
},
|
||||
annotation: None,
|
||||
},
|
||||
default: None,
|
||||
annotation: None,
|
||||
},
|
||||
],
|
||||
vararg: None,
|
||||
kwonlyargs: [],
|
||||
kwarg: None,
|
||||
},
|
||||
),
|
||||
body: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 56..56,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 56..58,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: " x",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
default: None,
|
||||
},
|
||||
],
|
||||
vararg: None,
|
||||
kwonlyargs: [],
|
||||
kwarg: None,
|
||||
},
|
||||
),
|
||||
body: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 56..56,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 56..58,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: " x",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -20,36 +20,34 @@ Module(
|
|||
range: 44..48,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..48,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..47,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..47,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 44..48,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..47,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..47,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -66,36 +64,34 @@ Module(
|
|||
range: 49..58,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 49..58,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 51..58,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 52..55,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 49..58,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 51..58,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 52..55,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -112,41 +108,39 @@ Module(
|
|||
range: 59..67,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 59..67,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 61..66,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 62..65,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 59..67,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 61..66,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 62..65,
|
||||
id: Name("foo"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: Some(
|
||||
DebugText {
|
||||
leading: "",
|
||||
trailing: "=",
|
||||
},
|
||||
),
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -164,66 +158,62 @@ Module(
|
|||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
TString(
|
||||
TString {
|
||||
range: 68..72,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 70..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 71..71,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 68..72,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 70..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 71..71,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 73..81,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 77..78,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 78..78,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
},
|
||||
TString {
|
||||
range: 73..81,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 77..78,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 78..78,
|
||||
id: Name(""),
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
|
|
|
@ -20,49 +20,47 @@ Module(
|
|||
range: 44..56,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..56,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 46..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "hello ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 52..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 53..54,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 55..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 44..56,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 46..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "hello ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 52..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 53..54,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 55..55,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -79,57 +77,55 @@ Module(
|
|||
range: 57..72,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 57..72,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 59..65,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "hello ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 65..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 66..67,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 68..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 68..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: ".3f",
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 57..72,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 59..65,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "hello ",
|
||||
},
|
||||
),
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 65..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 66..67,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: Some(
|
||||
InterpolatedStringFormatSpec {
|
||||
range: 68..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 68..71,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: ".3f",
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -8,7 +8,7 @@ input_file: crates/ruff_python_parser/resources/inline/err/template_strings_py31
|
|||
Module(
|
||||
ModModule {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..117,
|
||||
range: 0..89,
|
||||
body: [
|
||||
Expr(
|
||||
StmtExpr {
|
||||
|
@ -20,36 +20,34 @@ Module(
|
|||
range: 44..52,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..51,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..50,
|
||||
id: Name("hey"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..51,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..50,
|
||||
id: Name("hey"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -66,36 +64,34 @@ Module(
|
|||
range: 53..63,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 53..63,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 55..62,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 56..61,
|
||||
id: Name("there"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 53..63,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 55..62,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 56..61,
|
||||
id: Name("there"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -112,76 +108,24 @@ Module(
|
|||
range: 64..88,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 64..88,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 68..85,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "what's\nhappening?",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
TString {
|
||||
range: 64..88,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 68..85,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "what's\nhappening?",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 89..101,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "implicitly",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 101..116,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 103..115,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "concatenated",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -219,13 +163,4 @@ Module(
|
|||
4 | / t"""what's
|
||||
5 | | happening?"""
|
||||
| |_____________^ Syntax Error: Cannot use t-strings on Python 3.13 (syntax was added in Python 3.14)
|
||||
6 | "implicitly"t"concatenated"
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
4 | t"""what's
|
||||
5 | happening?"""
|
||||
6 | "implicitly"t"concatenated"
|
||||
| ^^^^^^^^^^^^^^^ Syntax Error: Cannot use t-strings on Python 3.13 (syntax was added in Python 3.14)
|
||||
|
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@ input_file: crates/ruff_python_parser/resources/inline/ok/template_strings_py314
|
|||
Module(
|
||||
ModModule {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 0..117,
|
||||
range: 0..89,
|
||||
body: [
|
||||
Expr(
|
||||
StmtExpr {
|
||||
|
@ -20,36 +20,34 @@ Module(
|
|||
range: 44..52,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..51,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..50,
|
||||
id: Name("hey"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 44..52,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 46..51,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 47..50,
|
||||
id: Name("hey"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -66,36 +64,34 @@ Module(
|
|||
range: 53..63,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 53..63,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 55..62,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 56..61,
|
||||
id: Name("there"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
TString {
|
||||
range: 53..63,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Interpolation(
|
||||
InterpolatedElement {
|
||||
range: 55..62,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
expression: Name(
|
||||
ExprName {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 56..61,
|
||||
id: Name("there"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
debug_text: None,
|
||||
conversion: None,
|
||||
format_spec: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Single,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -112,76 +108,24 @@ Module(
|
|||
range: 64..88,
|
||||
value: TStringValue {
|
||||
inner: Single(
|
||||
TString(
|
||||
TString {
|
||||
range: 64..88,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 68..85,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "what's\nhappening?",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
TString {
|
||||
range: 64..88,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 68..85,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "what's\nhappening?",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: true,
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
Expr(
|
||||
StmtExpr {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TString(
|
||||
ExprTString {
|
||||
node_index: AtomicNodeIndex(..),
|
||||
range: 89..116,
|
||||
value: TStringValue {
|
||||
inner: Concatenated(
|
||||
[
|
||||
Literal(
|
||||
StringLiteral {
|
||||
range: 89..101,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "implicitly",
|
||||
flags: StringLiteralFlags {
|
||||
quote_style: Double,
|
||||
prefix: Empty,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
TString(
|
||||
TString {
|
||||
range: 101..116,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
elements: [
|
||||
Literal(
|
||||
InterpolatedStringLiteralElement {
|
||||
range: 103..115,
|
||||
node_index: AtomicNodeIndex(..),
|
||||
value: "concatenated",
|
||||
},
|
||||
),
|
||||
],
|
||||
flags: TStringFlags {
|
||||
quote_style: Double,
|
||||
prefix: Regular,
|
||||
triple_quoted: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -5424,51 +5424,25 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
|
||||
fn infer_tstring_expression(&mut self, tstring: &ast::ExprTString) -> Type<'db> {
|
||||
let ast::ExprTString { value, .. } = tstring;
|
||||
for part in value {
|
||||
match part {
|
||||
ast::TStringPart::Literal(_) => {}
|
||||
ast::TStringPart::FString(fstring) => {
|
||||
for element in &fstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Interpolation(expression) => {
|
||||
let ast::InterpolatedElement {
|
||||
expression,
|
||||
format_spec,
|
||||
..
|
||||
} = expression;
|
||||
self.infer_expression(expression);
|
||||
|
||||
if let Some(format_spec) = format_spec {
|
||||
for element in format_spec.elements.interpolations() {
|
||||
self.infer_expression(&element.expression);
|
||||
}
|
||||
}
|
||||
for tstring in value {
|
||||
for element in &tstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Interpolation(
|
||||
tstring_interpolation_element,
|
||||
) => {
|
||||
let ast::InterpolatedElement {
|
||||
expression,
|
||||
format_spec,
|
||||
..
|
||||
} = tstring_interpolation_element;
|
||||
self.infer_expression(expression);
|
||||
if let Some(format_spec) = format_spec {
|
||||
for element in format_spec.elements.interpolations() {
|
||||
self.infer_expression(&element.expression);
|
||||
}
|
||||
ast::InterpolatedStringElement::Literal(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::TStringPart::TString(tstring) => {
|
||||
for element in &tstring.elements {
|
||||
match element {
|
||||
ast::InterpolatedStringElement::Interpolation(
|
||||
tstring_interpolation_element,
|
||||
) => {
|
||||
let ast::InterpolatedElement {
|
||||
expression,
|
||||
format_spec,
|
||||
..
|
||||
} = tstring_interpolation_element;
|
||||
self.infer_expression(expression);
|
||||
if let Some(format_spec) = format_spec {
|
||||
for element in format_spec.elements.interpolations() {
|
||||
self.infer_expression(&element.expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::InterpolatedStringElement::Literal(_) => {}
|
||||
}
|
||||
}
|
||||
ast::InterpolatedStringElement::Literal(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue