aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-04 15:02:48 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-04 15:02:48 -0600
commitbd4ca514538157e4300169821e867e4c4051affc (patch)
treef8e2d53e25dc53a51e6f7e0cd1b86ae130a5734f /src
parente3c7df868b638f8dbf2423401b2fb72fc0779249 (diff)
downloadmakers-bd4ca514538157e4300169821e867e4c4051affc.tar.gz
makers-bd4ca514538157e4300169821e867e4c4051affc.zip
implement `and` function
Diffstat (limited to 'src')
-rw-r--r--src/makefile/functions.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 750d56a..45ef925 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -54,20 +54,21 @@ pub fn expand_call(
assert!(args.len() == 2 || args.len() == 3);
conditional::r#if(macros, &args[0], &args[1], args.get(2))
}
+ "and" => {
+ assert!(!args.is_empty());
+ conditional::and(macros, args.iter())
+ }
- // foreach
"foreach" => {
assert_eq!(args.len(), 3);
foreach(macros, &args[0], &args[1], &args[2])
}
- // call
"call" => {
assert!(!args.is_empty());
call(macros, args.iter())
}
- // eval
"eval" => {
assert_eq!(args.len(), 1);
let should_eval = eval(macros, &args[0])?;
@@ -84,7 +85,6 @@ pub fn expand_call(
origin(macros, &args[0])
}
- // shell
"shell" => {
assert_eq!(args.len(), 1);
shell(macros, &args[0])
@@ -250,6 +250,20 @@ mod conditional {
macros.expand(if_true)
}
}
+
+ pub fn and<'a>(
+ macros: &MacroSet,
+ args: impl Iterator<Item = &'a TokenString>,
+ ) -> Result<String> {
+ let mut last = String::new();
+ for arg in args {
+ last = macros.expand(arg)?;
+ if last.is_empty() {
+ return Ok(String::new());
+ }
+ }
+ Ok(last)
+ }
}
pub fn foreach(