diff options
Diffstat (limited to 'src/run')
| -rw-r--r-- | src/run/mod.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/run/mod.rs b/src/run/mod.rs index 64522d9..3420c30 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -457,10 +457,17 @@ impl Executor { stdout: OutputWriter, ) -> SpawnedCmd { for branch in c.branches.into_iter() { - // TODO: do not compile every time - if let Ok(compiled) = branch.pattern.try_compile() - && compiled.matches(&c.discriminant) + if let Ok(compiled) = Session::cached_regex(self.se.as_ref(), branch.pattern) + && let Some(mtch) = compiled.run(&c.discriminant) { + // put submatches into variables + if !mtch.submatches.is_empty() { + let mut se = self.se.lock().unwrap(); + for (var, match_loc) in mtch.submatches.into_iter() { + let val = c.discriminant[match_loc].to_vec(); + se.vars.set(var, val); + } + } return self.execute_block(branch.block, stdin, stdout); } } |
