From 923566c4e924816b522100d44fc6b5f2466918fa Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 21 Dec 2016 23:29:14 -0800 Subject: [PATCH] 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 --- src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 30c2699..4d2264a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = 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 }