From 8d990bbdcb51a97b3f9430f57f947507b138b488 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 4 Apr 2021 15:04:07 -0600 Subject: implement `or` function --- src/makefile/functions.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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, + ) -> Result { + 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, -- cgit v1.2.3