Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 10, 2024
1 parent 8c07f0a commit fbe3bf4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/elements/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ pub fn eat_redirect(feeder: &mut Feeder, core: &mut ShellCore,
}
}

pub fn eat_redirects(feeder: &mut Feeder, core: &mut ShellCore,
ans: &mut Vec<Redirect>, ans_text: &mut String) {
loop {
eat_blank_with_comment(feeder, core, ans_text);
if ! eat_redirect(feeder, core, ans, ans_text){
break;
}
}
}

pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Option<Box<dyn Command>> {
if let Some(a) = SimpleCommand::parse(feeder, core){ Some(Box::new(a)) }
else if let Some(a) = ParenCommand::parse(feeder, core) { Some(Box::new(a)) }
Expand Down
8 changes: 1 addition & 7 deletions src/elements/command/while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ impl WhileCommand {
ans.text.push_str(&ans.do_script.as_mut().unwrap().get_text());
ans.text.push_str(&feeder.consume(4)); //done

loop {
command::eat_blank_with_comment(feeder, core, &mut ans.text);
if ! command::eat_redirect(feeder, core, &mut ans.redirects, &mut ans.text){
break;
}
}
//dbg!("{:?}", &ans);
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text);
Some(ans)
}else{
None
Expand Down
4 changes: 4 additions & 0 deletions test/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,8 @@ res=$($com <<< 'touch /tmp/rusty_bash ; while [ -f /tmp/rusty_bash ] ; do echo w
res=$($com <<< 'rm -f /tmp/rusty_bash ; while [ -f /tmp/rusty_bash ] ; do echo wait ; rm /tmp/rusty_bash ; done')
[ "$res" == "" ] || err $LINENO

res=$($com <<< 'touch /tmp/rusty_bash ; while [ -f /tmp/rusty_bash ] ; do echo wait ; rm /tmp/rusty_bash ; done > /tmp/rusty_bash1'; cat /tmp/rusty_bash1 ; cat /tmp/rusty_bash1 )
[ "$res" == "wait
wait" ] || err $LINENO

echo OK $0

0 comments on commit fbe3bf4

Please sign in to comment.