Start adding commandtree abstraction

This commit is contained in:
greg 2019-03-14 21:25:37 -07:00
parent 6d88447458
commit 57f3d39ea1
1 changed files with 31 additions and 2 deletions

View File

@ -93,7 +93,33 @@ impl Repl {
}
fn handle_interpreter_directive(&mut self, input: &str) -> Option<String> {
Some(format!("you typed {}, which is unsupported", input))
let mut iter = input.chars();
iter.next();
let commands: Vec<&str> = iter
.as_str()
.split_whitespace()
.collect();
if commands.len() < 1 {
return None;
}
let directives = self.get_directives();
let mut dir_pointer: &CommandTree = &directives;
for command in commands.iter() {
match dir_pointer {
CommandTree::Top(subcommands) | CommandTree::NonTerminal { children: subcommands, .. } => {
let q = subcommands;
},
CommandTree::Terminal { name, .. } => {
}
}
}
Some(format!("you typed {:?}", commands))
}
fn get_cur_language_state(&mut self) -> &mut Box<ProgrammingLanguageInterface> {
@ -141,7 +167,10 @@ impl Repl {
*/
CommandTree::Top(vec![
CommandTree::term("exit", Some("exit the REPL")),
CommandTree::term_with_function("exit", Some("exit the REPL"), Box::new(|repl: &mut Repl, cmds: Vec<String>| {
repl.save_before_exit();
::std::process::exit(0)
})),
CommandTree::term_with_function("quit", Some("exit the REPL"), Box::new(|repl: &mut Repl, cmds: Vec<String>| {
repl.save_before_exit();
::std::process::exit(0)