parser : prise en compte de ';'

This commit is contained in:
Ahurac 2024-04-14 17:06:51 +02:00
parent f0f137d18f
commit ddcbf4d7ef
3 changed files with 19 additions and 15 deletions

View file

@ -27,6 +27,10 @@ impl CommandSequence {
self.next_command.as_mut().unwrap().add(command);
}
}
pub fn is_empty(&self) -> bool {
self.command.is_none()
}
}
impl Command for CommandSequence {

View file

@ -17,10 +17,10 @@ pub fn run() {
let user_input = get_user_input();
if user_input.is_some() {
let command_sequence = parse(user_input.unwrap());
let mut command_sequence = parse(user_input.unwrap());
if command_sequence.is_some() {
current_exit_code = command_sequence.unwrap().spawn();
if !command_sequence.is_empty() {
current_exit_code = command_sequence.spawn();
}
} else {
println!();

View file

@ -37,6 +37,8 @@ fn parse_main(characters: &mut Vec<char>, current_arg: &mut String) -> Vec<Strin
argv.append(&mut parse_main(characters, &mut String::default()));
argv
} else if current_char == ';' {
vec![]
} else {
current_arg.push(current_char);
parse_main(characters, current_arg)
@ -44,22 +46,20 @@ fn parse_main(characters: &mut Vec<char>, current_arg: &mut String) -> Vec<Strin
}
}
pub fn parse(line: String) -> Option<CommandSequence> {
pub fn parse(line: String) -> CommandSequence {
let mut characters: Vec<char> = line.chars().rev().collect();
let mut command_sequence = CommandSequence::new();
None
/*
while !characters.is_empty() {
let argv = parse_main(&mut characters, &mut String::default());
if !argv.is_empty() {
let command = CommandBuilder::new(argv).build();
let mut command_sequence = CommandSequence::new();
command_sequence.add(command);
Some(command_sequence)
} else {
None
}
*/
}
command_sequence
}
#[derive(Debug)]