diff options
| -rw-r--r-- | src/parse.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/parse.rs b/src/parse.rs index 27b07de..efe3b33 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -31,7 +31,7 @@ pub enum ParseError { UnexpectedPipe, - Unknownu8(u8), + Unknown(u8), } type Result<T> = std::result::Result<T, ParseError>; @@ -63,7 +63,6 @@ fn adv(b: &mut &[u8]) { fn parse_quoted_string(b: &mut &[u8], delim: u8) -> Result<Vec<u8>> { // TODO: escape sequence stuff - *b = &b[1..]; let mut s = Vec::new(); while b.len() > 0 { if b[0] == delim { @@ -74,7 +73,12 @@ fn parse_quoted_string(b: &mut &[u8], delim: u8) -> Result<Vec<u8>> { s.push(b[0]); adv(b); } - Err(ParseError::Incomplete) + + if delim == b' ' { + Ok(s) + } else { + Err(ParseError::Incomplete) + } } impl Parse for Vec<u8> { @@ -92,7 +96,7 @@ impl Parse for Vec<u8> { } else if c.is_ascii_graphic() { parse_quoted_string(b, b' ') } else { - Err(ParseError::Unknownu8(c)) + Err(ParseError::Unknown(c)) } } } @@ -121,7 +125,7 @@ impl Parse for Command { impl Parse for Pipes { fn parse(b: &mut &[u8]) -> Result<Self> { - let cmds: Vec<Command> = vec![parse(b)?]; + let mut cmds: Vec<Command> = vec![parse(b)?]; loop { spaces(b); @@ -132,8 +136,9 @@ impl Parse for Pipes { let c = b[0]; if c == b'|' { adv(b); + cmds.push(parse(b)?); } else { - Err(ParseError::Unknownu8(c))?; + Err(ParseError::Unknown(c))?; } } } |
