Make eval output nicer
This commit is contained in:
parent
f6536e7ebd
commit
6435d5e958
@ -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<String> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user