aboutsummaryrefslogtreecommitdiffstats
path: root/src/run/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/run/mod.rs')
-rw-r--r--src/run/mod.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/run/mod.rs b/src/run/mod.rs
index a2a6cb1..f86278d 100644
--- a/src/run/mod.rs
+++ b/src/run/mod.rs
@@ -26,6 +26,7 @@ pub enum ExecError {
Parse(crate::parse::ParseError),
Break,
Continue,
+ NoCaseMatch,
}
impl ExecError {
@@ -71,6 +72,7 @@ impl ExecError {
ExecError::Parse(pe) => format!("parse error: {pe:?}"),
ExecError::Break => "break: only useful in loops".to_string(),
ExecError::Continue => "continue: only useful in loops".to_string(),
+ ExecError::NoCaseMatch => "case: no pattern matched".to_string(),
}
}
}
@@ -356,6 +358,7 @@ impl Executor {
Ast::Pipes(pipes) => self.execute_pipeline(pipes, stdin, stdout),
Ast::If(cond) => self.execute_if(cond, stdin, stdout),
Ast::While(w) => self.execute_while(w, stdin, stdout),
+ Ast::Case(c) => self.execute_case(c, stdin, stdout),
}
}
@@ -446,6 +449,21 @@ impl Executor {
SpawnedCmd::Fun(handle)
}
+ fn execute_case(
+ &mut self,
+ c: parse::Case<PostExpansion>,
+ stdin: InputReader,
+ stdout: OutputWriter,
+ ) -> SpawnedCmd {
+ for branch in c.branches.into_iter() {
+ // TODO: regex case patterns
+ if branch.pattern == c.discriminant {
+ return self.execute_block(branch.block, stdin, stdout);
+ }
+ }
+ SpawnedCmd::Joined(Err(ExecError::NoCaseMatch))
+ }
+
pub fn execute_script(
&mut self,
s: parse::Script,