From 32952421157ec2e3fbfe84f29663085c02a0c9d3 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 24 Mar 2018 17:27:54 -0700 Subject: [PATCH] Show err output when evaluating non-interactively --- schala-lang/src/eval.rs | 6 +++--- schala-lang/src/lib.rs | 9 +++++++-- source_files/schala/first.schala | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 44bcca0..0dab7d0 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -102,17 +102,17 @@ impl<'a> State<'a> { State { parent_frame: Some(parent), values: HashMap::new() } } - pub fn evaluate(&mut self, ast: AST) -> Vec { + 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(fully_evaluated) = output { - acc.push(fully_evaluated.to_string()); + acc.push(Ok(fully_evaluated.to_string())); } }, Err(error) => { - acc.push(format!("Eval error: {}", error)); + acc.push(Err(format!("Eval error: {}", error))); return acc; }, } diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index e4fc19c..ca006a5 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -107,7 +107,12 @@ impl ProgrammingLanguageInterface for Schala { } let evaluation_outputs = self.state.evaluate(ast); - let text_output: String = evaluation_outputs.into_iter().intersperse(format!("\n")).collect(); - evaluation.output(Ok(text_output)) + let text_output: Result, String> = evaluation_outputs + .into_iter() + .collect(); + + let eval_output = text_output + .map(|v| { v.into_iter().intersperse(format!("\n")).collect() }); + evaluation.output(eval_output) } } diff --git a/source_files/schala/first.schala b/source_files/schala/first.schala index aeecf97..a8cca94 100644 --- a/source_files/schala/first.schala +++ b/source_files/schala/first.schala @@ -4,6 +4,9 @@ fn main() { a + b } +foo + print(main()) +