forked from katzen-cafe/iowo
49 lines
1.9 KiB
Rust
49 lines
1.9 KiB
Rust
|
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||
|
|
||
|
pub type FileId = usize;
|
||
|
|
||
|
/// The enum representing a syntax error, used for error reporting
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub enum SyntaxError {
|
||
|
/// This variant indicates a token that the Lexer didn't recognize
|
||
|
InvalidToken(Vec<(FileId, logos::Span)>),
|
||
|
/// `MissingStreamer` means, that the pipeline starts with a Pipe (`|`), so it has no streamer as input in front of it.
|
||
|
MissingStreamer(Vec<(FileId, logos::Span)>),
|
||
|
/// `MissingSink` means, that the pipeline ends with a Pipe (`|`), meaning that the output can't go anywhere
|
||
|
MissingSink,
|
||
|
/// This indicates a missing filter somewhere in the pipeline, meaning that there's 2 pipes after one another
|
||
|
MissingFilter,
|
||
|
/// A literal cannot be a sink
|
||
|
LiteralAsSink,
|
||
|
/// A literal can't be a filter either
|
||
|
LiteralAsFilter,
|
||
|
/// A literal acting as streamer cannot take arguments
|
||
|
LiteralWithArgs,
|
||
|
}
|
||
|
|
||
|
impl SyntaxError {
|
||
|
pub fn to_diagnostic(&self) -> Diagnostic<usize> {
|
||
|
match self {
|
||
|
Self::InvalidToken(errs) => Diagnostic::error()
|
||
|
.with_message("failed to parse invalid tokens")
|
||
|
.with_labels(
|
||
|
errs.into_iter()
|
||
|
.map(|(file_id, span)| {
|
||
|
Label::primary(*file_id, span.clone()).with_message("invalid token")
|
||
|
})
|
||
|
.collect(),
|
||
|
),
|
||
|
Self::MissingStreamer(locs) => Diagnostic::error()
|
||
|
.with_message("pipelines must always start with a streamer")
|
||
|
.with_labels(
|
||
|
locs.into_iter()
|
||
|
.map(|(file_id, span)| {
|
||
|
Label::primary(*file_id, span.clone()).with_message("missing streamer")
|
||
|
})
|
||
|
.collect(),
|
||
|
),
|
||
|
_ => todo!(),
|
||
|
}
|
||
|
}
|
||
|
}
|