Added support for assigning variables to the output of a choice

This commit is contained in:
2026-05-26 17:48:36 +01:00
parent 59f32e975b
commit f6a95f76bd
5 changed files with 61 additions and 27 deletions
+37 -8
View File
@@ -2,11 +2,17 @@ use crate::
{
// Internal code
tokenise,
api,
//Libs
HashMap,
Arc,
Mutex,
VecDeque,
warn,
debug,
mpsc::Receiver,
};
use super::keyword_parse;
#[allow(unused_variables)]
pub fn identifier_parse
@@ -15,6 +21,8 @@ pub fn identifier_parse
identifier: &String,
tokens: &[tokenise::Token],
variables: &mut HashMap<String, tokenise::Value>,
rx: &Receiver<(usize,String)>,
happening_queue: &Arc<Mutex<VecDeque<api::DataToSend>>>,
) -> Result<(usize,bool),(String,usize)>
{
let mut sum_index: usize = index;
@@ -27,12 +35,35 @@ pub fn identifier_parse
sum_index += 1;
let result: bool = match tokenise::get_value_token(tokens, sum_index)
{
Ok(value) => operator_match(&current,value,operator,identifier,variables),
Err(_) => todo!(),
// An value that can be directly assigned to or compared against the variable
Ok(value) =>
{
sum_index += 1;
operator_match(&current,value,operator,identifier,variables)
},
// Another thing like a choice or an input
Err(_) =>
{
let keyword = tokenise::get_keyword_token(tokens,sum_index)
.map_err(|err| (err,sum_index))?;
match keyword.to_lowercase().as_str()
{
"choice" =>
{
let choice: String;
(sum_index, choice) = keyword_parse::choice_parse(tokens, index+1, happening_queue,rx)
.map_err(|err| (err,sum_index+1))?;
variables.insert(identifier.to_owned(), tokenise::Value::String(choice));
}
_ =>
{
warn!("Unexpected keyword {keyword}");
},
}
false
},
};
sum_index += 1;
debug!("{variables:?}");
Ok((sum_index,result))
}
@@ -75,9 +106,7 @@ fn operator_match
};
variables.insert(identifier.to_owned(), result);
},
// TODO choice assignment
// TODO input assignment
// TODO comparisons :DDD
// Comparisons, return a boolean
tokenise::Operator::Comparison(comp) =>
{
let result = match (current, &value)