summaryrefslogtreecommitdiff
path: root/src/macro_processor
diff options
context:
space:
mode:
Diffstat (limited to 'src/macro_processor')
-rw-r--r--src/macro_processor/macro_processor.rs39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs
index f26780e..82a94ef 100644
--- a/src/macro_processor/macro_processor.rs
+++ b/src/macro_processor/macro_processor.rs
@@ -51,9 +51,9 @@ fn smp_builtin_define(
let arg0 = smp.process_input(&args[0])?;
if args.len() > 1 {
let arg1 = smp.process_input(&args[1])?;
- smp.define_macro(arg0, arg1);
+ smp.define_macro(arg0, MacroType::String(arg1));
} else {
- smp.define_macro(arg0, String::new());
+ smp.define_macro(arg0, MacroType::String(String::new()));
}
Ok(String::new())
}
@@ -212,6 +212,7 @@ enum ParserState {
Normal,
InMacro,
InMacroArgs,
+ DNL,
}
/// Defines a MacroProcessor object, with it's associated state
@@ -233,32 +234,32 @@ impl MacroProcessor {
/// Bootstrapping-function for defining all builtins,
/// the same way all other macros might be defined
fn define_builtins(&mut self) {
- self.define_macro_fn(
+ self.define_macro(
String::from("define"),
MacroType::Function(smp_builtin_define),
);
- self.define_macro_fn(
+ self.define_macro(
String::from("ifdef"),
MacroType::Function(smp_builtin_ifdef),
);
- self.define_macro_fn(
+ self.define_macro(
String::from("ifndef"),
MacroType::Function(smp_builtin_ifndef),
);
- self.define_macro_fn(String::from("ifeq"), MacroType::Function(smp_builtin_ifeq));
- self.define_macro_fn(
+ self.define_macro(String::from("ifeq"), MacroType::Function(smp_builtin_ifeq));
+ self.define_macro(
String::from("ifneq"),
MacroType::Function(smp_builtin_ifneq),
);
- self.define_macro_fn(
+ self.define_macro(
String::from("include"),
MacroType::Function(smp_builtin_include),
);
- self.define_macro_fn(
+ self.define_macro(
String::from("shell"),
MacroType::Function(smp_builtin_shell),
);
- self.define_macro_fn(String::from("expr"), MacroType::Function(smp_builtin_expr));
+ self.define_macro(String::from("expr"), MacroType::Function(smp_builtin_expr));
// format('Result id %d', 3282)
}
@@ -268,7 +269,7 @@ impl MacroProcessor {
///
/// * `name` - The name of the new macro
/// * `body` - The body of the new macro, this will be expanded when macro is executed
- pub fn define_macro(&mut self, name: String, body: String) {
+ pub fn define_macro_string(&mut self, name: String, body: String) {
self.macros.insert(name, MacroType::String(body));
}
@@ -278,7 +279,7 @@ impl MacroProcessor {
///
/// * `name` - The name of the new macro
/// * `macro_expansion` - The MacroType struct to use.
- pub fn define_macro_fn(&mut self, name: String, macro_expansion: MacroType) {
+ pub fn define_macro(&mut self, name: String, macro_expansion: MacroType) {
self.macros.insert(name, macro_expansion);
}
@@ -303,11 +304,12 @@ impl MacroProcessor {
let placeholder = format!("${}", i + 1);
expanded = expanded.replace(&placeholder, arg);
}
- return Ok(expanded);
+ self.process_input(&expanded)
}
MacroType::Function(func) => {
return func(self, macro_name, args);
}
+ MacroType::Array(vec) => return Ok(format!("Array[{}]", vec.len())),
}
}
@@ -339,6 +341,11 @@ impl MacroProcessor {
highlight_debug!(input, macro_name_start, i);
match state {
+ ParserState::DNL => {
+ if c == '\n' {
+ state = ParserState::Normal;
+ }
+ }
ParserState::Normal => {
macro_name_start = i;
@@ -365,6 +372,12 @@ impl MacroProcessor {
}
if macro_name == "SNNL" {
skip_next_line_ending = c != '\n';
+ } else if macro_name == "DNL" {
+ if c != '\n' {
+ state = ParserState::DNL;
+ }
+ macro_name.clear();
+ continue;
} else {
let expanded = self.expand_macro(&macro_name, &mut [])?;
output.push_str(&expanded);