aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs19
-rw-r--r--test_data/sentences.txt2
2 files changed, 21 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index a96f1a5..2d7c335 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -75,6 +75,7 @@ type ProgResult<T> = Result<T, Error>;
#[derive(Debug, Clone)]
enum DropIn {
Any,
+ Literal(String),
Basic(String),
Var(String),
OneOf(Vec<DropIn>),
@@ -99,6 +100,16 @@ impl DropIn {
return Ok(DropIn::OneOf(options))
}
+ // TODO: investigate viability of supporting escape sequences
+ if let Some(inner) = text.strip_prefix('"')
+ .and_then(|s| s.strip_suffix('"'))
+ {
+ // REVIEW: investigate interactions of filenames that contain '"'
+ if !inner.contains('"') {
+ return Ok(DropIn::Literal(inner.to_string()));
+ }
+ }
+
if let Some(var_name) = text.strip_prefix('?') {
return Ok(DropIn::Var(var_name.to_string()));
}
@@ -149,6 +160,10 @@ impl CategorySet {
}
pub fn random_from_drop_in(&mut self, drop_in: &DropIn) -> ProgResult<String> {
+ if let DropIn::Literal(s) = drop_in {
+ return Ok(s.clone());
+ }
+
let simple_di = if let DropIn::OneOf(ds) = drop_in {
ds.choose(&mut thread_rng())
.expect("got a OneOf that is empty, somehow")
@@ -157,6 +172,9 @@ impl CategorySet {
};
let category = match simple_di {
+ DropIn::Literal(s) => {
+ return Ok(s.clone());
+ },
DropIn::Basic(s) => {
OsString::from(s)
},
@@ -280,6 +298,7 @@ fn read_lines(path: &PathBuf) -> ProgResult<Vec<String>> {
Ok(lines)
}
+// REVIEW: There has to be a better way to do this. Separate into multiple functions?
fn read_files(dir_path: &str, unique: bool) -> ProgResult<(SentenceSet, CategorySet)> {
let mut opt_sentences: Option<SentenceSet> = None;
let mut categories = CategorySet::new(unique);
diff --git a/test_data/sentences.txt b/test_data/sentences.txt
index 5933427..7c48dbf 100644
--- a/test_data/sentences.txt
+++ b/test_data/sentences.txt
@@ -12,3 +12,5 @@ This sentence uses 10 identical variables: %%?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%%
This sentence uses four completely random types: %%?%% %%?%% %%?%% %%?%%
+This sentence chooses the word 'foo' or 'bar': %%"foo"|"bar"%%
+This sentence chooses the word 'foo' or a word from type c: %%"foo"|c%%