|
3 | 3 |
|
4 | 4 | use super::{Command, Pipe, Redirect}; |
5 | 5 | use crate::elements::command; |
6 | | -use crate::elements::command::{BraceCommand, IfCommand, ParenCommand, WhileCommand}; |
| 6 | +use crate::elements::command::{ |
| 7 | + BraceCommand, IfCommand, ParenCommand, SimpleCommand, WhileCommand |
| 8 | +}; |
7 | 9 | use crate::error::exec::ExecError; |
8 | 10 | use crate::error::parse::ParseError; |
9 | 11 | use crate::utils; |
10 | 12 | use crate::{Feeder, ShellCore}; |
11 | 13 | use nix::unistd::Pid; |
12 | 14 | use nix::sys::wait::WaitStatus; |
| 15 | +//use std::{thread, time}; |
13 | 16 | use crate::core::jobtable::JobEntry; |
14 | 17 |
|
15 | 18 | #[derive(Debug, Clone, Default)] |
@@ -87,6 +90,8 @@ impl Command for Coprocess { |
87 | 90 | core.job_table.push(entry); |
88 | 91 | core.tty_fd = backup; |
89 | 92 |
|
| 93 | + //thread::sleep(time::Duration::from_millis(100)); |
| 94 | + //core.jobtable_check_status()?; |
90 | 95 | Ok(None) |
91 | 96 | } |
92 | 97 |
|
@@ -162,20 +167,42 @@ impl Coprocess { |
162 | 167 | Ok(()) |
163 | 168 | } |
164 | 169 |
|
| 170 | + fn parse_simple_command(feeder: &mut Feeder, |
| 171 | + core: &mut ShellCore |
| 172 | + ) -> Result<Option<Self>, ParseError> { |
| 173 | + let mut ans = Self::default(); |
| 174 | + ans.text += &feeder.consume(6); |
| 175 | + command::eat_blank_with_comment(feeder, core, &mut ans.text); |
| 176 | + |
| 177 | + ans.command = if let Some(a) = SimpleCommand::parse(feeder, core)? { |
| 178 | + ans.text += &a.get_text(); |
| 179 | + ans.name = "COPROC".to_string(); |
| 180 | + Some(a) |
| 181 | + }else{ |
| 182 | + return Err(ParseError::UnexpectedSymbol("coproc".to_string())); |
| 183 | + }; |
| 184 | + |
| 185 | + Ok(Some(ans)) |
| 186 | + } |
| 187 | + |
165 | 188 | pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Result<Option<Self>, ParseError> { |
166 | 189 | if ! feeder.starts_with("coproc") { |
167 | 190 | return Ok(None); |
168 | 191 | } |
169 | 192 | let mut ans = Self::default(); |
170 | 193 | ans.lineno = feeder.lineno; |
171 | 194 |
|
| 195 | + feeder.set_backup(); |
| 196 | + |
172 | 197 | ans.eat_header(feeder, core)?; |
173 | 198 | ans.eat_body(feeder, core)?; |
174 | 199 |
|
175 | 200 | if ans.command.is_some() { |
| 201 | + feeder.pop_backup(); |
176 | 202 | Ok(Some(ans)) |
177 | 203 | } else { |
178 | | - Ok(None) |
| 204 | + feeder.rewind(); |
| 205 | + Self::parse_simple_command(feeder, core) |
179 | 206 | } |
180 | 207 | } |
181 | 208 | } |
0 commit comments