astral-sh/ruff

Auto-generate more of the AST representation

開放

#15,655 建立於 2025年1月21日

 (1 則留言) (2 個反應) (0 位負責人)Rust (2,088 個分叉)batch import
help wantedinternal

倉庫指標

星標
 (47,527 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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).

貢獻者指南