Show err output when evaluating non-interactively

This commit is contained in:
greg 2018-03-24 17:27:54 -07:00
parent ebda79e5fd
commit 78f12c8f1d
3 changed files with 13 additions and 5 deletions

View File

@ -102,17 +102,17 @@ impl<'a> State<'a> {
State { parent_frame: Some(parent), values: HashMap::new() }
}
pub fn evaluate(&mut self, ast: AST) -> Vec<String> {
pub fn evaluate(&mut self, ast: AST) -> Vec<Result<String, String>> {
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;
},
}

View File

@ -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<Vec<String>, String> = evaluation_outputs
.into_iter()
.collect();
let eval_output = text_output
.map(|v| { v.into_iter().intersperse(format!("\n")).collect() });
evaluation.output(eval_output)
}
}

View File

@ -4,6 +4,9 @@ fn main() {
a + b
}
foo
print(main())