about summary refs log tree commit diff
path: root/pkgs/profpatsch/execline
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2020-06-27 04:03:08 +0200
committerProfpatsch <mail@profpatsch.de>2020-06-27 04:03:08 +0200
commit13ad936f8432d2fe46169716ddf5eb7d4f84f202 (patch)
treecb81532becb3decbb767aa85288f33cd6c368ebf /pkgs/profpatsch/execline
parent5543a7fefd0bd28e50d7945587353d77a520c402 (diff)
pkgs/profpatsch/execline/el_semicolon: mark empty blocks as blocks
Diffstat (limited to 'pkgs/profpatsch/execline')
-rw-r--r--pkgs/profpatsch/execline/el_semicolon.rs15
1 files changed, 10 insertions, 5 deletions
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<Vec<Arg<'a>>, Error> {
+pub fn el_semicolon<'a, S: AsRef<[u8]>>(args: &'a [S]) -> Result<Vec<Arg<'a>>, Error> {
     let mut cur_block : Option<Vec<&'a [u8]>> = None;
     let mut res : Vec<Arg<'a>> = 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 {