Skip to content

Commit

Permalink
print errors in interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lgyanf committed Oct 3, 2023
1 parent be282ed commit 192f077
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -270,7 +270,15 @@ pub fn run_prompt() -> Result<(), Box<dyn Error>> {
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);
}
}
_ => (),
}
}
}

Expand Down

0 comments on commit 192f077

Please sign in to comment.