//! This module contains the error types for the tokeniser. #[derive(Debug, Clone, Copy)] /// 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 { 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(()) } }