From 13ad936f8432d2fe46169716ddf5eb7d4f84f202 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 27 Jun 2020 04:03:08 +0200 Subject: pkgs/profpatsch/execline/el_semicolon: mark empty blocks as blocks --- pkgs/profpatsch/execline/el_semicolon.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'pkgs/profpatsch/execline/el_semicolon.rs') diff --git a/pkgs/profpatsch/execline/el_semicolon.rs b/pkgs/profpatsch/execline/el_semicolon.rs index 9dc08d9b..46bf0aed 100644 --- a/pkgs/profpatsch/execline/el_semicolon.rs +++ b/pkgs/profpatsch/execline/el_semicolon.rs @@ -6,7 +6,7 @@ const BLOCK_END : &'static [u8] = &[]; /// A parsed execline argument. #[derive(Debug, PartialEq, Eq)] -enum Arg<'a> { +pub enum Arg<'a> { /// Normal argument. Arg(&'a [u8]), /// A block. @@ -14,11 +14,15 @@ enum Arg<'a> { /// On the command line a block is represented /// by a list of arguments which start with a space /// and end with an empty string. + /// + /// An empty block was just an empty string on its own. + /// You will have to decide whether you want to treat + /// it as a block or an empty string. Block(Vec<&'a [u8]>) } #[derive(Debug, PartialEq, Eq)] -enum Error { +pub enum Error { /// The argument was not quoted, at index. UnquotedArgument(usize), /// The last block was not terminated @@ -31,14 +35,15 @@ enum Error { /// but `el_semicolon` will only parse one level. /// Usually that is intended, because nested blocks /// are intended to be parsed by nested programs. -fn el_semicolon<'a>(args: &'a [&'a [u8]]) -> Result>, Error> { +pub fn el_semicolon<'a, S: AsRef<[u8]>>(args: &'a [S]) -> Result>, Error> { let mut cur_block : Option> = None; let mut res : Vec> = vec![]; for (i, arg) in args.iter().enumerate() { - if arg == &BLOCK_END { + let arg = arg.as_ref(); + if arg == BLOCK_END { let bl = cur_block.take(); match bl { - None => res.push(Arg::Arg(arg)), + None => res.push(Arg::Block(vec![])), Some(bl) => res.push(Arg::Block(bl)) } } else { -- cgit 1.4.1