use miette::Diagnostic;
use thiserror::Error;
use crate::lex::{LexError, TokenKind};
#[derive(Diagnostic, Debug, Error)]
pub enum AstError {
#[error("Unexpected end of input, expected {expected}")]
UnexpectedEof {
expected: String,
#[source_code]
src: String,
#[label = "input ends here"]
err_span: miette::SourceSpan,
},
#[error("Expected {expected}, found `{found:?}`")]
UnexpectedToken {
expected: String,
found: TokenKind,
#[source_code]
src: String,
#[label = "this token"]
err_span: miette::SourceSpan,
},
#[error("{message}")]
Custom {
message: String,
#[source_code]
src: String,
#[label = "{message}"]
err_span: miette::SourceSpan,
},
#[error("Lexer error: {0}")]
LexerError(LexError),
}
impl From<LexError> for AstError {
fn from(lex_err: LexError) -> Self {
AstError::LexerError(lex_err)
}
}