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/functions.rs | |
parent | 31a35ac86e41a698a5eafcc0b4cbfa64e2066c39 (diff) | |
download | makers-89a87698ed39188fee792cc3488bffed2ff525cf.tar.gz makers-89a87698ed39188fee792cc3488bffed2ff525cf.zip |
implement `eval`
Diffstat (limited to 'src/makefile/functions.rs')
-rw-r--r-- | src/makefile/functions.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index 43ed44b..a22ec3b 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -1,10 +1,18 @@ +use std::cell::RefCell; +use std::rc::Rc; + use eyre::{bail, Result}; use super::pattern::r#match; use super::r#macro::{Set as MacroSet, Source as MacroSource}; use super::token::TokenString; -pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result<String> { +pub fn expand_call( + name: &str, + args: &[TokenString], + macros: &MacroSet, + to_eval: Option<Rc<RefCell<Vec<String>>>>, +) -> Result<String> { match name { "filter" => { assert_eq!(args.len(), 2); @@ -54,7 +62,16 @@ pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> Resul } // eval - "eval" => todo!(), + "eval" => { + assert_eq!(args.len(), 1); + let should_eval = eval::eval(macros, &args[0])?; + if let Some(to_eval) = to_eval { + to_eval.borrow_mut().push(should_eval); + } else { + bail!("tried to eval something but no eval back-channel was available"); + } + return Ok(String::new()); + } "origin" => { assert_eq!(args.len(), 1); @@ -268,6 +285,14 @@ mod call { } } +mod eval { + use super::*; + + pub fn eval(macros: &MacroSet, arg: &TokenString) -> Result<String> { + macros.expand(arg) + } +} + mod origin { use super::*; @@ -317,7 +342,7 @@ mod test { type R = Result<()>; fn call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result<String> { - super::expand_call(name, args, macros) + super::expand_call(name, args, macros, None) } macro_rules! call { |