pub trait Parser {
type Error: Error + Send + Sync + 'static;
// Required methods
fn parse(&mut self, input: &str) -> Result<IRModule, Self::Error>;
fn name(&self) -> &'static str;
fn extensions(&self) -> &[&'static str];
// Provided methods
fn validate(&self, _input: &str) -> Result<(), Self::Error> { ... }
fn metadata(&self) -> ParserMetadata { ... }
}Expand description
Core trait for all parsers
Implement this trait to add support for new input formats. The parser is responsible for converting input text into an IR module that can be processed by code generators.
§Type Parameters
Error- The error type produced by this parser. Must implementstd::error::Error + Send + Sync + 'staticfor composability.
§Examples
ⓘ
use unistructgen_core::{Parser, IRModule};
struct MyParser {
options: MyOptions,
}
impl Parser for MyParser {
type Error = MyParserError;
fn parse(&mut self, input: &str) -> Result<IRModule, Self::Error> {
// Parse input and return IR
todo!()
}
fn name(&self) -> &'static str {
"MyFormat"
}
fn extensions(&self) -> &[&'static str] {
&["my", "myformat"]
}
}Required Associated Types§
Required Methods§
Sourcefn extensions(&self) -> &[&'static str]
fn extensions(&self) -> &[&'static str]
Provided Methods§
Sourcefn metadata(&self) -> ParserMetadata
fn metadata(&self) -> ParserMetadata
Get metadata about the parser (optional)
Returns additional information about the parser’s capabilities, version, etc. Default implementation returns empty metadata.