Closed youknowone closed 1 year ago
cc @MichaReiser
Thanks for working on this and sorry for my late reply. I've been busy with other work and haven't had time to think more about the problem.
I still think that I would favor the flat structure over the nested one because:
is_stmt()
, as_stmt()
and stmt()
on the flat structure. Would you mind if I change the enum to a flat structure? I will also introduce a AstRef
as part of that work because that's actually the enum that I need first.
Because current Ast
enum is the counter part of python side ast.AST
(each rust enum matches to inheritance from Python), adding a new enum for flat structure seems better if you need one. Before adding the Ast
type, the top level ast.AST
was the only missing type from Rust side.
On the other hand, adding is_stmt_if()
to current Ast
seems also reasonable if it fits your requirements. (probably not if you need to use match)
I wish conversion between Ast and other types like Stmt and Expr doesn't require much cost. If we can achieve it with flat structure, that's also fine.
Because current
Ast
enum is the counter part of python sideast.AST
(each rust enum matches to inheritance from Python), adding a new enum for flat structure seems better if you need one. Before adding theAst
type, the top levelast.AST
was the only missing type from Rust side. On the other hand, addingis_stmt_if()
to currentAst
seems also reasonable if it fits your requirements. (probably not if you need to use match)
I'll add it on the Ruff side if you want to keep using the Ast
node for CPython compatibility
Yes, that will be a good option.
One of the possible solution of #48