mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-14 17:35:03 +01:00
nice errors
This commit is contained in:
parent
bea961bbbd
commit
40a7aaac71
5 changed files with 181 additions and 43 deletions
24
src/lib.rs
24
src/lib.rs
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue