diff --git a/.~lock.report.odt# b/.~lock.report.odt# index 5578e24..76dbfef 100644 --- a/.~lock.report.odt# +++ b/.~lock.report.odt# @@ -1 +1 @@ -,deadvey,linux-pc,30.04.2026 12:49,file:///home/deadvey/.config/libreoffice/4; \ No newline at end of file +,deadvey,linux-pc,03.05.2026 02:13,file:///home/deadvey/.config/libreoffice/4; \ No newline at end of file diff --git a/report.odt b/report.odt index ea7d361..dc19a13 100644 Binary files a/report.odt and b/report.odt differ diff --git a/src/.api.rs.swp b/src/.api.rs.swp deleted file mode 100644 index 3d6394f..0000000 Binary files a/src/.api.rs.swp and /dev/null differ diff --git a/src/.character.rs.swp b/src/.parsing.rs.swp similarity index 65% rename from src/.character.rs.swp rename to src/.parsing.rs.swp index 7741b8f..9ef50d4 100644 Binary files a/src/.character.rs.swp and b/src/.parsing.rs.swp differ diff --git a/src/parsing.rs b/src/parsing.rs index 5647891..21a84b1 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -12,6 +12,7 @@ use crate:: Mutex, info, debug, + warn, }; @@ -19,7 +20,7 @@ use crate:: // Returns success or an error string pub async fn token_parse( tokens: &Vec<&str>, - mut characters: Arc>>, + characters: Arc>>, data_to_send: Arc>, rx: &Receiver, ) -> Result<(),String> @@ -44,7 +45,7 @@ pub async fn token_parse( let character_name: String = token.chars().skip(1).collect(); info!("Doing something with a character: {}", character_name); // The index is incremented to after the character's instructions - index += match character_parse(index+1, &tokens, character_name, &characters, &data_to_send, &rx).await + index += match character_parse(index+1, &tokens, character_name, &characters, &data_to_send).await { Ok(increment) => increment, Err(error) => return Err(error), @@ -52,14 +53,48 @@ pub async fn token_parse( continue } // Miscelleneous instructions - if token.to_lowercase() == "end" + match token.to_lowercase().as_str() { - info!("END command, exiting"); - return Ok(()) // quit + "end" => + { + info!("END command, exiting"); + return Ok(()) // quit + }, + "choice" => + { + index += match choice_parse(index+1, &tokens).await + { + Ok(increment) => increment, + Err(error) => return Err(error), + } + } + _ => + { + warn!("Invalid command: {}", token); + } } index += 1; } } + +// TODO underdev +async fn choice_parse +( + index: usize, + tokens: &Vec<&str>, +) -> Result +{ + let mut sum_index: usize = index; + let mut choices: Vec = Vec::new(); + // Ensure the index is valid (the index is not beyond the vector) + let (choice_string, counter) = strings::extract_quoted(&tokens[sum_index..]) + .ok_or_else(|| "No choice string".to_string())?; + sum_index += counter; + choices.append(choice_string); + sum_index += strings::closing_char(&tokens[sum_index..], '{','}').unwrap(); //TODO eh + Ok(sum_index + 1) +} + // Parsing character related instructions async fn character_parse ( @@ -68,7 +103,6 @@ async fn character_parse character_name: String, characters: &Arc>>, data_to_send: &Arc>, - rx: &Receiver, ) -> Result { let mut sum_index: usize = index; diff --git a/src/parsing/strings.rs b/src/parsing/strings.rs index c6b1053..a3d0085 100644 --- a/src/parsing/strings.rs +++ b/src/parsing/strings.rs @@ -1,4 +1,18 @@ -pub fn extract_quoted(parts: &[&str]) -> Option<(String, usize)> { +pub fn closing_char(parts: &[&str], open: char, close: char) +-> Result +{ + let mut indentation: usize = 0; + for (index, part) in parts.into_iter().enumerate() + { + if part.contains(open) { indentation += 1; } + if part.contains(close) { indentation -= 1; } + if indentation == 0 { return Ok(index); } + } + Err(()) +} +pub fn extract_quoted(parts: &[&str]) +-> Option<(String, usize)> +{ let mut vec_string = Vec::new(); let mut counter: usize = 0; for part in parts diff --git a/stories/story.ha b/stories/story.ha index 5ce98b6..a8799fb 100644 --- a/stories/story.ha +++ b/stories/story.ha @@ -1,2 +1,8 @@ @tim says "hello world, it's a good day" +choice "choice numero uno" { + @tim says "super sad" +} +or "choice numero duo" { + @tim says "super unsad" +} END