From 192f077c62b1659be1adbcfeee8b88ebed9f964f Mon Sep 17 00:00:00 2001 From: Ivan Gromov Date: Tue, 3 Oct 2023 21:13:41 +0100 Subject: [PATCH] print errors in interactive mode --- src/interpreter.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index f673140..2dc8060 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -11,6 +11,7 @@ use crate::ast::expr::ExprType; use crate::ast::expr::UnaryOp; use crate::ast::visitor::StatementVisitor; use crate::ast::{Expr, Visitor}; +use crate::error; use crate::error::LoxError; use crate::error::LoxErrorKind; use crate::position::PositionRange; @@ -210,7 +211,6 @@ impl StatementVisitor for Interpreter<'_> { } ast::Statement::Print { expr, position: _ } => { let value = self.visit_expr(expr)?; - println!("{}", value); writeln!(self.stdout, "{}", value); } ast::Statement::Var { @@ -270,7 +270,15 @@ pub fn run_prompt() -> Result<(), Box> { if r == 0 { return Ok(()); } - run(&buffer); + let result = run(&buffer); + match result { + Err(errors) => { + for error in errors { + println!("Error at ({}, {}): {}", error.position.start.line, error.position.start.column, error.message); + } + } + _ => (), + } } }