From bd4ca514538157e4300169821e867e4c4051affc Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 4 Apr 2021 15:02:48 -0600 Subject: implement `and` function --- src/makefile/functions.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src') 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, + ) -> Result { + 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( -- cgit v1.2.3