diff options
Diffstat (limited to 'src/parse/mod.rs')
| -rw-r--r-- | src/parse/mod.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 184a514..88d0362 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -861,6 +861,21 @@ impl Parse for ExpString { } } +impl Parse for Vec<ExpString> { + fn parse(b: &mut Cursor<'_>) -> Result<Self> { + let mut strings = Vec::new(); + loop { + match ExpString::parse(b) { + Ok(s) => strings.push(s), + Err(ParseError::Eof) => break, + Err(ParseError::NotAString) => break, + Err(e) => Err(e)?, + } + } + Ok(strings) + } +} + #[derive(Debug, Clone, PartialEq)] pub struct Command<T: Stage> { pub cmd: T::Str, @@ -1036,7 +1051,12 @@ pub fn completion_context<E: Expander>(x: &[u8], e: &mut E) -> CompletionContext pub trait Parse: Sized { fn parse(b: &mut Cursor<'_>) -> Result<Self>; fn parse_from_bytes(x: &[u8]) -> Result<Self> { - Self::parse(&mut Cursor::new(x, ParseMode::Command)) + let mut c = Cursor::new(x, ParseMode::Command); + let parsed = Self::parse(&mut c)?; + if c.has() { + return Err(ParseError::Unknown(c.buf[0])); + } + Ok(parsed) } } |
