mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 09:30:35 +00:00
[internal] Move Linter OperatorPrecedence
into ruff_python_ast
crate (#16162)
## Summary This change begins to resolve #16071 by moving the `OperatorPrecedence` structs from the `ruff_python_linter` crate into `ruff_python_ast`. This PR also implements `precedence()` methods on the `Expr` and `ExprRef` enums. ## Test Plan Since this change mainly shifts existing logic, I didn't add any additional tests. Existing tests do pass.
This commit is contained in:
parent
63dd68e0ed
commit
fa28dc5ccf
5 changed files with 193 additions and 168 deletions
|
@ -18,7 +18,8 @@ use crate::{
|
|||
name::Name,
|
||||
str::{Quote, TripleQuotes},
|
||||
str_prefix::{AnyStringPrefix, ByteStringPrefix, FStringPrefix, StringLiteralPrefix},
|
||||
ExceptHandler, Expr, FStringElement, LiteralExpressionRef, Pattern, Stmt, TypeParam,
|
||||
ExceptHandler, Expr, ExprRef, FStringElement, LiteralExpressionRef, OperatorPrecedence,
|
||||
Pattern, Stmt, TypeParam,
|
||||
};
|
||||
|
||||
/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)
|
||||
|
@ -365,6 +366,17 @@ impl Expr {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the [`OperatorPrecedence`] of this expression
|
||||
pub fn precedence(&self) -> OperatorPrecedence {
|
||||
OperatorPrecedence::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprRef<'_> {
|
||||
pub fn precedence(&self) -> OperatorPrecedence {
|
||||
OperatorPrecedence::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// An AST node used to represent a IPython escape command at the expression level.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue