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 设计。在实现枚举、转换方法和类型检查之前,解决命名和所有权要求。支持的节点类型和所需的 API 达成一致并由测试覆盖后,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- rust
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100