From 3987360f8e689fab8f5b07e60ab4c2f9a1538003 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 1 Jun 2019 13:11:07 -0700 Subject: [PATCH] Working on directives --- schala-repl/src/repl/directives.rs | 9 ++------- schala-repl/src/repl/mod.rs | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/schala-repl/src/repl/directives.rs b/schala-repl/src/repl/directives.rs index 5c7945c..191b252 100644 --- a/schala-repl/src/repl/directives.rs +++ b/schala-repl/src/repl/directives.rs @@ -3,14 +3,9 @@ use itertools::Itertools; use crate::repl::Repl; use crate::repl::command_tree::CommandTree; -use crate::language::{ProgrammingLanguageInterface, LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse}; - -pub fn get_directives(language_state: &mut Box) -> CommandTree { - let pass_names = match language_state.request_meta(LangMetaRequest::StageNames) { - LangMetaResponse::StageNames(names) => names, - _ => vec![], - }; +use crate::language::{LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse}; +pub fn directives_from_pass_names(pass_names: &Vec) -> CommandTree { let passes_directives: Vec = pass_names.iter() .map(|pass_name| { CommandTree::nonterm_no_further_tab_completions(pass_name, None) }) .collect(); diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 658a0ca..f3a1bc8 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -5,14 +5,14 @@ use std::collections::HashSet; use colored::*; use crate::language::{ProgrammingLanguageInterface, ComputationRequest, ComputationResponse, -DebugAsk}; +DebugAsk, LangMetaResponse, LangMetaRequest}; mod command_tree; use self::command_tree::{CommandTree, BoxedCommandFunction}; mod repl_options; use repl_options::ReplOptions; mod directives; -use directives::get_directives; +use directives::directives_from_pass_names; const HISTORY_SAVE_FILE: &'static str = ".schala_history"; const OPTIONS_SAVE_FILE: &'static str = ".schala_repl"; @@ -22,19 +22,26 @@ pub struct Repl { line_reader: ::linefeed::interface::Interface<::linefeed::terminal::DefaultTerminal>, language_states: Vec>, options: ReplOptions, + directives: CommandTree, } impl Repl { - pub fn new(initial_states: Vec>) -> Repl { + pub fn new(mut initial_states: Vec>) -> Repl { use linefeed::Interface; let line_reader = Interface::new("schala-repl").unwrap(); let interpreter_directive_sigil = ':'; + let pass_names = match initial_states[0].request_meta(LangMetaRequest::StageNames) { + LangMetaResponse::StageNames(names) => names, + _ => vec![], + }; + Repl { interpreter_directive_sigil, line_reader, language_states: initial_states, options: ReplOptions::new(), + directives: directives_from_pass_names(&pass_names) } } @@ -84,7 +91,7 @@ impl Repl { fn update_line_reader(&mut self) { let tab_complete_handler = TabCompleteHandler::new(self.interpreter_directive_sigil, self.get_directives()); - self.line_reader.set_completer(Arc::new(tab_complete_handler)); + self.line_reader.set_completer(Arc::new(tab_complete_handler)); //TODO fix this here let prompt_str = format!(">> "); self.line_reader.set_prompt(&prompt_str).unwrap(); } @@ -222,7 +229,12 @@ impl Repl { fn get_directives(&mut self) -> CommandTree { let language_state = self.get_cur_language_state(); - get_directives(language_state) + let pass_names = match language_state.request_meta(LangMetaRequest::StageNames) { + LangMetaResponse::StageNames(names) => names, + _ => vec![], + }; + + directives_from_pass_names(&pass_names) } }