diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-06 14:11:43 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-06 14:11:43 -0600 |
commit | 5a101a96ada9ddbd4be54c46cd7d0125825c2283 (patch) | |
tree | dd5b54a8b0917d53e17e9fbd31b7280669bcc0ec /src/makefile/functions.rs | |
parent | 1602ad07efa6d3c4170928537843a0d61a5cd5e7 (diff) | |
download | makers-5a101a96ada9ddbd4be54c46cd7d0125825c2283.tar.gz makers-5a101a96ada9ddbd4be54c46cd7d0125825c2283.zip |
eagerly expand when appending to eagerly-expanded macros
Diffstat (limited to 'src/makefile/functions.rs')
-rw-r--r-- | src/makefile/functions.rs | 56 |
1 files changed, 46 insertions, 10 deletions
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::<Result<Vec<_>, _>>()?; @@ -417,7 +425,15 @@ pub fn call<'a>(macros: &MacroSet, args: impl Iterator<Item = &'a TokenString>) 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( |