From 6c2d5cc84acba7b7cfe6f40edbd1921002dd17c1 Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Fri, 4 Jun 2021 18:56:26 -0500 Subject: [PATCH] Prettier error handling --- src/repl.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/repl.rs b/src/repl.rs index a442a97..00a9c89 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -20,13 +20,20 @@ pub fn repl() { Ok(ast) => { println!("{:?}", ast); println!("{:?}", env.eval_items(&ast)); - }, + } Err(e) => { println!( "Error `{:?}` occured at span: {:?} = `{:?}`", e.kind, e.position.clone(), - line.slice(e.position) + line.slice(e.position.clone()) + ); + + println!(" | {}", line); + println!( + " {}{}-- Here", + " ".repeat(e.position.start), + "^".repeat((e.position.end - e.position.start).max(1)) ); } }