Better error handling in REPL
We have much better spanned expression support, so now we get to show it off!
This commit is contained in:
parent
a0c1f93392
commit
dc5ef63fef
38
src/repl.rs
38
src/repl.rs
|
@ -15,27 +15,25 @@ pub fn repl() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let mut parser = Parser::new(&line);
|
let mut parser = Parser::new(&line);
|
||||||
let ast = parser.init();
|
let value = parser.init().and_then(|ast| {
|
||||||
match ast {
|
println!("{:?}", &ast);
|
||||||
Ok(ast) => {
|
env.eval_stmts(&ast)
|
||||||
println!("{:?}", ast);
|
});
|
||||||
println!("{:?}", env.eval_stmts(&ast));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!(
|
|
||||||
"Error `{:?}` occurred at span: {:?} = `{:?}`",
|
|
||||||
e.kind,
|
|
||||||
e.span.clone(),
|
|
||||||
line.slice(e.span.clone())
|
|
||||||
);
|
|
||||||
|
|
||||||
println!(" | {}", line);
|
if let Err(e) = value {
|
||||||
println!(
|
println!(
|
||||||
" {}{}-- Here",
|
"Error `{:?}` occurred at span: {:?} = `{:?}`",
|
||||||
" ".repeat(e.span.start),
|
e.kind,
|
||||||
"^".repeat((e.span.end - e.span.start).max(1))
|
e.span.clone(),
|
||||||
);
|
line.slice(e.span.clone())
|
||||||
}
|
);
|
||||||
|
|
||||||
|
println!(" | {}", line);
|
||||||
|
println!(
|
||||||
|
" {}{}-- Here",
|
||||||
|
" ".repeat(e.span.start),
|
||||||
|
"^".repeat((e.span.end - e.span.start).max(1))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(rustyline::error::ReadlineError::Eof) => {
|
Err(rustyline::error::ReadlineError::Eof) => {
|
||||||
|
|
Loading…
Reference in a new issue