From 6435d5e9580f8e0ffbd2514f8f350fb0042c98d7 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 1 Oct 2017 19:29:05 -0700 Subject: [PATCH] Make eval output nicer --- src/schala_lang/eval.rs | 11 +++++------ src/schala_lang/mod.rs | 11 ++++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/schala_lang/eval.rs b/src/schala_lang/eval.rs index 8b597e3..e3fc3b4 100644 --- a/src/schala_lang/eval.rs +++ b/src/schala_lang/eval.rs @@ -19,23 +19,22 @@ impl ReplState { ReplState { } } - pub fn evaluate(&mut self, ast: AST) -> String { - let mut acc = String::new(); + pub fn evaluate(&mut self, ast: AST) -> Vec { + let mut acc = vec![]; for statement in ast.0 { match self.eval_statement(statement) { Ok(output) => { if let Some(s) = output { - acc.push_str(&s); - acc.push_str("\n"); + acc.push(s); } }, Err(error) => { - acc.push_str(&format!("Error: {}", error)); + acc.push(format!("Error: {}", error)); return acc; }, } } - format!("{}", acc) + acc } } diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index a8c69ea..7a24cb8 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -65,7 +65,16 @@ impl ProgrammingLanguageInterface for Schala { } let evaluation_output = self.state.evaluate(ast); - output.add_output(evaluation_output); + let mut acc = String::new(); + let mut iter = evaluation_output.iter().peekable(); + while let Some(s) = iter.next() { + acc.push_str(&s); + if let Some(_) = iter.peek() { + acc.push_str("\n"); + } + } + + output.add_output(acc); return output; } }