rusty-ast
A tool for parsing Rust code and visualizing its Abstract Syntax Tree (AST).
Features
- Parse Rust source files or code strings
- Visualize the AST structure in text format
- Display details of functions, structs, enums, and expressions
- Command-line tool with flexible options
Installation
Usage
CLI Tool
The rusty-ast command line tool can be used to parse and display the AST of Rust code.
# Parse a Rust file
# Parse Rust code from a string
# Control indentation
# Output in JSON format (coming soon)
As a Library
use ;
use Visit;
AST Structure
The tool displays Rust code structure with detailed information:
- Functions with parameters and return types
- Structs and their fields
- Enums and their variants
- Expressions (binary, function calls, conditionals, etc.)
- Literals (integers, floats, strings, booleans)
- Statements (variable declarations, expressions)
Requirements
- Rust 1.56 or higher
Dependencies
- syn: For parsing Rust code
- quote: For converting to token streams
- clap: For command-line argument parsing
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Here are some ways you can contribute:
- Implement JSON output format
- Add more detailed AST visualization
- Add support for more Rust language features
- Improve documentation and examples
Please feel free to submit issues and pull requests.
Acknowledgments
- Built on top of the excellent syn crate
- Inspired by tools like AST Explorer