More boilerplate

This commit is contained in:
greg 2018-05-09 03:38:02 -07:00
parent 30128d7d34
commit 81368179bb
2 changed files with 27 additions and 3 deletions

View File

@ -320,7 +320,27 @@ impl<'a> State<'a> {
/* BELOW HERE NEW STUFF */
impl<'a> State<'a> {
pub fn evaluate_new(&mut self, input: ReducedAST) -> Result<String, String> {
Ok("not done".to_string())
pub fn evaluate_new(&mut self, ast: ReducedAST) -> Vec<Result<String, String>> {
use ast_reducing::*;
let mut acc = vec![];
for statement in ast.0 {
match self.eval_statement_new(statement) {
Ok(output) => {
if let Some(fully_evaluated) = output {
acc.push(Ok(fully_evaluated/*.to_string()*/));
}
},
Err(error) => {
acc.push(Err(format!("Eval error: {}", error)));
return acc;
},
}
}
acc
}
fn eval_statement_new(&mut self, stmt: ::ast_reducing::Stmt) -> Result<Option<String>, String> {
Ok(Some(format!("stmt - {:?}", stmt)))
}
}

View File

@ -102,7 +102,11 @@ fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi
fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut UnfinishedComputation>) -> Result<String, String> {
let new_input = input.0;
let _new_eval_output = handle.state.evaluate_new(new_input);
let new_eval_output = handle.state.evaluate_new(new_input);
match new_eval_output[0] {
Ok(ref s) => println!("NEW OUTPUT> {}", s),
Err(ref e) => println!("NEW ERR> {}", e),
}
/* old-style eval */
let input = input.1;