diff --git a/schala-repl/src/repl/command_tree.rs b/schala-repl/src/repl/command_tree.rs index 9832f87..605b989 100644 --- a/schala-repl/src/repl/command_tree.rs +++ b/schala-repl/src/repl/command_tree.rs @@ -6,25 +6,25 @@ pub type BoxedCommandFunction = Box<(fn(&mut Repl, &[&str]) -> Option)>; pub enum CommandTree { Terminal { name: String, + children: Vec, help_msg: Option, - function: Option, + function: BoxedCommandFunction, }, NonTerminal { name: String, children: Vec, help_msg: Option, - function: Option, }, Top(Vec), } impl CommandTree { - pub fn term(s: &str, help: Option<&str>) -> CommandTree { - CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: None } + pub fn nonterm_no_further_tab_completions(s: &str, help: Option<&str>) -> CommandTree { + CommandTree::NonTerminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), children: vec![] } } - pub fn term_with_function(s: &str, help: Option<&str>, func: BoxedCommandFunction) -> CommandTree { - CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: Some(func) } + pub fn term_with_function(s: &str, help: Option<&str>, function: BoxedCommandFunction) -> CommandTree { + CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function, children: vec![] } } pub fn nonterm(s: &str, help: Option<&str>, children: Vec) -> CommandTree { @@ -32,10 +32,10 @@ impl CommandTree { name: s.to_string(), help_msg: help.map(|x| x.to_string()), children, - function: None, } } + /* pub fn nonterm_with_function(s: &str, help: Option<&str>, children: Vec, func: BoxedCommandFunction) -> CommandTree { CommandTree::NonTerminal { name: s.to_string(), @@ -44,6 +44,7 @@ impl CommandTree { function: Some(func), } } + */ pub fn get_cmd(&self) -> &str { match self { diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 51bb3b4..86a25e2 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -112,11 +112,8 @@ impl Repl { }; }, CommandTree::Terminal { name, function, .. } => { - break match function.as_ref() { - Some(f) => Ok((f, idx)), - None => Err(format!("No action specified for: {:?}", commands)), - }; - } + break Ok((function, idx)); + }, } } } @@ -200,7 +197,7 @@ impl Repl { }; let passes_directives: Vec = pass_names.iter() - .map(|pass_name| { CommandTree::term(pass_name, None) }) + .map(|pass_name| { CommandTree::nonterm_no_further_tab_completions(pass_name, None) }) .collect(); CommandTree::Top(vec![ @@ -237,20 +234,20 @@ impl Repl { CommandTree::nonterm("show", None, passes_directives.clone()), CommandTree::nonterm("hide", None, passes_directives.clone()), CommandTree::nonterm("timing", None, vec![ - CommandTree::term("on", None), - CommandTree::term("off", None), + CommandTree::nonterm_no_further_tab_completions("on", None), + CommandTree::nonterm_no_further_tab_completions("off", None), ]) ] ), CommandTree::nonterm("lang", Some("switch between languages, or go directly to a langauge by name"), vec![ - CommandTree::term("next", None), - CommandTree::term("prev", None), + CommandTree::nonterm_no_further_tab_completions("next", None), + CommandTree::nonterm_no_further_tab_completions("prev", None), CommandTree::nonterm("go", None, vec![]), ] ), - CommandTree::term("doc", Some("Get language-specific help for an item")), + CommandTree::nonterm_no_further_tab_completions("doc", Some("Get language-specific help for an item")), ]) } } @@ -339,7 +336,7 @@ impl Completer for TabCompleteHandler { let new_ptr: Option<&CommandTree> = command_tree.and_then(|cm| match cm { CommandTree::Top(children) => children.iter().find(|c| c.get_cmd() == s), CommandTree::NonTerminal { children, .. } => children.iter().find(|c| c.get_cmd() == s), - CommandTree::Terminal { .. } => None, + CommandTree::Terminal { children, .. } => children.iter().find(|c| c.get_cmd() == s), }); command_tree = new_ptr; }