summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQrius <[email protected]>2024-09-26 00:11:05 +0200
committerQrius <[email protected]>2024-09-26 00:11:05 +0200
commit1aa00ad16b140b93d893166ce1b7e93f3b847069 (patch)
tree950c109019d84633fdc3b04f83c427b142e05ee2
parent8e6be2a3092db112a5e59042b678654576d57d32 (diff)
downloadskaldpress-1aa00ad16b140b93d893166ce1b7e93f3b847069.tar.gz
skaldpress-1aa00ad16b140b93d893166ce1b7e93f3b847069.zip
Expand arguments of macro if it doesn't exist
-rw-r--r--src/macro_processor/macro_processor.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs
index 326b28f..85bf8e1 100644
--- a/src/macro_processor/macro_processor.rs
+++ b/src/macro_processor/macro_processor.rs
@@ -347,7 +347,18 @@ impl MacroProcessor {
/// * `args` - List of arguments parsed along with macro invokation (empty list if no arguments were parsed)
fn expand_macro(&mut self, macro_name: &str, args: &mut [String]) -> Result<String, SMPError> {
let Some(macro_body) = self.macros.get(macro_name) else {
- return Ok(format!("{}", macro_name));
+ if args.len() == 0 {
+ return Ok(format!("{}", macro_name));
+ }
+ let mut out = format!("{}(", macro_name);
+ for (i, arg) in args.iter().enumerate() {
+ out.push_str(&self.process_input(arg)?);
+ if i < (args.len() - 1) {
+ out.push(',');
+ }
+ }
+ out.push(')');
+ return Ok(out);
};
match macro_body {