3 releases
0.1.1 | Dec 26, 2024 |
---|---|
0.1.0 | Dec 26, 2024 |
#4 in #idl
298 downloads per month
56KB
1.5K
SLoC
Thrift Parser
A high-performance Apache Thrift IDL parser written in Rust that converts Thrift IDL files to JSON AST.
Features
- 🚀 Fast and efficient parsing
- 🎯 Complete Thrift IDL support
- 🔄 JSON AST output
- 📝 Comment preservation
- 🎨 Detailed source location tracking
- ⚡ Parallel processing support
- 📊 Built-in benchmarking
Installation
[dependencies]
rico_parser = "0.1.0"
Usage
Basic Parsing
use rico_parser::Parser;
fn main() {
let input = r#"
namespace rs demo
struct User {
1: string name
2: i32 age
}
"#;
let mut parser = Parser::new(input);
match parser.parse() {
Ok(ast) => println!("{}", serde_json::to_string_pretty(&ast).unwrap()),
Err(e) => eprintln!("Error: {}", e),
}
}
Command Line Tools
Scan Multiple Files
The project includes a CLI tool for processing multiple Thrift files:
cargo run -p thrift-scan -- --path ./thrift/files --output ./json/output
Benchmark Parser Performance
Run benchmarks on Thrift files:
cargo run -p thrift-benchmark
Project Structure
lib/
: Core parser libraryscan/
: CLI tool for batch processingbenchmark/
: Performance benchmarking tool
Supported Thrift Features
- Base types (i32, i64, string, etc.)
- Collections (list, set, map)
- Structs and Exceptions
- Services and Functions
- Enums
- Constants
- Typedefs
- Namespaces
- Includes
- Comments and Annotations
Development
Building
cargo build --workspace
Running Tests
cargo test --workspace
Code Structure
- Lexer: Tokenizes input using Logos
- Parser: Recursive descent parser
- AST: Strongly typed syntax tree
- Location Tracking: Preserves source positions
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Dependencies
~2.2–3MB
~34K SLoC