mod fmt;
use super::SourcePos;
#[derive(Debug)]
pub enum ErrorKind {
UnexpectedEof,
Unexpected(u8),
EmptyByteLiteral,
InvalidEscapeSequence(Box<[u8]>),
InvalidNumber(Box<[u8]>),
InvalidIdentifier(Box<[u8]>),
}
#[derive(Debug)]
pub struct Error {
pub error: ErrorKind,
pub pos: SourcePos,
}
impl std::error::Error for Error {}
impl Error {
pub fn unexpected_eof(pos: SourcePos) -> Self {
Self { error: ErrorKind::UnexpectedEof, pos }
}
pub fn unexpected(input: u8, pos: SourcePos) -> Self {
Self { error: ErrorKind::Unexpected(input), pos }
}
pub fn empty_byte_literal(pos: SourcePos) -> Self {
Self { error: ErrorKind::EmptyByteLiteral, pos }
}
pub fn invalid_escape_sequence(sequence: &[u8], pos: SourcePos) -> Self {
Self {
error: ErrorKind::InvalidEscapeSequence(sequence.into()),
pos,
}
}
pub fn invalid_number(number: &[u8], pos: SourcePos) -> Self {
Self {
error: ErrorKind::InvalidNumber(number.into()),
pos,
}
}
pub fn invalid_identifier(ident: &[u8], pos: SourcePos) -> Self {
Self {
error: ErrorKind::InvalidIdentifier(ident.into()),
pos,
}
}
}