add error if command not found
This commit is contained in:
parent
bec4429c3a
commit
f9bb10d104
2 changed files with 15 additions and 29 deletions
14
src/enums.rs
14
src/enums.rs
|
@ -136,17 +136,17 @@ fn parse_without_addr(c: char) -> Command {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn parse(c: char, addr: Address) -> Command {
|
fn parse(c: char, addr: Address) -> Result<Command, String> {
|
||||||
match c {
|
match c {
|
||||||
'p' => Command::Print(addr),
|
'p' => Ok(Command::Print(addr)),
|
||||||
'n' => Command::Number(addr),
|
'n' => Ok(Command::Number(addr)),
|
||||||
'q' => Command::Quit(false),
|
'q' => Ok(Command::Quit(false)),
|
||||||
'Q' => Command::Quit(true),
|
'Q' => Ok(Command::Quit(true)),
|
||||||
_ => Command::Help,
|
_ => Ok(Command::Help),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_command(c: char, addr: Address) -> Command {
|
pub fn parse_command(c: char, addr: Address) -> Result<Command, String> {
|
||||||
parse(c, addr)
|
parse(c, addr)
|
||||||
/*
|
/*
|
||||||
if let Some(a) = addr {
|
if let Some(a) = addr {
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -33,20 +33,6 @@ fn read_address(input: &str) -> Result<&str, Address> {
|
||||||
* Le char doit être une commande valide.
|
* Le char doit être une commande valide.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
fn parse_multi_addr(addr: &str) -> Address {
|
|
||||||
//let extract = take_till::<&str, &str, Error>(|c| c == ',');
|
|
||||||
let extract = take_till::<&str, &str, Error<&str>>(|c| c != ",");
|
|
||||||
if let Ok((still, before)) = extract(addr) {
|
|
||||||
if let Ok((still, after)) = extract(addr) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Address::Null
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
fn check_address(c: char) -> bool {
|
fn check_address(c: char) -> bool {
|
||||||
c.is_digit(10) || c == '$' || c == ' ' || c == '.'
|
c.is_digit(10) || c == '$' || c == ' ' || c == '.'
|
||||||
}
|
}
|
||||||
|
@ -76,13 +62,11 @@ fn parse_line(input: &str) -> Result<Command, String> {
|
||||||
let tmp = (address, command).parse(input);
|
let tmp = (address, command).parse(input);
|
||||||
if let Ok((input, (a, c))) = tmp {
|
if let Ok((input, (a, c))) = tmp {
|
||||||
let addr = parse_address(a);
|
let addr = parse_address(a);
|
||||||
Ok(parse_command(c, addr))
|
parse_command(c, addr)
|
||||||
} else if let Err(Error((_, t))) = tmp {
|
} else if let Err(Error((_, t))) = tmp {
|
||||||
println!("?");
|
Err(String::from("Erreur de parsing"))
|
||||||
Err(String::from("bruh moment"))
|
|
||||||
} else {
|
} else {
|
||||||
println!("bruh");
|
Err(String::from("Grosse erreur"))
|
||||||
Err(String::from("bruh moment"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,13 +87,15 @@ fn main() {
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
match io::stdin().read_line(&mut input) {
|
match io::stdin().read_line(&mut input) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
if let Ok(c) = parse_line(&input) {
|
let result_parse = parse_line(&input);
|
||||||
|
if let Ok(c) = result_parse {
|
||||||
let tmp = execute_command(&mut buffer_struct, c);
|
let tmp = execute_command(&mut buffer_struct, c);
|
||||||
if tmp {
|
if tmp {
|
||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Err(e) = result_parse {
|
||||||
//println!("coucou");
|
println!("?");
|
||||||
|
println!("{}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => println!("error"),
|
Err(e) => println!("error"),
|
||||||
|
|
Loading…
Reference in a new issue