-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Node
union
#48
Comments
pub enum AST {
Stmt(ast::Stmt),
Expr(ast::Expr),
...
} Then IfStmt and ConstantExpr will be under each variant. Do you need to flatten all the nodes? |
I haven't thought about it much but we can probably do either and both approaches have pros and cons:
|
Because adding top-level nodes to the root type |
What do you mean by top level? Do you mean the 'Stmt' and Expr (ond others) enums or something else? We can also add this to ruff_python_ast first and upstream it when we've figured out the api and you believe that this would be useful for RustPython too |
In
|
Add a new
Node
union that is an enum over all node types. This can be useful when implementing methods that can operate on any node. For example, Ruff's formatter has (roughly) the APIformat(node: AnyNode) -> String
I haven't figured out the full requirements yet, and I don't know yet if we'll need both the owned and reference versions:
The enums should have the following basic methods:
if_stmt(self) -> Option<ast::IfStmt>
as_if_stmt(&self) -> Option<&ast::IfStmt>
const is_if_stmt(&self) -> bool
Node could also implement
AsRef
that returns aNodeRef
I may have time to work on this sometime soon but I wanted to put this up for discussion first to get feedback.
The text was updated successfully, but these errors were encountered: