Generate commandtree on repl

This commit is contained in:
greg 2018-07-02 02:46:07 -07:00
parent 947f4f2ea6
commit 17a4028185

View File

@ -165,22 +165,9 @@ use linefeed::complete::{Completion, Completer};
use linefeed::terminal::Terminal; use linefeed::terminal::Terminal;
impl TabCompleteHandler { impl TabCompleteHandler {
fn new(sigil: char, passes: Vec<String>) -> TabCompleteHandler { fn new(sigil: char, top_level_commands: CommandTree) -> TabCompleteHandler {
TabCompleteHandler { TabCompleteHandler {
top_level_commands: CommandTree::Top(vec![ top_level_commands,
CommandTree::term("exit"),
CommandTree::term("quit"),
CommandTree::NonTerminal(format!("debug"), vec![
CommandTree::term("passes"),
CommandTree::NonTerminal(format!("show"), passes.iter().map(|p| CommandTree::term(p)).collect()),
CommandTree::NonTerminal(format!("hide"), passes.iter().map(|p| CommandTree::term(p)).collect()),
]),
CommandTree::NonTerminal(format!("lang"), vec![
CommandTree::term("next"),
CommandTree::term("prev"),
CommandTree::NonTerminal(format!("go"), vec![])//TODO
]),
]),
sigil, sigil,
} }
} }
@ -295,8 +282,8 @@ impl Repl {
loop { loop {
let language_name = self.languages[self.current_language_index].get_language_name(); let language_name = self.languages[self.current_language_index].get_language_name();
let directives = self.get_directives(&self.get_cur_language().get_passes());
let tab_complete_handler = TabCompleteHandler::new(self.interpreter_directive_sigil, self.get_cur_language().get_passes()); let tab_complete_handler = TabCompleteHandler::new(self.interpreter_directive_sigil, directives);
self.line_reader.set_completer(std::sync::Arc::new(tab_complete_handler)); self.line_reader.set_completer(std::sync::Arc::new(tab_complete_handler));
let prompt_str = format!("{} >> ", language_name); let prompt_str = format!("{} >> ", language_name);
@ -332,6 +319,23 @@ impl Repl {
interpreter_output.to_repl() interpreter_output.to_repl()
} }
fn get_directives(&self, passes: &Vec<String>) -> CommandTree {
CommandTree::Top(vec![
CommandTree::term("exit"),
CommandTree::term("quit"),
CommandTree::NonTerminal(format!("debug"), vec![
CommandTree::term("passes"),
CommandTree::NonTerminal(format!("show"), passes.iter().map(|p| CommandTree::term(p)).collect()),
CommandTree::NonTerminal(format!("hide"), passes.iter().map(|p| CommandTree::term(p)).collect()),
]),
CommandTree::NonTerminal(format!("lang"), vec![
CommandTree::term("next"),
CommandTree::term("prev"),
CommandTree::NonTerminal(format!("go"), vec![])//TODO
]),
])
}
fn handle_interpreter_directive(&mut self, input: &str) -> Option<String> { fn handle_interpreter_directive(&mut self, input: &str) -> Option<String> {
let mut iter = input.chars(); let mut iter = input.chars();
iter.next(); iter.next();