diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2024-04-04 00:42:02 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2024-04-04 00:42:02 +1300 |
| commit | c7850d24e95f2e5338a02e2dfe6c425ec1ef2ae8 (patch) | |
| tree | 3be31f163f630c9fe4364116df1eefd9eec07dfa /src | |
| parent | 0a1c4493524c61c647149223626941748736ac3e (diff) | |
Support for literal values
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 19 |
1 files changed, 19 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); |
