Make eval output nicer

This commit is contained in:
greg 2017-10-01 19:29:05 -07:00
parent f6536e7ebd
commit 6435d5e958
2 changed files with 15 additions and 7 deletions

View File

@ -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
}
}

View File

@ -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;
}
}