astral-sh/ruff

Auto-generate more of the AST representation

Open

#15,655 创建于 2025年1月21日

在 GitHub 查看
 (1 评论) (2 反应) (0 负责人)Rust (47,527 star) (2,088 fork)batch import
help wantedinternal

描述

In #15544 we added a script to auto-generate large parts of the Rust data model that we use to store the AST of parsed Python code. That script consumes a TOML file, which describes all of the possible syntax nodes (e.g., StmtIf, ExprBinOp) and any groups those nodes belong to (e.g. Stmt, Expr). The details of each syntax node are still defined manually in Rust.

We could go further with auto-generation, with existing art that we could build on. rust-analyzer uses ungrammar, while Python itself uses ASDL (asdl, parser, codegen). This would eliminate even more tedious hand-written Rust code — not just the struct/enum definitions themselves, but even things like the visit_source_order methods for each syntax node. It would also allow us to experiment more easily with other internal representations for the parsed AST — such as using IndexVec to store the syntax node content (as alluded to in https://github.com/astral-sh/ruff/pull/12419#issuecomment-2262727929).

贡献者指南

Auto-generate more of the AST representation · astral-sh/ruff#15655 | Good First Issue