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;
// Provided method
fn emit_pretty(&self, schema: &Schema) -> Result<Vec<u8>, ParseError> { ... }
}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.
Provided Methods§
Sourcefn emit_pretty(&self, schema: &Schema) -> Result<Vec<u8>, ParseError>
fn emit_pretty(&self, schema: &Schema) -> Result<Vec<u8>, ParseError>
Render a by-construction Schema (one with no parse-recovered
byte positions or interstitials) to source bytes.
Unlike emit, which reconstructs source from
byte-position fragments stored on the schema during parse,
emit_pretty walks tree-sitter grammar.json production rules
to render schemas built from scratch via SchemaBuilder.
§Errors
Returns ParseError::EmitFailed when the language has no
vendored grammar.json, when a vertex’s kind is not a grammar
rule, or when a required field has no corresponding schema edge.