Added support for assigning variables to the output of a choice
This commit is contained in:
@@ -30,18 +30,7 @@ pub fn keyword_parse(
|
||||
{
|
||||
"choice" =>
|
||||
{
|
||||
let choice_indeces = choice_parse(tokens, index, happening_queue)?;
|
||||
debug!("{choice_indeces:?}");
|
||||
let choice = match rx.recv()
|
||||
{
|
||||
Ok((choice,_)) => choice_indeces[choice],
|
||||
Err(err) =>
|
||||
{
|
||||
warn!("Error receiving choice from client, defaulting to choice 0 {err}");
|
||||
0
|
||||
}
|
||||
};
|
||||
index = choice;
|
||||
(index,_) = choice_parse(tokens, index, happening_queue, rx)?;
|
||||
},
|
||||
"if" =>
|
||||
{
|
||||
@@ -54,7 +43,7 @@ pub fn keyword_parse(
|
||||
if keyword != "else"
|
||||
{
|
||||
let identifier = tokenise::get_identifier_token(tokens, index)?;
|
||||
(index,result) = match identifier_parse::identifier_parse(index+1, &identifier, tokens, variables)
|
||||
(index,result) = match identifier_parse::identifier_parse(index+1, &identifier, tokens, variables,rx,happening_queue)
|
||||
{
|
||||
Ok((increment, result)) => (increment,result),
|
||||
Err((err,increment)) =>
|
||||
@@ -119,8 +108,14 @@ pub fn keyword_parse(
|
||||
Ok(index)
|
||||
}
|
||||
|
||||
fn choice_parse(tokens: &[tokenise::Token], mut index: usize, happening_queue: &Arc<Mutex<VecDeque<api::DataToSend>>>,)
|
||||
-> Result<Vec<usize>, String>
|
||||
pub fn choice_parse
|
||||
(
|
||||
tokens: &[tokenise::Token],
|
||||
mut index: usize,
|
||||
happening_queue: &Arc<Mutex<VecDeque<api::DataToSend>>>,
|
||||
rx: &Receiver<(usize,String)>,
|
||||
)
|
||||
-> Result<(usize,String), String>
|
||||
{
|
||||
let mut next_token: String = "or".to_string();
|
||||
let mut choices: Vec<String> = Vec::new();
|
||||
@@ -145,6 +140,16 @@ fn choice_parse(tokens: &[tokenise::Token], mut index: usize, happening_queue: &
|
||||
Err(_) => break,
|
||||
}
|
||||
};
|
||||
api::modify_data(happening_queue, "choice".to_string(), String::new(), String::new(), choices);
|
||||
Ok(choice_indeces)
|
||||
api::modify_data(happening_queue, "choice".to_string(), String::new(), String::new(), choices.clone());
|
||||
debug!("{choice_indeces:?}");
|
||||
let choice = match rx.recv()
|
||||
{
|
||||
Ok((choice,_)) => choice,
|
||||
Err(err) =>
|
||||
{
|
||||
warn!("Error receiving choice from client, defaulting to choice 0 {err}");
|
||||
0
|
||||
}
|
||||
};
|
||||
Ok((choice_indeces[choice],choices[choice].clone()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user