diff --git a/server/src/parsing.rs b/server/src/parsing.rs index bc27ed1..782aa5e 100644 --- a/server/src/parsing.rs +++ b/server/src/parsing.rs @@ -73,7 +73,7 @@ pub fn token_parse( // Identifier Some(tokenise::Token::Identifier(name)) => { - index = match identifier_parse::identifier_parse(index+1,name,tokens,&mut variables) + index = match identifier_parse::identifier_parse(index+1,name,tokens,&mut variables,rx,happening_queue) { Ok((increment,_)) => increment, Err((err,increment)) => diff --git a/server/src/parsing/identifier_parse.rs b/server/src/parsing/identifier_parse.rs index 2c0cea4..b0a430e 100644 --- a/server/src/parsing/identifier_parse.rs +++ b/server/src/parsing/identifier_parse.rs @@ -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, + rx: &Receiver<(usize,String)>, + happening_queue: &Arc>>, ) -> 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(¤t,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(¤t,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) diff --git a/server/src/parsing/keyword_parse.rs b/server/src/parsing/keyword_parse.rs index 545a170..3aca769 100644 --- a/server/src/parsing/keyword_parse.rs +++ b/server/src/parsing/keyword_parse.rs @@ -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>>,) --> Result, String> +pub fn choice_parse +( + tokens: &[tokenise::Token], + mut index: usize, + happening_queue: &Arc>>, + rx: &Receiver<(usize,String)>, +) +-> Result<(usize,String), String> { let mut next_token: String = "or".to_string(); let mut choices: Vec = 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())) } diff --git a/stories/characters.json b/stories/characters.json index 7d0549d..62f85f5 100644 --- a/stories/characters.json +++ b/stories/characters.json @@ -10,7 +10,7 @@ "pronoun_deppos": "His", "pronoun_indpos": "His", "pronoun_reflex": "Himself", - "head_shape": "", + "head_shape": "normal-male", "hair_style": "", "torso_shape": "", "arm_shape": "", diff --git a/stories/test.zip b/stories/test.zip index bb2c451..39ffe69 100644 Binary files a/stories/test.zip and b/stories/test.zip differ