Some kind of pipeline working

thanks to the rust syn crate guy for the macro idea
This commit is contained in:
greg 2018-04-29 00:04:31 -07:00
parent 14f31a5186
commit a305610a39
3 changed files with 51 additions and 0 deletions

View File

@ -6,6 +6,7 @@ extern crate lazy_static;
#[macro_use]
extern crate maplit;
#[macro_use]
extern crate schala_repl;
extern crate schala_codegen;
@ -39,6 +40,14 @@ impl Schala {
}
}
fn tokenizing_stage(input: &str) -> Result<Vec<tokenizing::Token>, ()> {
Ok(tokenizing::tokenize(input))
}
fn parsing_stage(input: Vec<tokenizing::Token>) -> Result<parsing::AST, parsing::ParseError> {
parsing::parse(input).0
}
impl ProgrammingLanguageInterface for Schala {
fn get_language_name(&self) -> String {
"Schala".to_string()
@ -48,6 +57,14 @@ impl ProgrammingLanguageInterface for Schala {
format!("schala")
}
fn execute_pipeline(&mut self, input: &str, options: &EvalOptions) -> FinishedComputation {
//let chain = pass_chain![tokenizing::tokenize, parsing::parse];
let chain = pass_chain![tokenizing_stage, parsing_stage];
let output = Ok(format!("{:?}", 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 {
schala_codegen::print_a_thing!();

View File

@ -163,6 +163,10 @@ pub trait ProgrammingLanguageInterface {
}
/* old */
fn execute_pipeline(&mut self, _input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
FinishedComputation { artifacts: HashMap::new(), text_output: Err(format!("Execution pipeline not done")) }
}
fn execute(&mut self, _input: &str, _eval_options: &EvalOptions) -> FinishedComputation {
FinishedComputation { artifacts: HashMap::new(), text_output: Err(format!("REPL evaluation not implemented")) }
}
@ -175,3 +179,30 @@ pub trait ProgrammingLanguageInterface {
format!(">> No custom interpreter directives specified <<")
}
}
#[macro_export]
macro_rules! pass_chain {
($($pass:path), *) => {
|begin| pass_chain_helper! { begin $(, $pass)* }
};
}
#[macro_export]
macro_rules! pass_chain_helper {
($e:expr, $next:path $(, $rest:path)*) => {
pass_chain_helper! {
{
let output = $next({
let input = $e;
println!("About to run: {}", stringify!($next));
input
});
println!("Finished running {}", stringify!($next));
output.unwrap()
}
$(, $rest)*
}
};
// Done
($e:expr) => { $e };
}

View File

@ -210,7 +210,10 @@ impl Repl {
fn input_handler(&mut self, input: &str) -> String {
let ref mut language = self.languages[self.current_language_index];
/*
let interpreter_output = language.execute(input, &self.options);
*/
let interpreter_output = language.execute_pipeline(input, &self.options);
interpreter_output.to_repl()
}