summaryrefslogtreecommitdiffstats
path: root/src/shell/history/mod.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-08 18:23:24 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-08 18:23:24 -0500
commit21f67c732a4af18b3a42b9fd34f4b1f4ec7a258d (patch)
tree523e85e00f41d3ff02e30eecc7ebdcf91a056962 /src/shell/history/mod.rs
parent39c9b26a8ab10950b2d26c5a6fd2dbe5189fb50c (diff)
downloadnbsh-21f67c732a4af18b3a42b9fd34f4b1f4ec7a258d.tar.gz
nbsh-21f67c732a4af18b3a42b9fd34f4b1f4ec7a258d.zip
implement while
Diffstat (limited to 'src/shell/history/mod.rs')
-rw-r--r--src/shell/history/mod.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs
index 1eb98c7..0caffa6 100644
--- a/src/shell/history/mod.rs
+++ b/src/shell/history/mod.rs
@@ -287,7 +287,7 @@ impl Stack {
fn should_execute(&self) -> bool {
for frame in &self.frames {
- if let Frame::If(false) = frame {
+ if matches!(frame, Frame::If(false) | Frame::While(_, false)) {
return false;
}
}
@@ -297,7 +297,7 @@ impl Stack {
enum Frame {
If(bool),
- While,
+ While(usize, bool),
For,
}
@@ -379,8 +379,15 @@ fn run_commands(
stack.push(Frame::If(env.latest_status().success()));
pc += 1;
}
- crate::parse::ast::Command::While(_pipeline) => {
- todo!();
+ crate::parse::ast::Command::While(pipeline) => {
+ if stack.should_execute() {
+ run_pipeline!(pipeline);
+ }
+ stack.push(Frame::While(
+ pc,
+ env.latest_status().success(),
+ ));
+ pc += 1;
}
crate::parse::ast::Command::For(_var, _pipeline) => {
todo!();
@@ -389,8 +396,12 @@ fn run_commands(
Frame::If(_) => {
pc += 1;
}
- Frame::While => {
- todo!()
+ Frame::While(start, should) => {
+ if should {
+ pc = start;
+ } else {
+ pc += 1;
+ }
}
Frame::For => {
todo!()