parser : prise en compte de ';'
This commit is contained in:
parent
f0f137d18f
commit
ddcbf4d7ef
3 changed files with 19 additions and 15 deletions
|
@ -27,6 +27,10 @@ impl CommandSequence {
|
||||||
self.next_command.as_mut().unwrap().add(command);
|
self.next_command.as_mut().unwrap().add(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.command.is_none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command for CommandSequence {
|
impl Command for CommandSequence {
|
||||||
|
|
|
@ -17,10 +17,10 @@ pub fn run() {
|
||||||
let user_input = get_user_input();
|
let user_input = get_user_input();
|
||||||
|
|
||||||
if user_input.is_some() {
|
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() {
|
if !command_sequence.is_empty() {
|
||||||
current_exit_code = command_sequence.unwrap().spawn();
|
current_exit_code = command_sequence.spawn();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!();
|
println!();
|
||||||
|
|
|
@ -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.append(&mut parse_main(characters, &mut String::default()));
|
||||||
|
|
||||||
argv
|
argv
|
||||||
|
} else if current_char == ';' {
|
||||||
|
vec![]
|
||||||
} else {
|
} else {
|
||||||
current_arg.push(current_char);
|
current_arg.push(current_char);
|
||||||
parse_main(characters, current_arg)
|
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 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());
|
||||||
let argv = parse_main(&mut characters, &mut String::default());
|
|
||||||
|
|
||||||
if !argv.is_empty() {
|
if !argv.is_empty() {
|
||||||
let command = CommandBuilder::new(argv).build();
|
let command = CommandBuilder::new(argv).build();
|
||||||
let mut command_sequence = CommandSequence::new();
|
command_sequence.add(command);
|
||||||
command_sequence.add(command);
|
}
|
||||||
Some(command_sequence)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
command_sequence
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Reference in a new issue