diff options
author | Qrius <[email protected]> | 2024-09-26 00:11:05 +0200 |
---|---|---|
committer | Qrius <[email protected]> | 2024-09-26 00:11:05 +0200 |
commit | 1aa00ad16b140b93d893166ce1b7e93f3b847069 (patch) | |
tree | 950c109019d84633fdc3b04f83c427b142e05ee2 /src | |
parent | 8e6be2a3092db112a5e59042b678654576d57d32 (diff) | |
download | skaldpress-1aa00ad16b140b93d893166ce1b7e93f3b847069.tar.gz skaldpress-1aa00ad16b140b93d893166ce1b7e93f3b847069.zip |
Expand arguments of macro if it doesn't exist
Diffstat (limited to 'src')
-rw-r--r-- | src/macro_processor/macro_processor.rs | 13 |
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 { |