From 17a40281856a330f5cf0b4cba31732f8eeaebcd4 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 2 Jul 2018 02:46:07 -0700 Subject: [PATCH] Generate commandtree on repl --- schala-repl/src/lib.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index 2709f56..50243d5 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -165,22 +165,9 @@ use linefeed::complete::{Completion, Completer}; use linefeed::terminal::Terminal; impl TabCompleteHandler { - fn new(sigil: char, passes: Vec) -> TabCompleteHandler { + fn new(sigil: char, top_level_commands: CommandTree) -> TabCompleteHandler { TabCompleteHandler { - top_level_commands: 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 - ]), - ]), + top_level_commands, sigil, } } @@ -295,8 +282,8 @@ impl Repl { loop { let language_name = self.languages[self.current_language_index].get_language_name(); - - let tab_complete_handler = TabCompleteHandler::new(self.interpreter_directive_sigil, self.get_cur_language().get_passes()); + let directives = self.get_directives(&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)); let prompt_str = format!("{} >> ", language_name); @@ -332,6 +319,23 @@ impl Repl { interpreter_output.to_repl() } + fn get_directives(&self, passes: &Vec) -> 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 { let mut iter = input.chars(); iter.next();