tokeniser: errors now print with SourceInfo if added

This commit is contained in:
2025-06-28 23:11:24 +01:00
parent b8be1bd95f
commit a65dca6c5c
+31 -1
View File
@@ -50,7 +50,34 @@ impl AssembleError {
return Ok(());
};
write!(f, "Parser error, {parse_error} at {source_info}")?;
writeln!(f, "Parser error, {parse_error} at {source_info}.")?;
// Prints out the context for our error.
source_info.print_context_with_underline().map_err(|e| {
_ = writeln!(f, "Print context error: {e}");
std::fmt::Error {}
})?;
Ok(())
}
/// Prints a tokeniser error to the screen.
fn print_tokeniser_error(
&self,
f: &mut std::fmt::Formatter<'_>,
err: &TokeniserError,
) -> std::fmt::Result {
let Some(source_info) = &self.source_info else {
write!(
f,
"Tokeniser error thrown with no source information. Error: {err}"
)?;
return Ok(());
};
writeln!(f, "Tokeniser error, {err} at {source_info}.")?;
// Prints out the context for our error.
source_info.print_context_with_underline().map_err(|e| {
@@ -70,6 +97,9 @@ impl Display for AssembleError {
match &self.kind {
AssembleErrorKind::Parser(err) => self.print_parser_error(f, err)?,
AssembleErrorKind::Tokeniser(err) => {
self.print_tokeniser_error(f, err)?;
}
_ => write!(f, "{}", self.kind)?,
}