aboutsummaryrefslogtreecommitdiff
path: root/src/makefile
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-05 11:58:17 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-05 11:58:17 -0600
commitc5b0ecbfbb73113e99f8baa29891fbe0ba598b68 (patch)
treedb94e9b7f6f3fa860042602c991a0f7c4598748f /src/makefile
parentf7b8de180cc8db854ceba3f1644e9d7387d74ae3 (diff)
downloadmakers-c5b0ecbfbb73113e99f8baa29891fbe0ba598b68.tar.gz
makers-c5b0ecbfbb73113e99f8baa29891fbe0ba598b68.zip
implement function `subst`
Diffstat (limited to 'src/makefile')
-rw-r--r--src/makefile/functions.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 6e9d3cb..46caca5 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -16,6 +16,10 @@ pub fn expand_call(
to_eval: Option<Rc<RefCell<Vec<String>>>>,
) -> Result<String> {
match name {
+ "subst" => {
+ assert_eq!(args.len(), 3);
+ text::subst(macros, &args[0], &args[1], &args[2])
+ }
"strip" => {
assert_eq!(args.len(), 1);
text::strip(macros, &args[0])
@@ -123,6 +127,18 @@ pub fn expand_call(
mod text {
use super::*;
+ pub fn subst(
+ macros: &MacroSet,
+ from: &TokenString,
+ to: &TokenString,
+ text: &TokenString,
+ ) -> Result<String> {
+ let from = macros.expand(from)?;
+ let to = macros.expand(to)?;
+ let text = macros.expand(text)?;
+ Ok(text.replace(&from, &to))
+ }
+
pub fn strip(macros: &MacroSet, text: &TokenString) -> Result<String> {
let text = macros.expand(text)?;
// TODO don't allocate this vec