aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-04 14:57:44 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-04 14:57:44 -0600
commite3c7df868b638f8dbf2423401b2fb72fc0779249 (patch)
treeb84dbac90821d97cf58d67b48d6f6622b6217530
parent81a9e84be89719e2a856b7600b6cf5780295d340 (diff)
downloadmakers-e3c7df868b638f8dbf2423401b2fb72fc0779249.tar.gz
makers-e3c7df868b638f8dbf2423401b2fb72fc0779249.zip
implement `strip` function
-rw-r--r--src/makefile/functions.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index d746d8a..750d56a 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 {
+ "strip" => {
+ assert_eq!(args.len(), 1);
+ text::strip(macros, &args[0])
+ }
"filter" => {
assert_eq!(args.len(), 2);
text::filter(macros, &args[0], &args[1])
@@ -95,6 +99,13 @@ pub fn expand_call(
mod text {
use super::*;
+ pub fn strip(macros: &MacroSet, text: &TokenString) -> Result<String> {
+ let text = macros.expand(text)?;
+ // TODO don't allocate this vec
+ let words = text.split_whitespace().collect::<Vec<_>>();
+ Ok(words.join(" "))
+ }
+
pub fn filter(macros: &MacroSet, patterns: &TokenString, text: &TokenString) -> Result<String> {
let patterns = macros.expand(patterns)?;
let patterns = patterns.split_whitespace().collect::<Vec<_>>();