RustPython / RustPython/Parser
Add `Node` union
還沒有人認領這個 Issue。
- 主要語言
- Rust
- 星號
- 117
- 分支
- 38
- 平均合併
- 4 天 7 小時
- 30 天內合併 PR
- 1
描述
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.
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
檢視現有的 AST 節點型別,並比較提議的擁有型 Node 與參照型 NodeRef 設計。在實作 enum、轉換方法和型別檢查之前,解決命名與所有權需求。支援的節點型別和必要的 API 達成共識並由測試涵蓋後,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- rust
- 領域
- compilers
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100