#thrift #idl #ast #json #parser

rico

A high-performance Apache Thrift IDL parser that converts Thrift IDL files to JSON AST

9 releases

new 0.1.7 Jan 5, 2025
0.1.6 Jan 2, 2025
0.1.6-alpha.1 Dec 29, 2024

#1735 in Parser implementations

Download history 103/week @ 2024-12-21 378/week @ 2024-12-28

481 downloads per month
Used in rico-scan

MIT license

99KB
2K 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 = { version = "*" }

Usage

Basic Parsing

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),
    }
}

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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Logos for lexer generation
  • Serde for JSON serialization

Dependencies

~6–12MB
~117K SLoC