ferogram-tl-parser 0.1.0

Parser for Telegram's Type Language (.tl) schema files
Documentation
  • Coverage
  • 100%
    46 out of 46 items documented1 out of 4 items with examples
  • Size
  • Source code size: 35.05 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.38 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 38s Average build duration of successful builds.
  • all releases: 38s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ankit-chaubey/ferogram
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ankit-chaubey

ferogram-tl-parser

Parser for Telegram's TL (Type Language) schema files.

Crates.io Telegram Channel docs.rs Telegram Channel License: MIT OR Apache-2.0 Telegram Channel

Reads .tl schema files and produces a structured AST. Used internally by ferogram-tl-gen as a build-dependency - most users don't depend on this crate directly.


Installation

[dependencies]
ferogram-tl-parser = "0.4.8"

AST Types

pub struct Definition {
    pub name:     String,
    pub id:       Option<u32>,    // CRC32, may be omitted
    pub params:   Vec<Parameter>,
    pub ty:       Type,
    pub category: Category,       // Type or Function
}

pub enum ParameterType {
    Flags,
    Normal { ty: Type, flag: Option<Flag> },
    Repeated { params: Vec<Parameter> },
}

pub enum Category { Type, Function }

Usage

use ferogram_tl_parser::{parse_tl_file, TlIterator, tl::Category};

// Collect all definitions
let schema = std::fs::read_to_string("api.tl").unwrap();
let definitions = parse_tl_file(&schema).unwrap();

// Streaming iterator (lower memory)
for def in TlIterator::new(&schema) {
    match def.category {
        Category::Type     => { /* constructor */ }
        Category::Function => { /* RPC function */ }
    }
}

Parse errors return ParseError with the failing line. Malformed tokens stop the iterator rather than silently skipping.


Stack position

ferogram-tl-types
└ ferogram-tl-gen
  └ ferogram-tl-parser  <-- here

License

MIT or Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.

Ankit Chaubey - github.com/ankit-chaubey