#[cfg(test)] mod test; use super::{error::SyntaxError, PipelineElement, PipelineElementKind}; pub fn check(syntax: &[PipelineElement]) -> Result<(), Vec> { let mut errs = Vec::new(); if let Err(e_span) = check_missing_streamer(syntax) { errs.push(SyntaxError::MissingStreamer(vec![e_span])); } if let Err(err_locs) = check_missing_filters(syntax) { errs.push(SyntaxError::MissingFilter(err_locs)) } if let Err(e_span) = check_missing_sink(syntax) { errs.push(SyntaxError::MissingSink(vec![e_span])); } if errs.is_empty() { Ok(()) } else { Err(errs) } } fn check_missing_streamer(syntax: &[PipelineElement]) -> Result<(), logos::Span> { if let Some(&PipelineElement { kind: PipelineElementKind::Pipe, ref span, }) = syntax.first() { Err(span.clone()) } else { Ok(()) } } fn check_missing_filters(syntax: &[PipelineElement]) -> Result<(), Vec> { let mut missing_filter_locs = Vec::new(); for i in 0..syntax.len() { if let ( Some(&PipelineElement { kind: PipelineElementKind::Pipe, ref span, }), Some(&PipelineElement { kind: PipelineElementKind::Pipe, span: ref span1, }), ) = (syntax.get(i), syntax.get(i + 1)) { missing_filter_locs.push(span.start..span1.end) } } if missing_filter_locs.is_empty() { Ok(()) } else { Err(missing_filter_locs) } } fn check_missing_sink(syntax: &[PipelineElement]) -> Result<(), logos::Span> { if let Some(&PipelineElement { kind: PipelineElementKind::Pipe, ref span, }) = syntax.last() { Err(span.clone()) } else { Ok(()) } }