tokeniser: errors now print with SourceInfo if added
This commit is contained in:
+31
-1
@@ -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)?,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user