iowo/src/syntax/check.rs

35 lines
766 B
Rust
Raw Normal View History

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)]));
}
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(())
}
}