diff --git a/src/parser.rs b/src/parser.rs index 4e9a378..057499e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,6 +1,22 @@ use crate::command::command_builder::CommandBuilder; use crate::command::command_sequence::CommandSequence; +fn parse_quote(characters: &mut Vec) -> Result { + if characters.is_empty() { + Err(UnmatchedQuoteError) + } else { + let mut quoted_arg = String::default(); + let mut current_char = characters.pop().unwrap(); + + while !characters.is_empty() && current_char != '\'' { + quoted_arg.push(current_char); + current_char = characters.pop().unwrap(); + } + + Ok(quoted_arg) + } +} + fn build_argv(characters: &mut Vec, current_arg: &mut String) -> Vec { if characters.is_empty() { vec![] @@ -16,6 +32,11 @@ fn build_argv(characters: &mut Vec, current_arg: &mut String) -> Vec, current_arg: &mut String) -> Vec Option { let mut characters: Vec = line.chars().rev().collect(); - let argv = build_argv(&mut characters, &mut String::from("")); + let argv = build_argv(&mut characters, &mut String::default()); if !argv.is_empty() { let command = CommandBuilder::new(argv).build(); @@ -34,3 +55,6 @@ pub fn parse_command_line(line: String) -> Option { None } } + +#[derive(Debug)] +struct UnmatchedQuoteError;