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
commit1131c5d8a1ba573701b101ef0939b9505e1e2943 (patch)
treef0ddd3a20057cedb498438bd3df52350f801ffe7
parentd1da14e73c33e015e868a011cb473177edbd3759 (diff)
downloadskaldpress-1131c5d8a1ba573701b101ef0939b9505e1e2943.tar.gz
skaldpress-1131c5d8a1ba573701b101ef0939b9505e1e2943.zip
Add some sensible parsing of nested parantheses
-rw-r--r--src/macro_processor/macro_processor.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs
index cec742e..5556388 100644
--- a/src/macro_processor/macro_processor.rs
+++ b/src/macro_processor/macro_processor.rs
@@ -207,7 +207,7 @@ fn smp_builtin_indent(
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") {
+ if args.len() <= 2 || (args[2] != "skip_first") {
for _ in 0..indent_size {
lin.push(' ');
}
@@ -373,6 +373,8 @@ impl MacroProcessor {
let mut in_quote_single = false;
let mut in_quote_double = false;
+ let mut parens_level = 0;
+
for (i, c) in input.char_indices() {
highlight_debug!(input, macro_name_start, i);
@@ -401,6 +403,7 @@ impl MacroProcessor {
if c.is_alphanumeric() || c == '_' {
macro_name.push(c);
} else if c == '(' {
+ parens_level += 1;
state = ParserState::InMacroArgs;
} else {
if self.macros.contains_key(&macro_name) {
@@ -424,20 +427,27 @@ impl MacroProcessor {
}
}
ParserState::InMacroArgs => {
- if c == ')' {
+ if (c == ')') && (parens_level == 1) {
highlight_debug!("\x1b[32m\x1b[7m", input, (macro_name_start -> i));
-
+ parens_level = 0;
macro_args.push(argument.trim().to_string());
+ println!("{:?}", macro_args);
let expanded = self.expand_macro(&macro_name, &mut macro_args)?;
output.push_str(&expanded);
state = ParserState::Normal;
macro_name.clear();
macro_args.clear();
argument.clear();
- } else if c == ',' {
+ } else if (c == ',') && (parens_level == 1) {
macro_args.push(argument.trim().to_string());
argument.clear();
} else {
+ if c == '(' {
+ parens_level += 1;
+ }
+ if c == ')' {
+ parens_level -= 1;
+ }
argument.push(c);
}
}