Successfully passing state handle to pass functions
This commit is contained in:
parent
5abaadc0ca
commit
1f4228b887
@ -40,11 +40,11 @@ impl Schala {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tokenizing_stage(input: &str) -> Result<Vec<tokenizing::Token>, ()> {
|
fn tokenizing_stage(handle: &mut Schala, input: &str) -> Result<Vec<tokenizing::Token>, ()> {
|
||||||
Ok(tokenizing::tokenize(input))
|
Ok(tokenizing::tokenize(input))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parsing_stage(input: Vec<tokenizing::Token>) -> Result<parsing::AST, parsing::ParseError> {
|
fn parsing_stage(handle: &mut Schala, input: Vec<tokenizing::Token>) -> Result<parsing::AST, parsing::ParseError> {
|
||||||
parsing::parse(input).0
|
parsing::parse(input).0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,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![self, tokenizing_stage, parsing_stage];
|
let mut chain = pass_chain![self, tokenizing_stage, parsing_stage];
|
||||||
chain(input)
|
chain(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,8 +182,8 @@ pub trait ProgrammingLanguageInterface {
|
|||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! pass_chain {
|
macro_rules! pass_chain {
|
||||||
($self:expr, $($pass:path), *) => {
|
($state:expr, $($pass:path), *) => {
|
||||||
|text_input| { pass_chain_helper! { $self, text_input $(, $pass)* } }
|
|text_input| { pass_chain_helper! { $state, text_input $(, $pass)* } }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,13 +191,13 @@ macro_rules! pass_chain {
|
|||||||
//but should in the future return a FinishedComputation
|
//but should in the future return a FinishedComputation
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! pass_chain_helper {
|
macro_rules! pass_chain_helper {
|
||||||
($self:expr, $input:expr, $pass:path $(, $rest:path)*) => {
|
($state:expr, $input:expr, $pass:path $(, $rest:path)*) => {
|
||||||
{
|
{
|
||||||
let pass_name = stringify!($pass);
|
let pass_name = stringify!($pass);
|
||||||
println!("Running pass {}", pass_name);
|
println!("Running pass {}", pass_name);
|
||||||
let output = $pass($input);
|
let output = $pass($state, $input);
|
||||||
match output {
|
match output {
|
||||||
Ok(result) => pass_chain_helper! { $self, result $(, $rest)* },
|
Ok(result) => pass_chain_helper! { $state, result $(, $rest)* },
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let comp = UnfinishedComputation::default();
|
let comp = UnfinishedComputation::default();
|
||||||
comp.output(Err(format!("Pass {} failed with {:?}", pass_name, err)))
|
comp.output(Err(format!("Pass {} failed with {:?}", pass_name, err)))
|
||||||
@ -206,7 +206,7 @@ macro_rules! pass_chain_helper {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Done
|
// Done
|
||||||
($self:expr, $final_output:expr) => {
|
($state:expr, $final_output:expr) => {
|
||||||
{
|
{
|
||||||
let comp = UnfinishedComputation::default();
|
let comp = UnfinishedComputation::default();
|
||||||
let final_output: FinishedComputation = comp.output(Ok(format!("{:?}", $final_output)));
|
let final_output: FinishedComputation = comp.output(Ok(format!("{:?}", $final_output)));
|
||||||
|
Loading…
Reference in New Issue
Block a user