mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2025-09-25 16:01:30 +02:00
implement better checking and errors
This commit is contained in:
parent
3f4846744b
commit
344afa22b5
4 changed files with 125 additions and 52 deletions
48
src/syntax/error.rs
Normal file
48
src/syntax/error.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
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!(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue