From 89a87698ed39188fee792cc3488bffed2ff525cf Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 3 Apr 2021 12:26:33 -0600 Subject: implement `eval` --- src/makefile/macro.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/makefile/macro.rs') 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, lookup_internal: Option<&'lookup dyn LookupInternal>, + #[cfg(feature = "full")] + pub to_eval: Rc>>, } 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(), } } } -- cgit v1.2.3