mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-13 07:08:19 +00:00
New AST nodes for f-string elements (#8835)
Rebase of #6365 authored by @davidszotten. ## Summary This PR updates the AST structure for an f-string elements. The main **motivation** behind this change is to have a dedicated node for the string part of an f-string. Previously, the existing `ExprStringLiteral` node was used for this purpose which isn't exactly correct. The `ExprStringLiteral` node should include the quotes as well in the range but the f-string literal element doesn't include the quote as it's a specific part within an f-string. For example, ```python f"foo {x}" # ^^^^ # This is the literal part of an f-string ``` The introduction of `FStringElement` enum is helpful which represent either the literal part or the expression part of an f-string. ### Rule Updates This means that there'll be two nodes representing a string depending on the context. One for a normal string literal while the other is a string literal within an f-string. The AST checker is updated to accommodate this change. The rules which work on string literal are updated to check on the literal part of f-string as well. #### Notes 1. The `Expr::is_literal_expr` method would check for `ExprStringLiteral` and return true if so. But now that we don't represent the literal part of an f-string using that node, this improves the method's behavior and confines to the actual expression. We do have the `FStringElement::is_literal` method. 2. We avoid checking if we're in a f-string context before adding to `string_type_definitions` because the f-string literal is now a dedicated node and not part of `Expr`. 3. Annotations cannot use f-string so we avoid changing any rules which work on annotation and checks for `ExprStringLiteral`. ## Test Plan - All references of `Expr::StringLiteral` were checked to see if any of the rules require updating to account for the f-string literal element node. - New test cases are added for rules which check against the literal part of an f-string. - Check the ecosystem results and ensure it remains unchanged. ## Performance There's a performance penalty in the parser. The reason for this remains unknown as it seems that the generated assembly code is now different for the `__reduce154` function. The reduce function body is just popping the `ParenthesizedExpr` on top of the stack and pushing it with the new location. - The size of `FStringElement` enum is the same as `Expr` which is what it replaces in `FString::format_spec` - The size of `FStringExpressionElement` is the same as `ExprFormattedValue` which is what it replaces I tried reducing the `Expr` enum from 80 bytes to 72 bytes but it hardly resulted in any performance gain. The difference can be seen here: - Original profile: https://share.firefox.dev/3Taa7ES - Profile after boxing some node fields: https://share.firefox.dev/3GsNXpD ### Backtracking I tried backtracking the changes to see if any of the isolated change produced this regression. The problem here is that the overall change is so small that there's only a single checkpoint where I can backtrack and that checkpoint results in the same regression. This checkpoint is to revert using `Expr` to the `FString::format_spec` field. After this point, the change would revert back to the original implementation. ## Review process The review process is similar to #7927. The first set of commits update the node structure, parser, and related AST files. Then, further commits update the linter and formatter part to account for the AST change. --------- Co-authored-by: David Szotten <davidszotten@gmail.com>
This commit is contained in:
parent
fcc08894cf
commit
cdac90ef68
77 changed files with 1714 additions and 1925 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::visitor::preorder::PreorderVisitor;
|
||||
use crate::{
|
||||
self as ast, Alias, ArgOrKeyword, Arguments, Comprehension, Decorator, ExceptHandler, Expr,
|
||||
Keyword, MatchCase, Mod, Parameter, ParameterWithDefault, Parameters, Pattern,
|
||||
FStringElement, Keyword, MatchCase, Mod, Parameter, ParameterWithDefault, Parameters, Pattern,
|
||||
PatternArguments, PatternKeyword, Stmt, TypeParam, TypeParamParamSpec, TypeParamTypeVar,
|
||||
TypeParamTypeVarTuple, TypeParams, WithItem,
|
||||
};
|
||||
|
@ -71,7 +71,6 @@ pub enum AnyNode {
|
|||
ExprYieldFrom(ast::ExprYieldFrom),
|
||||
ExprCompare(ast::ExprCompare),
|
||||
ExprCall(ast::ExprCall),
|
||||
ExprFormattedValue(ast::ExprFormattedValue),
|
||||
ExprFString(ast::ExprFString),
|
||||
ExprStringLiteral(ast::ExprStringLiteral),
|
||||
ExprBytesLiteral(ast::ExprBytesLiteral),
|
||||
|
@ -88,6 +87,8 @@ pub enum AnyNode {
|
|||
ExprSlice(ast::ExprSlice),
|
||||
ExprIpyEscapeCommand(ast::ExprIpyEscapeCommand),
|
||||
ExceptHandlerExceptHandler(ast::ExceptHandlerExceptHandler),
|
||||
FStringExpressionElement(ast::FStringExpressionElement),
|
||||
FStringLiteralElement(ast::FStringLiteralElement),
|
||||
PatternMatchValue(ast::PatternMatchValue),
|
||||
PatternMatchSingleton(ast::PatternMatchSingleton),
|
||||
PatternMatchSequence(ast::PatternMatchSequence),
|
||||
|
@ -166,7 +167,8 @@ impl AnyNode {
|
|||
| AnyNode::ExprYieldFrom(_)
|
||||
| AnyNode::ExprCompare(_)
|
||||
| AnyNode::ExprCall(_)
|
||||
| AnyNode::ExprFormattedValue(_)
|
||||
| AnyNode::FStringExpressionElement(_)
|
||||
| AnyNode::FStringLiteralElement(_)
|
||||
| AnyNode::ExprFString(_)
|
||||
| AnyNode::ExprStringLiteral(_)
|
||||
| AnyNode::ExprBytesLiteral(_)
|
||||
|
@ -233,7 +235,6 @@ impl AnyNode {
|
|||
AnyNode::ExprYieldFrom(node) => Some(Expr::YieldFrom(node)),
|
||||
AnyNode::ExprCompare(node) => Some(Expr::Compare(node)),
|
||||
AnyNode::ExprCall(node) => Some(Expr::Call(node)),
|
||||
AnyNode::ExprFormattedValue(node) => Some(Expr::FormattedValue(node)),
|
||||
AnyNode::ExprFString(node) => Some(Expr::FString(node)),
|
||||
AnyNode::ExprStringLiteral(node) => Some(Expr::StringLiteral(node)),
|
||||
AnyNode::ExprBytesLiteral(node) => Some(Expr::BytesLiteral(node)),
|
||||
|
@ -278,6 +279,8 @@ impl AnyNode {
|
|||
| AnyNode::StmtContinue(_)
|
||||
| AnyNode::StmtIpyEscapeCommand(_)
|
||||
| AnyNode::ExceptHandlerExceptHandler(_)
|
||||
| AnyNode::FStringExpressionElement(_)
|
||||
| AnyNode::FStringLiteralElement(_)
|
||||
| AnyNode::PatternMatchValue(_)
|
||||
| AnyNode::PatternMatchSingleton(_)
|
||||
| AnyNode::PatternMatchSequence(_)
|
||||
|
@ -356,7 +359,8 @@ impl AnyNode {
|
|||
| AnyNode::ExprYieldFrom(_)
|
||||
| AnyNode::ExprCompare(_)
|
||||
| AnyNode::ExprCall(_)
|
||||
| AnyNode::ExprFormattedValue(_)
|
||||
| AnyNode::FStringExpressionElement(_)
|
||||
| AnyNode::FStringLiteralElement(_)
|
||||
| AnyNode::ExprFString(_)
|
||||
| AnyNode::ExprStringLiteral(_)
|
||||
| AnyNode::ExprBytesLiteral(_)
|
||||
|
@ -459,7 +463,8 @@ impl AnyNode {
|
|||
| AnyNode::ExprYieldFrom(_)
|
||||
| AnyNode::ExprCompare(_)
|
||||
| AnyNode::ExprCall(_)
|
||||
| AnyNode::ExprFormattedValue(_)
|
||||
| AnyNode::FStringExpressionElement(_)
|
||||
| AnyNode::FStringLiteralElement(_)
|
||||
| AnyNode::ExprFString(_)
|
||||
| AnyNode::ExprStringLiteral(_)
|
||||
| AnyNode::ExprBytesLiteral(_)
|
||||
|
@ -547,7 +552,8 @@ impl AnyNode {
|
|||
| AnyNode::ExprYieldFrom(_)
|
||||
| AnyNode::ExprCompare(_)
|
||||
| AnyNode::ExprCall(_)
|
||||
| AnyNode::ExprFormattedValue(_)
|
||||
| AnyNode::FStringExpressionElement(_)
|
||||
| AnyNode::FStringLiteralElement(_)
|
||||
| AnyNode::ExprFString(_)
|
||||
| AnyNode::ExprStringLiteral(_)
|
||||
| AnyNode::ExprBytesLiteral(_)
|
||||
|
@ -660,7 +666,8 @@ impl AnyNode {
|
|||
Self::ExprYieldFrom(node) => AnyNodeRef::ExprYieldFrom(node),
|
||||
Self::ExprCompare(node) => AnyNodeRef::ExprCompare(node),
|
||||
Self::ExprCall(node) => AnyNodeRef::ExprCall(node),
|
||||
Self::ExprFormattedValue(node) => AnyNodeRef::ExprFormattedValue(node),
|
||||
Self::FStringExpressionElement(node) => AnyNodeRef::FStringExpressionElement(node),
|
||||
Self::FStringLiteralElement(node) => AnyNodeRef::FStringLiteralElement(node),
|
||||
Self::ExprFString(node) => AnyNodeRef::ExprFString(node),
|
||||
Self::ExprStringLiteral(node) => AnyNodeRef::ExprStringLiteral(node),
|
||||
Self::ExprBytesLiteral(node) => AnyNodeRef::ExprBytesLiteral(node),
|
||||
|
@ -2621,12 +2628,12 @@ impl AstNode for ast::ExprCall {
|
|||
visitor.visit_arguments(arguments);
|
||||
}
|
||||
}
|
||||
impl AstNode for ast::ExprFormattedValue {
|
||||
impl AstNode for ast::FStringExpressionElement {
|
||||
fn cast(kind: AnyNode) -> Option<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
if let AnyNode::ExprFormattedValue(node) = kind {
|
||||
if let AnyNode::FStringExpressionElement(node) = kind {
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
|
@ -2634,7 +2641,7 @@ impl AstNode for ast::ExprFormattedValue {
|
|||
}
|
||||
|
||||
fn cast_ref(kind: AnyNodeRef) -> Option<&Self> {
|
||||
if let AnyNodeRef::ExprFormattedValue(node) = kind {
|
||||
if let AnyNodeRef::FStringExpressionElement(node) = kind {
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
|
@ -2653,16 +2660,54 @@ impl AstNode for ast::ExprFormattedValue {
|
|||
where
|
||||
V: PreorderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprFormattedValue {
|
||||
value, format_spec, ..
|
||||
let ast::FStringExpressionElement {
|
||||
expression,
|
||||
format_spec,
|
||||
..
|
||||
} = self;
|
||||
visitor.visit_expr(value);
|
||||
visitor.visit_expr(expression);
|
||||
|
||||
if let Some(expr) = format_spec {
|
||||
visitor.visit_format_spec(expr);
|
||||
if let Some(format_spec) = format_spec {
|
||||
for spec_part in &format_spec.elements {
|
||||
visitor.visit_f_string_element(spec_part);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl AstNode for ast::FStringLiteralElement {
|
||||
fn cast(kind: AnyNode) -> Option<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
if let AnyNode::FStringLiteralElement(node) = kind {
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn cast_ref(kind: AnyNodeRef) -> Option<&Self> {
|
||||
if let AnyNodeRef::FStringLiteralElement(node) = kind {
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn as_any_node_ref(&self) -> AnyNodeRef {
|
||||
AnyNodeRef::from(self)
|
||||
}
|
||||
|
||||
fn into_any_node(self) -> AnyNode {
|
||||
AnyNode::from(self)
|
||||
}
|
||||
|
||||
fn visit_preorder<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: PreorderVisitor<'a> + ?Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
impl AstNode for ast::ExprFString {
|
||||
fn cast(kind: AnyNode) -> Option<Self>
|
||||
where
|
||||
|
@ -4339,10 +4384,10 @@ impl AstNode for ast::FString {
|
|||
where
|
||||
V: PreorderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::FString { values, range: _ } = self;
|
||||
let ast::FString { elements, range: _ } = self;
|
||||
|
||||
for expr in values {
|
||||
visitor.visit_expr(expr);
|
||||
for fstring_element in elements {
|
||||
visitor.visit_f_string_element(fstring_element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4467,7 +4512,6 @@ impl From<Expr> for AnyNode {
|
|||
Expr::YieldFrom(node) => AnyNode::ExprYieldFrom(node),
|
||||
Expr::Compare(node) => AnyNode::ExprCompare(node),
|
||||
Expr::Call(node) => AnyNode::ExprCall(node),
|
||||
Expr::FormattedValue(node) => AnyNode::ExprFormattedValue(node),
|
||||
Expr::FString(node) => AnyNode::ExprFString(node),
|
||||
Expr::StringLiteral(node) => AnyNode::ExprStringLiteral(node),
|
||||
Expr::BytesLiteral(node) => AnyNode::ExprBytesLiteral(node),
|
||||
|
@ -4496,6 +4540,15 @@ impl From<Mod> for AnyNode {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<FStringElement> for AnyNode {
|
||||
fn from(element: FStringElement) -> Self {
|
||||
match element {
|
||||
FStringElement::Literal(node) => AnyNode::FStringLiteralElement(node),
|
||||
FStringElement::Expression(node) => AnyNode::FStringExpressionElement(node),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Pattern> for AnyNode {
|
||||
fn from(pattern: Pattern) -> Self {
|
||||
match pattern {
|
||||
|
@ -4789,9 +4842,15 @@ impl From<ast::ExprCall> for AnyNode {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ast::ExprFormattedValue> for AnyNode {
|
||||
fn from(node: ast::ExprFormattedValue) -> Self {
|
||||
AnyNode::ExprFormattedValue(node)
|
||||
impl From<ast::FStringExpressionElement> for AnyNode {
|
||||
fn from(node: ast::FStringExpressionElement) -> Self {
|
||||
AnyNode::FStringExpressionElement(node)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ast::FStringLiteralElement> for AnyNode {
|
||||
fn from(node: ast::FStringLiteralElement) -> Self {
|
||||
AnyNode::FStringLiteralElement(node)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5089,7 +5148,8 @@ impl Ranged for AnyNode {
|
|||
AnyNode::ExprYieldFrom(node) => node.range(),
|
||||
AnyNode::ExprCompare(node) => node.range(),
|
||||
AnyNode::ExprCall(node) => node.range(),
|
||||
AnyNode::ExprFormattedValue(node) => node.range(),
|
||||
AnyNode::FStringExpressionElement(node) => node.range(),
|
||||
AnyNode::FStringLiteralElement(node) => node.range(),
|
||||
AnyNode::ExprFString(node) => node.range(),
|
||||
AnyNode::ExprStringLiteral(node) => node.range(),
|
||||
AnyNode::ExprBytesLiteral(node) => node.range(),
|
||||
|
@ -5184,7 +5244,8 @@ pub enum AnyNodeRef<'a> {
|
|||
ExprYieldFrom(&'a ast::ExprYieldFrom),
|
||||
ExprCompare(&'a ast::ExprCompare),
|
||||
ExprCall(&'a ast::ExprCall),
|
||||
ExprFormattedValue(&'a ast::ExprFormattedValue),
|
||||
FStringExpressionElement(&'a ast::FStringExpressionElement),
|
||||
FStringLiteralElement(&'a ast::FStringLiteralElement),
|
||||
ExprFString(&'a ast::ExprFString),
|
||||
ExprStringLiteral(&'a ast::ExprStringLiteral),
|
||||
ExprBytesLiteral(&'a ast::ExprBytesLiteral),
|
||||
|
@ -5278,7 +5339,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
AnyNodeRef::ExprYieldFrom(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::ExprCompare(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::ExprCall(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::ExprFormattedValue(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::FStringExpressionElement(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::FStringLiteralElement(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::ExprFString(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::ExprStringLiteral(node) => NonNull::from(*node).cast(),
|
||||
AnyNodeRef::ExprBytesLiteral(node) => NonNull::from(*node).cast(),
|
||||
|
@ -5378,7 +5440,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
AnyNodeRef::ExprYieldFrom(_) => NodeKind::ExprYieldFrom,
|
||||
AnyNodeRef::ExprCompare(_) => NodeKind::ExprCompare,
|
||||
AnyNodeRef::ExprCall(_) => NodeKind::ExprCall,
|
||||
AnyNodeRef::ExprFormattedValue(_) => NodeKind::ExprFormattedValue,
|
||||
AnyNodeRef::FStringExpressionElement(_) => NodeKind::FStringExpressionElement,
|
||||
AnyNodeRef::FStringLiteralElement(_) => NodeKind::FStringLiteralElement,
|
||||
AnyNodeRef::ExprFString(_) => NodeKind::ExprFString,
|
||||
AnyNodeRef::ExprStringLiteral(_) => NodeKind::ExprStringLiteral,
|
||||
AnyNodeRef::ExprBytesLiteral(_) => NodeKind::ExprBytesLiteral,
|
||||
|
@ -5473,7 +5536,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
| AnyNodeRef::ExprYieldFrom(_)
|
||||
| AnyNodeRef::ExprCompare(_)
|
||||
| AnyNodeRef::ExprCall(_)
|
||||
| AnyNodeRef::ExprFormattedValue(_)
|
||||
| AnyNodeRef::FStringExpressionElement(_)
|
||||
| AnyNodeRef::FStringLiteralElement(_)
|
||||
| AnyNodeRef::ExprFString(_)
|
||||
| AnyNodeRef::ExprStringLiteral(_)
|
||||
| AnyNodeRef::ExprBytesLiteral(_)
|
||||
|
@ -5540,7 +5604,6 @@ impl<'a> AnyNodeRef<'a> {
|
|||
| AnyNodeRef::ExprYieldFrom(_)
|
||||
| AnyNodeRef::ExprCompare(_)
|
||||
| AnyNodeRef::ExprCall(_)
|
||||
| AnyNodeRef::ExprFormattedValue(_)
|
||||
| AnyNodeRef::ExprFString(_)
|
||||
| AnyNodeRef::ExprStringLiteral(_)
|
||||
| AnyNodeRef::ExprBytesLiteral(_)
|
||||
|
@ -5585,6 +5648,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
| AnyNodeRef::StmtContinue(_)
|
||||
| AnyNodeRef::StmtIpyEscapeCommand(_)
|
||||
| AnyNodeRef::ExceptHandlerExceptHandler(_)
|
||||
| AnyNodeRef::FStringExpressionElement(_)
|
||||
| AnyNodeRef::FStringLiteralElement(_)
|
||||
| AnyNodeRef::PatternMatchValue(_)
|
||||
| AnyNodeRef::PatternMatchSingleton(_)
|
||||
| AnyNodeRef::PatternMatchSequence(_)
|
||||
|
@ -5662,7 +5727,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
| AnyNodeRef::ExprYieldFrom(_)
|
||||
| AnyNodeRef::ExprCompare(_)
|
||||
| AnyNodeRef::ExprCall(_)
|
||||
| AnyNodeRef::ExprFormattedValue(_)
|
||||
| AnyNodeRef::FStringExpressionElement(_)
|
||||
| AnyNodeRef::FStringLiteralElement(_)
|
||||
| AnyNodeRef::ExprFString(_)
|
||||
| AnyNodeRef::ExprStringLiteral(_)
|
||||
| AnyNodeRef::ExprBytesLiteral(_)
|
||||
|
@ -5765,7 +5831,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
| AnyNodeRef::ExprYieldFrom(_)
|
||||
| AnyNodeRef::ExprCompare(_)
|
||||
| AnyNodeRef::ExprCall(_)
|
||||
| AnyNodeRef::ExprFormattedValue(_)
|
||||
| AnyNodeRef::FStringExpressionElement(_)
|
||||
| AnyNodeRef::FStringLiteralElement(_)
|
||||
| AnyNodeRef::ExprFString(_)
|
||||
| AnyNodeRef::ExprStringLiteral(_)
|
||||
| AnyNodeRef::ExprBytesLiteral(_)
|
||||
|
@ -5853,7 +5920,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
| AnyNodeRef::ExprYieldFrom(_)
|
||||
| AnyNodeRef::ExprCompare(_)
|
||||
| AnyNodeRef::ExprCall(_)
|
||||
| AnyNodeRef::ExprFormattedValue(_)
|
||||
| AnyNodeRef::FStringExpressionElement(_)
|
||||
| AnyNodeRef::FStringLiteralElement(_)
|
||||
| AnyNodeRef::ExprFString(_)
|
||||
| AnyNodeRef::ExprStringLiteral(_)
|
||||
| AnyNodeRef::ExprBytesLiteral(_)
|
||||
|
@ -5975,7 +6043,8 @@ impl<'a> AnyNodeRef<'a> {
|
|||
AnyNodeRef::ExprYieldFrom(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::ExprCompare(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::ExprCall(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::ExprFormattedValue(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::FStringExpressionElement(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::FStringLiteralElement(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::ExprFString(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::ExprStringLiteral(node) => node.visit_preorder(visitor),
|
||||
AnyNodeRef::ExprBytesLiteral(node) => node.visit_preorder(visitor),
|
||||
|
@ -6354,9 +6423,15 @@ impl<'a> From<&'a ast::ExprCall> for AnyNodeRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::ExprFormattedValue> for AnyNodeRef<'a> {
|
||||
fn from(node: &'a ast::ExprFormattedValue) -> Self {
|
||||
AnyNodeRef::ExprFormattedValue(node)
|
||||
impl<'a> From<&'a ast::FStringExpressionElement> for AnyNodeRef<'a> {
|
||||
fn from(node: &'a ast::FStringExpressionElement) -> Self {
|
||||
AnyNodeRef::FStringExpressionElement(node)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::FStringLiteralElement> for AnyNodeRef<'a> {
|
||||
fn from(node: &'a ast::FStringLiteralElement) -> Self {
|
||||
AnyNodeRef::FStringLiteralElement(node)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6615,7 +6690,6 @@ impl<'a> From<&'a Expr> for AnyNodeRef<'a> {
|
|||
Expr::YieldFrom(node) => AnyNodeRef::ExprYieldFrom(node),
|
||||
Expr::Compare(node) => AnyNodeRef::ExprCompare(node),
|
||||
Expr::Call(node) => AnyNodeRef::ExprCall(node),
|
||||
Expr::FormattedValue(node) => AnyNodeRef::ExprFormattedValue(node),
|
||||
Expr::FString(node) => AnyNodeRef::ExprFString(node),
|
||||
Expr::StringLiteral(node) => AnyNodeRef::ExprStringLiteral(node),
|
||||
Expr::BytesLiteral(node) => AnyNodeRef::ExprBytesLiteral(node),
|
||||
|
@ -6644,6 +6718,15 @@ impl<'a> From<&'a Mod> for AnyNodeRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a FStringElement> for AnyNodeRef<'a> {
|
||||
fn from(element: &'a FStringElement) -> Self {
|
||||
match element {
|
||||
FStringElement::Expression(node) => AnyNodeRef::FStringExpressionElement(node),
|
||||
FStringElement::Literal(node) => AnyNodeRef::FStringLiteralElement(node),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Pattern> for AnyNodeRef<'a> {
|
||||
fn from(pattern: &'a Pattern) -> Self {
|
||||
match pattern {
|
||||
|
@ -6772,7 +6855,8 @@ impl Ranged for AnyNodeRef<'_> {
|
|||
AnyNodeRef::ExprYieldFrom(node) => node.range(),
|
||||
AnyNodeRef::ExprCompare(node) => node.range(),
|
||||
AnyNodeRef::ExprCall(node) => node.range(),
|
||||
AnyNodeRef::ExprFormattedValue(node) => node.range(),
|
||||
AnyNodeRef::FStringExpressionElement(node) => node.range(),
|
||||
AnyNodeRef::FStringLiteralElement(node) => node.range(),
|
||||
AnyNodeRef::ExprFString(node) => node.range(),
|
||||
AnyNodeRef::ExprStringLiteral(node) => node.range(),
|
||||
AnyNodeRef::ExprBytesLiteral(node) => node.range(),
|
||||
|
@ -6869,7 +6953,8 @@ pub enum NodeKind {
|
|||
ExprYieldFrom,
|
||||
ExprCompare,
|
||||
ExprCall,
|
||||
ExprFormattedValue,
|
||||
FStringExpressionElement,
|
||||
FStringLiteralElement,
|
||||
ExprFString,
|
||||
ExprStringLiteral,
|
||||
ExprBytesLiteral,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue