aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/conditional.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/conditional.rs')
-rw-r--r--src/makefile/conditional.rs41
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(())
+ }
+}