Get rid of println's for token/ast debugging

Instead just explicitly stick them into the returned string.

This is necessary 'cause I'm gonna convert simplerepl to use ncurses
soon, so I can't have any side effects
This commit is contained in:
greg 2016-12-21 23:29:14 -08:00
parent 96c51a9b88
commit 923566c4e9
1 changed files with 7 additions and 3 deletions

View File

@ -95,13 +95,15 @@ impl ReplState for InterpreterState {
}
fn repl_handler(input: &str, state: &mut InterpreterState) -> String {
let mut result = String::new();
let tokens = match tokenize(input) {
None => return format!("Tokenization error"),
Some(t) => t
};
if state.show_tokens {
println!("Tokens: {:?}", tokens);
result.push_str(&format!("Tokens: {:?}\n", tokens));
}
let ast = match parse(&tokens, &[]) {
@ -110,11 +112,13 @@ fn repl_handler(input: &str, state: &mut InterpreterState) -> String {
};
if state.show_parse {
println!("AST: {:?}", ast);
result.push_str(&format!("AST: {:?}\n", ast));
}
let mut output: Vec<String> = state.evaluator.run(ast);
//for now only handle last output
output.pop().unwrap_or("".to_string())
let interpreter_result = output.pop().unwrap_or("".to_string());
result.push_str(&interpreter_result);
result
}