aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-04 16:05:39 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-04 16:05:39 -0600
commit9c426f09533c88667cbc3cec2cd6df3a357a703b (patch)
tree5e19f801303764308a08ccd6024638f5c877cecc /src
parentf28e74c6c28c58819cbdc69994ce17407443bbb4 (diff)
downloadmakers-9c426f09533c88667cbc3cec2cd6df3a357a703b.tar.gz
makers-9c426f09533c88667cbc3cec2cd6df3a357a703b.zip
improve replacement in macro tokens
Diffstat (limited to 'src')
-rw-r--r--src/makefile/macro.rs40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs
index 0ab1b4b..4d58e07 100644
--- a/src/makefile/macro.rs
+++ b/src/makefile/macro.rs
@@ -121,10 +121,14 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> {
Some((subst1, subst2)) => {
let subst1 = self.expand(subst1)?;
let subst1_suffix = regex::escape(&subst1);
- let subst1_suffix = Regex::new(&format!(r"{}\b", subst1_suffix))
+ let subst1_suffix = Regex::new(&format!(r"{}(\s|$)", subst1_suffix))
.context("formed invalid regex somehow")?;
let subst2 = self.expand(subst2)?;
- subst1_suffix.replace_all(&macro_value, subst2).to_string()
+ subst1_suffix
+ .replace_all(&macro_value, |c: &regex::Captures| {
+ format!("{}{}", subst2, c.get(1).unwrap().as_str())
+ })
+ .to_string()
}
None => macro_value,
};
@@ -132,12 +136,10 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> {
}
#[cfg(feature = "full")]
Token::FunctionCall { name, args } => {
- result.push_str(&functions::expand_call(
- name,
- args,
- self,
- Some(Rc::clone(&self.to_eval)),
- )?);
+ let fn_result =
+ functions::expand_call(name, args, self, Some(Rc::clone(&self.to_eval)))?;
+ log::trace!("expanded {} into \"{}\"", token, &fn_result);
+ result.push_str(&fn_result);
}
}
}
@@ -240,3 +242,25 @@ fn builtins() -> Vec<(&'static str, TokenString)> {
FFLAGS=""
]
}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ type R = Result<()>;
+
+ #[test]
+ fn subst() -> R {
+ let mut macros = Set::new();
+ macros.set(
+ "oof".to_owned(),
+ Source::File,
+ TokenString::text("bruh; swag; yeet;"),
+ );
+ assert_eq!(
+ macros.expand(&"$(oof:;=?)".parse().unwrap())?,
+ "bruh? swag? yeet?"
+ );
+ Ok(())
+ }
+}