summaryrefslogtreecommitdiff
path: root/src/highlighter.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/highlighter.rs')
-rw-r--r--src/highlighter.rs32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/highlighter.rs b/src/highlighter.rs
index 40e618e..fe40160 100644
--- a/src/highlighter.rs
+++ b/src/highlighter.rs
@@ -105,22 +105,28 @@ impl Highlighter {
fn replace_variables(pattern: &str, variables: &HashMap<String, String>) -> String {
let mut output = String::new();
- let mut chars = pattern.chars();
- while let Some(c) = chars.next() {
- if c == '<' {
- let mut name = String::from('<');
- loop {
- match chars.next() {
- Some('>') => { name.push('>'); break; }
- Some(c) => name.push(c),
- None => panic!("Missing '>' character"),
+ let chars: Vec<char> = pattern.chars().collect();
+ let mut i = 0;
+ 'outer: while let Some(c) = chars.get(i) {
+ if *c == '<' {
+ let mut name = String::from(*c);
+ let mut j = i+1;
+ while let Some(d) = chars.get(j) {
+ name.push(*d);
+ if *d == '>' {
+ let pattern = variables.get(&name).expect(&format!("Missing definition for {name:?}"));
+ output.push_str(&format!("(?:{pattern})"));
+ i = j+1;
+ continue 'outer;
}
+ if !d.is_lowercase() && *d != '-' {
+ break;
+ }
+ j += 1;
}
- let pattern = variables.get(&name).expect(&format!("Missing definition for {name:?}"));
- output.push_str(&format!("(?:{pattern})"));
- } else {
- output.push(c);
}
+ output.push(*c);
+ i += 1;
}
return output;
}