2023-11-15 21:13:04 +01:00
|
|
|
use super::{
|
|
|
|
error::{FileId, SyntaxError},
|
|
|
|
PipelineElement, PipelineElementKind,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn check(
|
|
|
|
syntax: Vec<PipelineElement>,
|
|
|
|
raw_source: &str,
|
|
|
|
file_id: FileId,
|
|
|
|
) -> Result<Vec<PipelineElement>, Vec<SyntaxError>> {
|
|
|
|
let mut errs = Vec::new();
|
|
|
|
|
|
|
|
if let Err(e_span) = check_missing_streamer(&syntax) {
|
|
|
|
errs.push(SyntaxError::MissingStreamer(vec![(file_id, e_span)]));
|
|
|
|
}
|
|
|
|
|
2023-11-16 08:58:39 +01:00
|
|
|
if let Err(mut err_locs) = check_missing_filters(&syntax) {
|
|
|
|
errs.push(SyntaxError::MissingFilter(
|
|
|
|
err_locs.into_iter().map(|loc| (file_id, loc)).collect(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2023-11-15 21:13:04 +01:00
|
|
|
if errs.is_empty() {
|
|
|
|
Ok(syntax)
|
|
|
|
} else {
|
|
|
|
Err(errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_missing_streamer(syntax: &Vec<PipelineElement>) -> Result<(), logos::Span> {
|
|
|
|
if let Some(&PipelineElement {
|
|
|
|
kind: PipelineElementKind::Pipe,
|
|
|
|
ref span,
|
|
|
|
}) = syntax.first()
|
|
|
|
{
|
|
|
|
Err(span.clone())
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2023-11-16 08:58:39 +01:00
|
|
|
|
|
|
|
fn check_missing_filters(syntax: &Vec<PipelineElement>) -> Result<(), Vec<logos::Span>> {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|