Crate mz_walkabout
source ·Expand description
Visitor generation for Rust structs and enums.
Usage documentation is a work in progress, but for an example of the
generated visitor, see the sqlparser::ast::visit
module.
Some of our ASTs, which we represent with a tree of Rust structs and enums, are sufficiently complicated that maintaining a visitor by hand is onerous. This crate provides a generalizable framework for parsing Rust struct and enum definitions from source code and automatically generating tree traversal (“visitor”) code.
Note that the desired structure of the Visit
and VisitMut
traits
precludes the use of a custom derive procedural macro. We need to consider
the entire AST at once to build the Visit
and VisitMut
traits, and
derive macros only allow you to see one struct at a time.
The design of the visitors is modeled after the visitors provided by the
syn
crate. See: https://github.com/dtolnay/syn/tree/master/codegen
The name of this crate is an homage to CockroachDB’s Go package of the same name.
Modules§
- gen 🔒Code generation.
- Intermediate representation (IR) for codegen.
- parse 🔒A basic parser for Rust code.
Functions§
- Generates a fold transformer for a mutable AST.
- Generates a visitor for an immutable AST.
- Generates a visitor for a mutable AST.
- Loads type definitions from the specified module.