diff options
Diffstat (limited to 'src/macro_processor')
| -rw-r--r-- | src/macro_processor/macro_processor.rs | 25 | 
1 files changed, 25 insertions, 0 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs index 7ec296e..cec742e 100644 --- a/src/macro_processor/macro_processor.rs +++ b/src/macro_processor/macro_processor.rs @@ -197,6 +197,27 @@ fn smp_builtin_expr(      }  } +/// Indent argument 2 by N spaces +fn smp_builtin_indent( +    smp: &mut MacroProcessor, +    _macro_name: &str, +    args: &mut [String], +) -> Result<String, SMPError> { +    let indent_size = args[0].parse::<u32>().unwrap_or(0); +    let mut out = String::with_capacity(args[1].len()); +    for l in args[1].lines() { +        let mut lin = String::with_capacity(indent_size.try_into().unwrap_or(0) + l.len()); +        if args.len() <= 2 && (args[2] != "skip_first") { +            for _ in 0..indent_size { +                lin.push(' '); +            } +        } +        lin.push_str(&smp.process_input(&l)?); +        out.push_str(&lin); +    } +    Ok(String::new()) +} +  /// Types of macros, this is to make it easy to store both functions and strings  #[derive(Clone)]  pub enum MacroType { @@ -270,6 +291,10 @@ impl MacroProcessor {              String::from("shell"),              MacroType::Function(smp_builtin_shell),          ); +        self.define_macro( +            String::from("indent"), +            MacroType::Function(smp_builtin_indent), +        );          self.define_macro(String::from("expr"), MacroType::Function(smp_builtin_expr));          // format('Result id %d', 3282)      }  | 
