1use crate::{
7 error::{CowStr, PassResult, SourceDiag},
8 Recipe,
9};
10
11mod event_consumer;
12
13pub use event_consumer::parse_events;
14
15pub type AnalysisResult = PassResult<Recipe>;
16
17#[derive(PartialEq, Eq, Debug, Clone, Copy)]
18pub(crate) enum DefineMode {
19 All,
20 Components,
21 Steps,
22 Text,
23}
24
25#[derive(PartialEq, Eq, Debug, Clone, Copy)]
26pub(crate) enum DuplicateMode {
27 New,
28 Reference,
29}
30
31#[derive(Default)]
33pub struct ParseOptions<'a> {
34 pub recipe_ref_check: Option<RecipeRefCheck<'a>>,
36 pub metadata_validator: Option<MetadataValidator<'a>>,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
51pub enum CheckResult {
52 Ok,
53 Warning(Vec<CowStr>),
54 Error(Vec<CowStr>),
55}
56
57impl CheckResult {
58 pub(crate) fn into_source_diag<F, O>(self, message: F) -> Option<SourceDiag>
59 where
60 F: FnOnce() -> O,
61 O: Into<CowStr>,
62 {
63 let (severity, hints) = match self {
64 CheckResult::Ok => return None,
65 CheckResult::Warning(hints) => (crate::error::Severity::Warning, hints),
66 CheckResult::Error(hints) => (crate::error::Severity::Error, hints),
67 };
68 let mut diag = SourceDiag::unlabeled(message(), severity, crate::error::Stage::Analysis);
69 for hint in hints {
70 diag.add_hint(hint);
71 }
72 Some(diag)
73 }
74}
75
76pub struct CheckOptions {
81 include: bool,
82 run_std_checks: bool,
83}
84
85impl Default for CheckOptions {
86 fn default() -> Self {
87 Self {
88 include: true,
89 run_std_checks: true,
90 }
91 }
92}
93
94impl CheckOptions {
95 pub fn include(&mut self, do_include: bool) {
100 self.include = do_include;
101 }
102
103 pub fn run_std_checks(&mut self, do_check: bool) {
111 self.run_std_checks = do_check;
112 }
113}
114
115pub type RecipeRefCheck<'a> = Box<dyn FnMut(&str) -> CheckResult + 'a>;
116pub type MetadataValidator<'a> =
117 Box<dyn FnMut(&serde_yaml::Value, &serde_yaml::Value, &mut CheckOptions) -> CheckResult + 'a>;