Working on directives
This commit is contained in:
parent
78d1e93e4b
commit
3987360f8e
@ -3,14 +3,9 @@ use itertools::Itertools;
|
|||||||
|
|
||||||
use crate::repl::Repl;
|
use crate::repl::Repl;
|
||||||
use crate::repl::command_tree::CommandTree;
|
use crate::repl::command_tree::CommandTree;
|
||||||
use crate::language::{ProgrammingLanguageInterface, LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse};
|
use crate::language::{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![],
|
|
||||||
};
|
|
||||||
|
|
||||||
|
pub fn directives_from_pass_names(pass_names: &Vec<String>) -> CommandTree {
|
||||||
let passes_directives: Vec<CommandTree> = pass_names.iter()
|
let passes_directives: Vec<CommandTree> = pass_names.iter()
|
||||||
.map(|pass_name| { CommandTree::nonterm_no_further_tab_completions(pass_name, None) })
|
.map(|pass_name| { CommandTree::nonterm_no_further_tab_completions(pass_name, None) })
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -5,14 +5,14 @@ use std::collections::HashSet;
|
|||||||
use colored::*;
|
use colored::*;
|
||||||
use crate::language::{ProgrammingLanguageInterface,
|
use crate::language::{ProgrammingLanguageInterface,
|
||||||
ComputationRequest, ComputationResponse,
|
ComputationRequest, ComputationResponse,
|
||||||
DebugAsk};
|
DebugAsk, LangMetaResponse, LangMetaRequest};
|
||||||
|
|
||||||
mod command_tree;
|
mod command_tree;
|
||||||
use self::command_tree::{CommandTree, BoxedCommandFunction};
|
use self::command_tree::{CommandTree, BoxedCommandFunction};
|
||||||
mod repl_options;
|
mod repl_options;
|
||||||
use repl_options::ReplOptions;
|
use repl_options::ReplOptions;
|
||||||
mod directives;
|
mod directives;
|
||||||
use directives::get_directives;
|
use directives::directives_from_pass_names;
|
||||||
|
|
||||||
const HISTORY_SAVE_FILE: &'static str = ".schala_history";
|
const HISTORY_SAVE_FILE: &'static str = ".schala_history";
|
||||||
const OPTIONS_SAVE_FILE: &'static str = ".schala_repl";
|
const OPTIONS_SAVE_FILE: &'static str = ".schala_repl";
|
||||||
@ -22,19 +22,26 @@ pub struct Repl {
|
|||||||
line_reader: ::linefeed::interface::Interface<::linefeed::terminal::DefaultTerminal>,
|
line_reader: ::linefeed::interface::Interface<::linefeed::terminal::DefaultTerminal>,
|
||||||
language_states: Vec<Box<ProgrammingLanguageInterface>>,
|
language_states: Vec<Box<ProgrammingLanguageInterface>>,
|
||||||
options: ReplOptions,
|
options: ReplOptions,
|
||||||
|
directives: CommandTree,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Repl {
|
impl Repl {
|
||||||
pub fn new(initial_states: Vec<Box<ProgrammingLanguageInterface>>) -> Repl {
|
pub fn new(mut initial_states: Vec<Box<ProgrammingLanguageInterface>>) -> Repl {
|
||||||
use linefeed::Interface;
|
use linefeed::Interface;
|
||||||
let line_reader = Interface::new("schala-repl").unwrap();
|
let line_reader = Interface::new("schala-repl").unwrap();
|
||||||
let interpreter_directive_sigil = ':';
|
let interpreter_directive_sigil = ':';
|
||||||
|
|
||||||
|
let pass_names = match initial_states[0].request_meta(LangMetaRequest::StageNames) {
|
||||||
|
LangMetaResponse::StageNames(names) => names,
|
||||||
|
_ => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
Repl {
|
Repl {
|
||||||
interpreter_directive_sigil,
|
interpreter_directive_sigil,
|
||||||
line_reader,
|
line_reader,
|
||||||
language_states: initial_states,
|
language_states: initial_states,
|
||||||
options: ReplOptions::new(),
|
options: ReplOptions::new(),
|
||||||
|
directives: directives_from_pass_names(&pass_names)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +91,7 @@ impl Repl {
|
|||||||
|
|
||||||
fn update_line_reader(&mut self) {
|
fn update_line_reader(&mut self) {
|
||||||
let tab_complete_handler = TabCompleteHandler::new(self.interpreter_directive_sigil, self.get_directives());
|
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!(">> ");
|
let prompt_str = format!(">> ");
|
||||||
self.line_reader.set_prompt(&prompt_str).unwrap();
|
self.line_reader.set_prompt(&prompt_str).unwrap();
|
||||||
}
|
}
|
||||||
@ -222,7 +229,12 @@ impl Repl {
|
|||||||
|
|
||||||
fn get_directives(&mut self) -> CommandTree {
|
fn get_directives(&mut self) -> CommandTree {
|
||||||
let language_state = self.get_cur_language_state();
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user