Skip to main content

AstParser

Trait AstParser 

Source
pub trait AstParser: Send + Sync {
    // Required methods
    fn protocol_name(&self) -> &str;
    fn parse(
        &self,
        source: &[u8],
        file_path: &str,
    ) -> Result<Schema, ParseError>;
    fn emit(&self, schema: &Schema) -> Result<Vec<u8>, ParseError>;
    fn supported_extensions(&self) -> &[&str];
    fn theory_meta(&self) -> &ExtractedTheoryMeta;
}
Expand description

A full-AST parser and emitter for a specific programming language.

Each implementation wraps a tree-sitter grammar and its auto-derived theory, providing parse (source → Schema) and emit (Schema → source) operations.

Required Methods§

Source

fn protocol_name(&self) -> &str

The panproto protocol name (e.g. "typescript", "python").

Source

fn parse(&self, source: &[u8], file_path: &str) -> Result<Schema, ParseError>

Parse source code into a full-AST Schema.

§Errors

Returns ParseError if tree-sitter parsing fails or schema construction fails.

Source

fn emit(&self, schema: &Schema) -> Result<Vec<u8>, ParseError>

Emit a Schema back to source code bytes.

The emitter walks the schema graph top-down, using formatting constraints (comment, indent, blank-lines-before) to reproduce the original formatting.

§Errors

Returns ParseError::EmitFailed if emission fails.

Source

fn supported_extensions(&self) -> &[&str]

File extensions this parser handles (e.g. ["ts", "tsx"]).

Source

fn theory_meta(&self) -> &ExtractedTheoryMeta

The auto-derived theory metadata for this language.

Implementors§