nice errors

This commit is contained in:
nora 2021-10-07 22:15:10 +02:00
parent bea961bbbd
commit 40a7aaac71
5 changed files with 181 additions and 43 deletions

View file

@ -1,15 +1,25 @@
mod alloc;
mod errors;
mod lex;
mod parse;
pub fn run_program(program: &str) {
let lexer = lex::Lexer::lex(program);
let tokens: Result<Vec<_>, _> = lexer.collect();
println!(
"{:#?}",
tokens.map(|tokens| tokens
let (success, errors) = lexer.partition::<Vec<_>, _>(|result| result.is_ok());
if errors.is_empty() {
println!(
"{:#?}",
success
.into_iter()
.map(Result::unwrap)
.map(|token| token.kind)
.collect::<Vec<_>>()
);
} else {
errors
.into_iter()
.map(|token| token.kind)
.collect::<Vec<_>>())
);
.map(Result::unwrap_err)
.for_each(|err| crate::errors::display_error(program, err));
}
}