Skip to main content

Parser

Trait Parser 

Source
pub trait Parser: Send + Sync {
    // Required methods
    fn parse_string(
        &self,
        content: &str,
        path: &Path,
    ) -> Result<Spec, Vec<ParseError>>;
    fn name(&self) -> &str;

    // Provided method
    fn parse_file(&self, path: &Path) -> Result<Spec, Vec<ParseError>> { ... }
}
Expand description

The public interface for parsing spec files into the ought IR.

Mirrors ought_run::Runner: one trait, one concrete implementation today (OughtMdParser), and room to add more spec formats without breaking callers. Most consumers should take &dyn Parser (or impl Parser) rather than naming a concrete type.

Required Methods§

Source

fn parse_string( &self, content: &str, path: &Path, ) -> Result<Spec, Vec<ParseError>>

Parse a spec from an in-memory string, using path only as the source-location label for error messages and source locations.

Source

fn name(&self) -> &str

Short, stable name for this parser (e.g. "ought.md"). Used for diagnostics and, eventually, format dispatch.

Provided Methods§

Source

fn parse_file(&self, path: &Path) -> Result<Spec, Vec<ParseError>>

Parse a spec file from disk. The default implementation reads the file and delegates to Parser::parse_string, so format-specific parsers usually only need to implement parse_string.

Implementors§