Working on directives

This commit is contained in:
greg 2019-06-01 13:11:07 -07:00
parent 78d1e93e4b
commit 3987360f8e
2 changed files with 19 additions and 12 deletions

View File

@ -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<ProgrammingLanguageInterface>) -> 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<String>) -> CommandTree {
let passes_directives: Vec<CommandTree> = pass_names.iter()
.map(|pass_name| { CommandTree::nonterm_no_further_tab_completions(pass_name, None) })
.collect();

View File

@ -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<Box<ProgrammingLanguageInterface>>,
options: ReplOptions,
directives: CommandTree,
}
impl Repl {
pub fn new(initial_states: Vec<Box<ProgrammingLanguageInterface>>) -> Repl {
pub fn new(mut initial_states: Vec<Box<ProgrammingLanguageInterface>>) -> 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)
}
}