RustPython / RustPython/Parser
Add `Node` union
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 117
- Forks
- 38
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 1
Description
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 API format(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:
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Node {
IfStmt(ast::IfStmt),
ConstantExpr(ast::ConstantExpr),
...
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, is_macro)]
enum NodeRef<'a> {
IfStmt(&'a ast::IfStmt),
ConstantExpr(&'a ast::ConstantExpr)
...
}
Note: An alternative naming more in line with
PathandPathBufwould be to name the typesNodeBuf(owned) andNode(reference)
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 a NodeRef
I may have time to work on this sometime soon but I wanted to put this up for discussion first to get feedback.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the existing AST node types and compare the proposed owned Node and reference NodeRef designs. Resolve the naming and ownership requirements before implementing the enum, conversion methods, and type checks. Done means the supported node types and required API are agreed and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100