Make eval output nicer
This commit is contained in:
parent
f6536e7ebd
commit
6435d5e958
@ -19,23 +19,22 @@ impl ReplState {
|
|||||||
ReplState { }
|
ReplState { }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evaluate(&mut self, ast: AST) -> String {
|
pub fn evaluate(&mut self, ast: AST) -> Vec<String> {
|
||||||
let mut acc = String::new();
|
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(s) = output {
|
if let Some(s) = output {
|
||||||
acc.push_str(&s);
|
acc.push(s);
|
||||||
acc.push_str("\n");
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
acc.push_str(&format!("Error: {}", error));
|
acc.push(format!("Error: {}", error));
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
format!("{}", acc)
|
acc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,16 @@ impl ProgrammingLanguageInterface for Schala {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let evaluation_output = self.state.evaluate(ast);
|
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;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user