diff options
| author | Jonas Maier <> | 2026-03-05 08:54:06 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-05 08:54:06 +0100 |
| commit | ba0b70df55a9439d5bd364df2ff17cd7875227c8 (patch) | |
| tree | 23d0549939644796ff9a08f1c506d932381f9fa6 /src | |
| parent | 9bee39d5bb89f74820b448d3dbb6617c64141ab7 (diff) | |
| download | pish-ba0b70df55a9439d5bd364df2ff17cd7875227c8.tar.gz | |
correct seeming parsing
Diffstat (limited to 'src')
| -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))?; } } } |
