use std::path::Path;
use crate::types::{ParseError, Spec};
mod clauses;
mod ids;
mod keywords;
mod metadata;
mod state;
pub trait Parser: Send + Sync {
fn parse_file(&self, path: &Path) -> Result<Spec, Vec<ParseError>> {
let content = std::fs::read_to_string(path).map_err(|e| {
vec![ParseError {
file: path.to_path_buf(),
line: 0,
message: format!("failed to read file: {}", e),
}]
})?;
self.parse_string(&content, path)
}
fn parse_string(&self, content: &str, path: &Path) -> Result<Spec, Vec<ParseError>>;
fn name(&self) -> &str;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct OughtMdParser;
impl Parser for OughtMdParser {
fn parse_string(&self, content: &str, path: &Path) -> Result<Spec, Vec<ParseError>> {
state::parse_string(content, path)
}
fn name(&self) -> &str {
"ought.md"
}
}