aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2024-03-28 21:53:53 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2024-03-28 21:53:53 +1300
commitcda07006720dc53367d0a552aa2c77796825f82d (patch)
tree00c155cbf3815350c8edf7825ad54a0dc6cb5153
parent8e33cc5dae9abbbf3e7a0371fcdc98f699481c1b (diff)
Implement fully-random category option
-rw-r--r--README.md12
-rw-r--r--src/main.rs8
-rw-r--r--test_data/sentences.txt2
3 files changed, 16 insertions, 6 deletions
diff --git a/README.md b/README.md
index b8b8cbe..467d786 100644
--- a/README.md
+++ b/README.md
@@ -31,6 +31,7 @@ Between these markers is some kind of definition of how the gap should be filled
```
Direct: %%foo%% - choose a word from the 'foo' category
+Random: %%?%% - choose a word from any category
Variable: %%?foo%% - choose a word from the category assigned to the 'foo' variable
Multiple: %%foo|bar%% - choose a word from either the 'foo' or 'bar' category
```
@@ -74,13 +75,14 @@ I think %%bar%% is kind of lame.
%%foo%% is certainly better than %%bar%%.
I would take %%foo|baz%% over %%bar%% any day.
%%?x%% and %%?x%% are certainly things that exist.
+%%?%%: kid tested, mother approved.
```
## Planned features / TODO
-* [ ] Re-implement argument parsing without `clap`
-* [ ] Special variable syntax for picking from a category but not saving it: `%%?%%`
-* [ ] Special syntax to choose between literal values rather than a category
-* [ ] Back-reference system to capture and repeat generated phrases
-* [ ] Learn how Markov chains work
+* Re-implement argument parsing without `clap`
+* ~~Special variable syntax for picking from a category but not saving it: `%%?%%`~~
+* Special syntax to choose between literal values rather than a category
+* Back-reference system to capture and repeat generated phrases
+* Learn how Markov chains work
diff --git a/src/main.rs b/src/main.rs
index 2fe5a26..4f299d4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -79,6 +79,7 @@ struct Args {
#[derive(Debug, Clone)]
enum DropIn {
+ Any,
Basic(String),
Var(String),
OneOf(Vec<DropIn>),
@@ -90,6 +91,10 @@ impl DropIn {
return Err(Error::EmptyOption)
}
+ if text == "?" {
+ return Ok(DropIn::Any);
+ }
+
if text.contains('|') {
let mut option_strs = text.split('|').collect::<Vec<&str>>();
option_strs.dedup();
@@ -166,6 +171,9 @@ impl CategorySet {
DropIn::OneOf(_) => {
panic!("Nested OneOf constructs are not supported")
},
+ DropIn::Any => {
+ self.random_category()?
+ },
};
let words = self.categories.get_mut(&category)
diff --git a/test_data/sentences.txt b/test_data/sentences.txt
index 1538972..5933427 100644
--- a/test_data/sentences.txt
+++ b/test_data/sentences.txt
@@ -11,4 +11,4 @@ This sentence uses type c, then a variable named 'c': %%c%% %%?c%%
This sentence uses 10 identical variables: %%?x%% %%?x%% %%?x%% %%?x%% %%?x%% %%?x%% %%?x%% %%?x%% %%?x%% %%?x%%
This sentence uses either type a or b: %%a|b%%
This sentence uses a variable, then either type a or the same variable: %%?x%% %%a|?x%%
-malformed sentence %%a||d%%
+This sentence uses four completely random types: %%?%% %%?%% %%?%% %%?%%