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§
Sourcefn parse_string(
&self,
content: &str,
path: &Path,
) -> Result<Spec, Vec<ParseError>>
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.
Provided Methods§
Sourcefn parse_file(&self, path: &Path) -> Result<Spec, Vec<ParseError>>
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.