Making pipeline macro nicer
This commit is contained in:
parent
a305610a39
commit
fd89de77cc
@ -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 {
|
||||||
|
@ -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 output = $next({
|
let pass_name = stringify!($pass);
|
||||||
let input = $e;
|
println!("Running pass {}", pass_name);
|
||||||
println!("About to run: {}", stringify!($next));
|
let output = $pass($input);
|
||||||
input
|
match output {
|
||||||
});
|
Ok(result) => pass_chain_helper! { result $(, $rest)* },
|
||||||
println!("Finished running {}", stringify!($next));
|
Err(err) => {
|
||||||
output.unwrap()
|
let comp = UnfinishedComputation::default();
|
||||||
|
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
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user