use crate::ast::Span;
#[derive(Debug, Clone, PartialEq)]
pub enum ParseErrorCode {
NotUtf8,
InvalidKdl,
MissingZenithRoot,
UnexpectedNode,
InvalidPropertyValue,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ParseError {
pub span: Option<Span>,
pub code: ParseErrorCode,
pub message: String,
}
impl ParseError {
pub fn spanless(code: ParseErrorCode, message: impl Into<String>) -> Self {
Self {
span: None,
code,
message: message.into(),
}
}
pub fn with_span(code: ParseErrorCode, span: Span, message: impl Into<String>) -> Self {
Self {
span: Some(span),
code,
message: message.into(),
}
}
}
impl std::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for ParseError {}
#[derive(Debug, Clone, PartialEq)]
pub struct FormatError {
pub message: String,
}
impl FormatError {
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
}
impl std::fmt::Display for FormatError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for FormatError {}