diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-03 12:26:33 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-03 12:26:33 -0600 |
commit | 89a87698ed39188fee792cc3488bffed2ff525cf (patch) | |
tree | dcb78dcc5005aa6b9192211cb7194d0a5f8d4919 /src/makefile/macro.rs | |
parent | 31a35ac86e41a698a5eafcc0b4cbfa64e2066c39 (diff) | |
download | makers-89a87698ed39188fee792cc3488bffed2ff525cf.tar.gz makers-89a87698ed39188fee792cc3488bffed2ff525cf.zip |
implement `eval`
Diffstat (limited to 'src/makefile/macro.rs')
-rw-r--r-- | src/makefile/macro.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs index 7fbb4a6..a1f2378 100644 --- a/src/makefile/macro.rs +++ b/src/makefile/macro.rs @@ -1,6 +1,10 @@ +#[cfg(feature = "full")] +use std::cell::RefCell; use std::collections::HashMap; use std::env; use std::fmt; +#[cfg(feature = "full")] +use std::rc::Rc; use eyre::{bail, Result, WrapErr}; use regex::Regex; @@ -26,6 +30,8 @@ pub struct Set<'parent, 'lookup> { parent: Option<&'parent Set<'parent, 'lookup>>, data: HashMap<String, (Source, TokenString)>, lookup_internal: Option<&'lookup dyn LookupInternal>, + #[cfg(feature = "full")] + pub to_eval: Rc<RefCell<Vec<String>>>, } impl<'parent, 'lookup> Set<'parent, 'lookup> { @@ -34,6 +40,8 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { parent: None, data: HashMap::new(), lookup_internal: None, + #[cfg(feature = "full")] + to_eval: Rc::new(RefCell::new(Vec::new())), } } @@ -58,7 +66,10 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { } else if let Some(parent) = self.parent { parent.lookup_internal(name) } else { - bail!("no lookup possible") + bail!( + "tried to lookup {:?} but no lookup function is available", + name + ) } } @@ -121,7 +132,12 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { } #[cfg(feature = "full")] Token::FunctionCall { name, args } => { - result.push_str(&functions::expand_call(name, args, self)?); + result.push_str(&functions::expand_call( + name, + args, + self, + Some(Rc::clone(&self.to_eval)), + )?); } } } @@ -146,6 +162,8 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { parent: Some(self), data: HashMap::new(), lookup_internal: Some(lookup), + #[cfg(feature = "full")] + to_eval: Default::default(), } } @@ -155,6 +173,8 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { parent: Some(self), data: HashMap::new(), lookup_internal: None, + #[cfg(feature = "full")] + to_eval: Default::default(), } } } |