Error messages

master
Araozu 2023-03-03 09:23:08 -05:00
parent 1b9a3377cb
commit a88c8e9216
3 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1 @@
val identifier = 322

View File

@ -14,11 +14,12 @@ impl PrintableError for LexError {
let whitespace = whitespace.iter().collect::<String>();
format!(
"\n{}\n{}^\n\n{}{}",
"\n{}\n{}^\n\n{}{}\n{}",
erroneous_code,
whitespace,
"Invalid character at pos ",
self.position + 1,
self.reason,
)
}
}

View File

@ -85,7 +85,11 @@ fn next_token(chars: &Chars, current_pos: usize) -> LexResult {
.unwrap_or_else(|| {
let error = LexError {
position: current_pos,
reason: format!("Unrecognized character: {}", next_char),
reason: format!(
"Unrecognized character `{}` (escaped: `{}`)",
next_char,
next_char.escape_default().to_string(),
),
};
LexResult::Err(error)
})