Fix bugs in interpreter argument parsing

This commit is contained in:
greg 2017-02-02 02:12:28 -08:00
parent ecf60198fa
commit 387ec25cda

View File

@ -192,8 +192,8 @@ impl Repl {
} }
}, },
"lang" => { "lang" => {
match commands[1] { match commands.get(1) {
"show" => { Some(&"show") => {
for (i, lang) in self.languages.iter().enumerate() { for (i, lang) in self.languages.iter().enumerate() {
if i == self.current_language_index { if i == self.current_language_index {
println!("* {}", lang.get_language_name()); println!("* {}", lang.get_language_name());
@ -202,33 +202,42 @@ impl Repl {
} }
} }
}, },
"next" => { Some(&"next") => {
self.current_language_index = (self.current_language_index + 1) % self.languages.len(); self.current_language_index = (self.current_language_index + 1) % self.languages.len();
} }
"prev" | "previous" => { Some(&"prev") | Some(&"previous") => {
self.current_language_index = if self.current_language_index == 0 { self.languages.len() - 1 } else { self.current_language_index - 1 } self.current_language_index = if self.current_language_index == 0 { self.languages.len() - 1 } else { self.current_language_index - 1 }
}, },
e => println!("Bad `lang` argument: {}", e), Some(e) => println!("Bad `lang` argument: {}", e),
None => println!("`lang` - valid arguments `show`, `next`, `prev`|`previous`"),
} }
}, },
"set" => { "set" => {
let show = match commands[1] { let show = match commands.get(1) {
"show" => true, Some(&"show") => true,
"hide" => false, Some(&"hide") => false,
e => { Some(e) => {
println!("Bad `set` argument: {}", e); println!("Bad `set` argument: {}", e);
return true; return true;
} }
None => {
println!("`set` - valid arguments `show {{option}}`, `hide {{option}}`");
return true;
}
}; };
match commands[2] { match commands.get(2) {
"tokens" => self.show_tokens = show, Some(&"tokens") => self.show_tokens = show,
"parse" => self.show_parse = show, Some(&"parse") => self.show_parse = show,
"eval" => { /*self.evaluator.set_option("trace_evaluation", show);*/ }, Some(&"eval") => { /*self.evaluator.set_option("trace_evaluation", show);*/ },
"llvm" => self.show_llvm_ir = show, Some(&"llvm") => self.show_llvm_ir = show,
e => { Some(e) => {
println!("Bad `show`/`hide` argument: {}", e); println!("Bad `show`/`hide` argument: {}", e);
return true; return true;
} }
None => {
println!("`show`/`hide` requires an argument");
return true;
}
} }
}, },
e => println!("Unknown command: {}", e) e => println!("Unknown command: {}", e)