tokeniser: add some actual tokeniser errors

TODO: Return these lol
This commit is contained in:
2025-06-28 23:05:07 +01:00
parent f42c6d4095
commit b8be1bd95f
+23 -2
View File
@@ -1,12 +1,33 @@
//! This module contains the error types for the tokeniser.
#[derive(Debug, Clone, Copy)]
pub enum TokeniserError {}
/// Types of errors that may be returned during tokenisation.
pub enum TokeniserError {
/// An unexpected character was found in the source code.
UnexpectedChar(char),
/// An unterminated string literal was found. [`SourceInfo`] will be attached if this
/// was returned.
UnterminatedString,
/// An invalid number format was encountered when parsing a literal value
/// ([`TokenType::Immediate`]).
InvalidNumber(&'static str),
/// An unrecognized token was encountered.
UnrecognisedToken,
}
impl TokeniserError {}
impl std::fmt::Display for TokeniserError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "TODO!!!!!!")
match self {
Self::UnexpectedChar(c) => write!(f, "unexpected char '{c}' found in input")?,
Self::InvalidNumber(lit) => {
write!(f, "invalid integer literal \"{lit}\" found in input")?;
}
&Self::UnrecognisedToken => write!(f, "unrecognised token found in input")?,
&Self::UnterminatedString => write!(f, "unterminated string literal")?,
}
Ok(())
}
}