use thiserror::Error;
#[derive(Error, Debug)]
pub enum ParserError {
#[error("Invalid magic bytes: expected 0x4A 0x58, got {0:02x} {1:02x}")]
InvalidMagic(u8, u8),
#[error("Unsupported version: {0}")]
UnsupportedVersion(u32),
#[error("Unexpected end of file at offset {0}")]
UnexpectedEof(usize),
#[error("Invalid token at offset {offset}: {message}")]
InvalidToken { offset: usize, message: String },
#[error("Parse error at offset {offset}: {message}")]
ParseError { offset: usize, message: String },
#[error("Invalid string index: {0}")]
InvalidStringIndex(usize),
#[error("Malformed structure: {0}")]
MalformedStructure(String),
#[error("IO error: {0}")]
IoError(String),
}
impl From<std::io::Error> for ParserError {
fn from(err: std::io::Error) -> Self {
ParserError::IoError(err.to_string())
}
}
pub type ParserResult<T> = Result<T, ParserError>;