diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-14 20:17:42 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-14 20:17:42 -0600 |
commit | 5a72fb28fb69a476437141a4eb898d6d001dd281 (patch) | |
tree | fcec27e259b34ac9d37fae737e27fd4c0601eae2 /src/makefile/conditional.rs | |
parent | 53124e9b8c1feade1b88144d286ae2fcc4692c7e (diff) | |
download | makers-5a72fb28fb69a476437141a4eb898d6d001dd281.tar.gz makers-5a72fb28fb69a476437141a4eb898d6d001dd281.zip |
implement potentially-mixed-quoted conditional args
Diffstat (limited to 'src/makefile/conditional.rs')
-rw-r--r-- | src/makefile/conditional.rs | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/makefile/conditional.rs b/src/makefile/conditional.rs index 95cab9e..98400e6 100644 --- a/src/makefile/conditional.rs +++ b/src/makefile/conditional.rs @@ -2,7 +2,7 @@ use eyre::{bail, Result}; use super::token::TokenString; -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub enum Line { /// spelled "ifeq" IfEqual(TokenString, TokenString), @@ -73,10 +73,23 @@ fn decode_condition_args(line_body: &str) -> Option<(TokenString, TokenString)> let mut tokens = tokens; tokens.strip_prefix("("); tokens.strip_suffix(")"); - tokens.split_once(',')? + tokens.split_once(",")? } else { - // TODO see if i really need to implement potentially-mixed-quoted args - return None; + let quotes = &["\"", "'"]; + let mut split_pair = None; + for (left_quote, right_quote) in quotes + .iter() + .flat_map(|left| quotes.iter().map(move |right| (left, right))) + { + if tokens.starts_with(left_quote) && tokens.ends_with(right_quote) { + let mut tokens = tokens; + tokens.strip_prefix(left_quote); + tokens.strip_suffix(right_quote); + split_pair = Some(tokens.split_once(&format!("{} {}", left_quote, right_quote))?); + break; + } + } + split_pair? }; arg1.trim_end(); arg2.trim_start(); @@ -182,3 +195,23 @@ impl Line { }) } } + +#[cfg(test)] +mod test { + use super::*; + + type R = Result<()>; + + #[test] + fn quotes() -> R { + let line = r#"ifeq 'x' "3""#; + assert_eq!( + Line::from(line, |_| panic!())?, + Some(Line::IfEqual( + TokenString::text("x"), + TokenString::text("3") + )) + ); + Ok(()) + } +} |