diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-06-06 22:55:27 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-06-06 22:55:27 +0200 |
| commit | 2e379710ca4ca1739788beb502a55d8bd596dc16 (patch) | |
| tree | 65461fd6a669e428bbfcb6ae8944f11627e3cb2b /src/run/mod.rs | |
| parent | 6b452e817090dba6c80454a42079fa5c9f83b1cd (diff) | |
| download | pish-main.tar.gz | |
Diffstat (limited to 'src/run/mod.rs')
| -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); } } |
