From a305610a394976aa30e4cc3c6c32ded45fc1b9af Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 29 Apr 2018 00:04:31 -0700 Subject: [PATCH] Some kind of pipeline working thanks to the rust syn crate guy for the macro idea --- schala-lang/src/lib.rs | 17 +++++++++++++++++ schala-repl/src/language.rs | 31 +++++++++++++++++++++++++++++++ schala-repl/src/lib.rs | 3 +++ 3 files changed, 51 insertions(+) diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index b948cd3..23083fe 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -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, ()> { + Ok(tokenizing::tokenize(input)) +} + +fn parsing_stage(input: Vec) -> Result { + 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!(); diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index c4d65e4..8fde299 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -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 }; +} diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index fc03bf9..772496f 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -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() }