Making pipeline macro nicer

This commit is contained in:
greg 2018-04-29 00:55:39 -07:00
parent a305610a39
commit fd89de77cc
2 changed files with 22 additions and 16 deletions

View File

@ -60,9 +60,7 @@ impl ProgrammingLanguageInterface for Schala {
fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation { fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation {
//let chain = pass_chain![tokenizing::tokenize, parsing::parse]; //let chain = pass_chain![tokenizing::tokenize, parsing::parse];
let chain = pass_chain![tokenizing_stage, parsing_stage]; let chain = pass_chain![tokenizing_stage, parsing_stage];
let output = Ok(format!("{:?}", chain(input))); chain(input)
let mut evaluation = UnfinishedComputation::default();
evaluation.output(output) //TODO rename this method it's confusing
} }
fn execute(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation { fn execute(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation {

View File

@ -183,26 +183,34 @@ pub trait ProgrammingLanguageInterface {
#[macro_export] #[macro_export]
macro_rules! pass_chain { macro_rules! pass_chain {
($($pass:path), *) => { ($($pass:path), *) => {
|begin| pass_chain_helper! { begin $(, $pass)* } |text_input| { pass_chain_helper! { text_input $(, $pass)* } }
}; };
} }
//generates a function resulting in (for now) the return type of the last one
//but should in the future return a FinishedComputation
#[macro_export] #[macro_export]
macro_rules! pass_chain_helper { macro_rules! pass_chain_helper {
($e:expr, $next:path $(, $rest:path)*) => { ($input:expr, $pass:path $(, $rest:path)*) => {
pass_chain_helper! { {
{ let pass_name = stringify!($pass);
let output = $next({ println!("Running pass {}", pass_name);
let input = $e; let output = $pass($input);
println!("About to run: {}", stringify!($next)); match output {
input Ok(result) => pass_chain_helper! { result $(, $rest)* },
}); Err(err) => {
println!("Finished running {}", stringify!($next)); let comp = UnfinishedComputation::default();
output.unwrap() comp.output(Err(format!("Pass {} failed with {:?}", pass_name, err)))
}
} }
$(, $rest)*
} }
}; };
// Done // Done
($e:expr) => { $e }; ($final_output:expr) => {
{
let comp = UnfinishedComputation::default();
let final_output: FinishedComputation = comp.output(Ok(format!("{:?}", $final_output)));
final_output
}
};
} }