diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-04 15:04:07 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-04 15:04:07 -0600 |
commit | 8d990bbdcb51a97b3f9430f57f947507b138b488 (patch) | |
tree | 6729bfcd0aef9d3fd27521544c15b72967205d03 | |
parent | bd4ca514538157e4300169821e867e4c4051affc (diff) | |
download | makers-8d990bbdcb51a97b3f9430f57f947507b138b488.tar.gz makers-8d990bbdcb51a97b3f9430f57f947507b138b488.zip |
implement `or` function
-rw-r--r-- | src/makefile/functions.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index 45ef925..9cd78f8 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -54,6 +54,10 @@ pub fn expand_call( assert!(args.len() == 2 || args.len() == 3); conditional::r#if(macros, &args[0], &args[1], args.get(2)) } + "or" => { + assert!(!args.is_empty()); + conditional::or(macros, args.iter()) + } "and" => { assert!(!args.is_empty()); conditional::and(macros, args.iter()) @@ -251,6 +255,19 @@ mod conditional { } } + pub fn or<'a>( + macros: &MacroSet, + args: impl Iterator<Item = &'a TokenString>, + ) -> Result<String> { + for arg in args { + let arg = macros.expand(arg)?; + if !arg.is_empty() { + return Ok(arg); + } + } + Ok(String::new()) + } + pub fn and<'a>( macros: &MacroSet, args: impl Iterator<Item = &'a TokenString>, |