Show err output when evaluating non-interactively
This commit is contained in:
parent
ebda79e5fd
commit
78f12c8f1d
@ -102,17 +102,17 @@ impl<'a> State<'a> {
|
|||||||
State { parent_frame: Some(parent), values: HashMap::new() }
|
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![];
|
let mut acc = vec![];
|
||||||
for statement in ast.0 {
|
for statement in ast.0 {
|
||||||
match self.eval_statement(statement) {
|
match self.eval_statement(statement) {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
if let Some(fully_evaluated) = output {
|
if let Some(fully_evaluated) = output {
|
||||||
acc.push(fully_evaluated.to_string());
|
acc.push(Ok(fully_evaluated.to_string()));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
acc.push(format!("Eval error: {}", error));
|
acc.push(Err(format!("Eval error: {}", error)));
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,12 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let evaluation_outputs = self.state.evaluate(ast);
|
let evaluation_outputs = self.state.evaluate(ast);
|
||||||
let text_output: String = evaluation_outputs.into_iter().intersperse(format!("\n")).collect();
|
let text_output: Result<Vec<String>, String> = evaluation_outputs
|
||||||
evaluation.output(Ok(text_output))
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let eval_output = text_output
|
||||||
|
.map(|v| { v.into_iter().intersperse(format!("\n")).collect() });
|
||||||
|
evaluation.output(eval_output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ fn main() {
|
|||||||
a + b
|
a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foo
|
||||||
|
|
||||||
print(main())
|
print(main())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user