From 5a101a96ada9ddbd4be54c46cd7d0125825c2283 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 6 Apr 2021 14:11:43 -0600 Subject: eagerly expand when appending to eagerly-expanded macros --- src/makefile/functions.rs | 56 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'src/makefile/functions.rs') diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index 7bb0908..a16c268 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -6,7 +6,7 @@ use std::rc::Rc; use eyre::{bail, Result, WrapErr}; use super::pattern::r#match; -use super::r#macro::{Set as MacroSet, Source as MacroSource}; +use super::r#macro::{Macro, Set as MacroSet, Source as MacroSource}; use super::token::TokenString; pub fn expand_call( @@ -401,7 +401,15 @@ pub fn foreach( let mut macros = macros.with_overlay(); let results = words .map(|word| { - macros.set(var.clone(), MacroSource::File, TokenString::text(word)); + macros.set( + var.clone(), + Macro { + source: MacroSource::File, + text: TokenString::text(word), + #[cfg(feature = "full")] + eagerly_expanded: false, + }, + ); macros.expand(text) }) .collect::, _>>()?; @@ -417,7 +425,15 @@ pub fn call<'a>(macros: &MacroSet, args: impl Iterator) let mut macros = macros.with_overlay(); for (i, x) in args.into_iter().enumerate() { - macros.set(i.to_string(), MacroSource::File, TokenString::text(x)); + macros.set( + i.to_string(), + Macro { + source: MacroSource::File, + text: TokenString::text(x), + #[cfg(feature = "full")] + eagerly_expanded: false, + }, + ); } macros.expand(&TokenString::r#macro(function)) } @@ -579,10 +595,22 @@ mod test { let mut macros = MacroSet::new(); macros.set( "test1".to_owned(), - MacroSource::File, - TokenString::text("something"), + Macro { + source: MacroSource::File, + text: TokenString::text("something"), + #[cfg(feature = "full")] + eagerly_expanded: false, + }, + ); + macros.set( + "test2".to_owned(), + Macro { + source: MacroSource::File, + text: TokenString::text(""), + #[cfg(feature = "full")] + eagerly_expanded: false, + }, ); - macros.set("test2".to_owned(), MacroSource::File, TokenString::text("")); assert_eq!( call( @@ -668,8 +696,12 @@ mod test { let mut macros = MacroSet::new(); macros.set( "test".to_owned(), - MacroSource::File, - "worked for $(item).".parse()?, + Macro { + source: MacroSource::File, + text: "worked for $(item).".parse()?, + #[cfg(feature = "full")] + eagerly_expanded: false, + }, ); assert_eq!( call( @@ -691,8 +723,12 @@ mod test { let mut macros = MacroSet::new(); macros.set( "reverse".to_owned(), - MacroSource::File, - "$(2) $(1)".parse()?, + Macro { + source: MacroSource::File, + text: "$(2) $(1)".parse()?, + #[cfg(feature = "full")] + eagerly_expanded: false, + }, ); assert_eq!( call( -- cgit v1.2.3