generated from ElnuDev/rust-project
Improve error handling for Eat optional parameter
This commit is contained in:
parent
247ce0ce98
commit
59f0f8258a
1 changed files with 7 additions and 2 deletions
|
@ -140,6 +140,11 @@ fn parse_file(file_path: PathBuf) -> Vec<Command> {
|
||||||
let token_lines = tokenize_file(file_path);
|
let token_lines = tokenize_file(file_path);
|
||||||
let mut commands = Vec::new();
|
let mut commands = Vec::new();
|
||||||
for line in token_lines {
|
for line in token_lines {
|
||||||
|
macro_rules! unknown {
|
||||||
|
() => {
|
||||||
|
panic!("Unknown command {}", describe_line(&line))
|
||||||
|
};
|
||||||
|
}
|
||||||
commands.push(match line.as_slice() {
|
commands.push(match line.as_slice() {
|
||||||
[Str(text)] => Say {
|
[Str(text)] => Say {
|
||||||
name: None,
|
name: None,
|
||||||
|
@ -153,10 +158,10 @@ fn parse_file(file_path: PathBuf) -> Vec<Command> {
|
||||||
food: food.to_owned(),
|
food: food.to_owned(),
|
||||||
politely: match tail {
|
politely: match tail {
|
||||||
[Boolean(politely)] => *politely,
|
[Boolean(politely)] => *politely,
|
||||||
_ => false,
|
_ => unknown!(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_ => panic!("Unknown command {}", describe_line(&line)),
|
_ => unknown!(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
commands
|
commands
|
||||||
|
|
Loading…
Add table
Reference in a new issue