A high-performance Apache Thrift IDL parser written in Rust that converts Thrift IDL files to JSON AST.
- 🚀 Fast and efficient parsing
- 🎯 Complete Thrift IDL support
- 🔄 JSON AST output
- 📝 Comment preservation
- 🎨 Detailed source location tracking
- ⚡ Parallel processing support
- 📊 Built-in benchmarking
The program takes 0.03
seconds, which is nearly a 10x performance improvement compared to the JavaScript implementation.
The test file contains approximately 15,000 lines of code.
[dependencies]
rico = "*"
use rico::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),
}
}
You can also use the rico-scan
command to scan multiple files and output the JSON AST to a folder.
cargo install rico-scan
Now you can use the rico-scan
CLI tool for processing multiple Thrift files:
rico-scan --path ./thrift/files --output ./output
Run benchmarks on Thrift files:
cargo run -p benchmark
creates/rico/
: Core parser libraryapps/scan/
: CLI tool for batch processingapps/benchmark/
: Performance benchmarking tool
- Base types (i32, i64, string, etc.)
- Collections (list, set, map)
- Structs and Exceptions
- Services and Functions
- Enums
- Constants
- Typedefs
- Namespaces
- Includes
- Comments and Annotations
# Install insta
curl -LsSf https://insta.rs/install.sh | sh
# Install pnpm
npm install -g pnpm bun
# Install dependencies
pnpm install
build crates
cargo build --workspace
build docs
cargo doc --workspace
build wasm
cd wasm/rico && npm run build
// debug use bun
bun examples/basic.ts
You can for instance first run the tests and not write and new snapshots, and if you like them run the tests again and update them:
INSTA_UPDATE=no cargo test
INSTA_UPDATE=always cargo test
For more information see insta
- Lexer: Tokenizes input using Logos
- Parser: Recursive descent parser
- AST: Strongly typed syntax tree
- Location Tracking: Preserves source positions
- 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
This project is licensed under the MIT License - see the LICENSE file for details.