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§
Sourcefn protocol_name(&self) -> &str
fn protocol_name(&self) -> &str
The panproto protocol name (e.g. "typescript", "python").
Sourcefn parse(&self, source: &[u8], file_path: &str) -> Result<Schema, ParseError>
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.
Sourcefn emit(&self, schema: &Schema) -> Result<Vec<u8>, ParseError>
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.
Sourcefn supported_extensions(&self) -> &[&str]
fn supported_extensions(&self) -> &[&str]
File extensions this parser handles (e.g. ["ts", "tsx"]).
Sourcefn theory_meta(&self) -> &ExtractedTheoryMeta
fn theory_meta(&self) -> &ExtractedTheoryMeta
The auto-derived theory metadata for this language.