use crate::{
error::{CowStr, PassResult, SourceDiag},
Recipe,
};
mod event_consumer;
pub use event_consumer::parse_events;
pub type AnalysisResult = PassResult<Recipe>;
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub(crate) enum DefineMode {
All,
Components,
Steps,
Text,
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub(crate) enum DuplicateMode {
New,
Reference,
}
#[derive(Default)]
pub struct ParseOptions<'a> {
pub recipe_ref_check: Option<RecipeRefCheck<'a>>,
pub metadata_validator: Option<MetadataValidator<'a>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CheckResult {
Ok,
Warning(Vec<CowStr>),
Error(Vec<CowStr>),
}
impl CheckResult {
pub(crate) fn into_source_diag<F, O>(self, message: F) -> Option<SourceDiag>
where
F: FnOnce() -> O,
O: Into<CowStr>,
{
let (severity, hints) = match self {
CheckResult::Ok => return None,
CheckResult::Warning(hints) => (crate::error::Severity::Warning, hints),
CheckResult::Error(hints) => (crate::error::Severity::Error, hints),
};
let mut diag = SourceDiag::unlabeled(message(), severity, crate::error::Stage::Analysis);
for hint in hints {
diag.add_hint(hint);
}
Some(diag)
}
}
pub struct CheckOptions {
include: bool,
run_std_checks: bool,
}
impl Default for CheckOptions {
fn default() -> Self {
Self {
include: true,
run_std_checks: true,
}
}
}
impl CheckOptions {
pub fn include(&mut self, do_include: bool) {
self.include = do_include;
}
pub fn run_std_checks(&mut self, do_check: bool) {
self.run_std_checks = do_check;
}
}
pub type RecipeRefCheck<'a> = Box<dyn FnMut(&str) -> CheckResult + 'a>;
pub type MetadataValidator<'a> =
Box<dyn FnMut(&serde_yaml::Value, &serde_yaml::Value, &mut CheckOptions) -> CheckResult + 'a>;