From bb39c59db27c6c7896d39804512e0336be6ffecf Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 2 Jun 2019 00:48:59 -0700 Subject: [PATCH] directive-related cleanup --- schala-repl/src/repl/command_tree.rs | 12 ++---------- schala-repl/src/repl/directives.rs | 29 ++++++++++++---------------- schala-repl/src/repl/mod.rs | 2 +- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/schala-repl/src/repl/command_tree.rs b/schala-repl/src/repl/command_tree.rs index 0b70c8f..26eff90 100644 --- a/schala-repl/src/repl/command_tree.rs +++ b/schala-repl/src/repl/command_tree.rs @@ -2,19 +2,15 @@ use super::{Repl, InterpreterDirectiveOutput}; use crate::repl::directive_actions::DirectiveAction; use colored::*; -pub type BoxedCommandFunction = Box<(fn(&mut Repl, &[&str]) -> Option)>; - /// A CommandTree is either a `Terminal` or a `NonTerminal`. When command parsing reaches the first /// Terminal, it will use the `DirectiveAction` found there to find an appropriate function to execute, /// and then execute it with any remaining arguments -//TODO remove function: BoxedCommandFunction #[derive(Clone)] pub enum CommandTree { Terminal { name: String, children: Vec, help_msg: Option, - function: BoxedCommandFunction, action: DirectiveAction, }, NonTerminal { @@ -32,12 +28,8 @@ impl CommandTree { CommandTree::NonTerminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), children: vec![], action: DirectiveAction::Null } } - pub fn terminal(s: &str, help: Option<&str>, children: Vec, function: BoxedCommandFunction) -> CommandTree { - CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function, children, action: DirectiveAction::Null } - } - - pub fn terminal_act(s: &str, help: Option<&str>, children: Vec, action: DirectiveAction) -> CommandTree { - CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: Box::new(|_,_| { None }), children, action} + pub fn terminal(s: &str, help: Option<&str>, children: Vec, action: DirectiveAction) -> CommandTree { + CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), children, action} } pub fn nonterm(s: &str, help: Option<&str>, children: Vec) -> CommandTree { diff --git a/schala-repl/src/repl/directives.rs b/schala-repl/src/repl/directives.rs index 7a7b9e5..6633467 100644 --- a/schala-repl/src/repl/directives.rs +++ b/schala-repl/src/repl/directives.rs @@ -1,10 +1,5 @@ -use std::fmt::Write as FmtWrite; - -use crate::repl::Repl; use crate::repl::command_tree::CommandTree; use crate::repl::directive_actions::DirectiveAction; -use crate::language::{LangMetaRequest, LangMetaResponse, DebugAsk, DebugResponse}; - pub fn directives_from_pass_names(pass_names: &Vec) -> CommandTree { use DirectiveAction::*; @@ -14,23 +9,23 @@ pub fn directives_from_pass_names(pass_names: &Vec) -> CommandTree { .collect(); CommandTree::Top(vec![ - CommandTree::terminal_act("exit", Some("exit the REPL"), vec![], QuitProgram), - CommandTree::terminal_act("quit", Some("exit the REPL"), vec![], QuitProgram), - CommandTree::terminal_act("help", Some("Print this help message"), vec![], Help), + CommandTree::terminal("exit", Some("exit the REPL"), vec![], QuitProgram), + CommandTree::terminal("quit", Some("exit the REPL"), vec![], QuitProgram), + CommandTree::terminal("help", Some("Print this help message"), vec![], Help), CommandTree::nonterm("debug", Some("Configure debug information"), vec![ - CommandTree::terminal_act("list-passes", Some("List all registered compiler passes"), vec![], ListPasses), - CommandTree::terminal_act("show-immediate", None, passes_directives.clone(), ShowImmediate), - CommandTree::terminal_act("show", None, passes_directives.clone(), Show), - CommandTree::terminal_act("hide", None, passes_directives.clone(), Hide), + CommandTree::terminal("list-passes", Some("List all registered compiler passes"), vec![], ListPasses), + CommandTree::terminal("show-immediate", None, passes_directives.clone(), ShowImmediate), + CommandTree::terminal("show", None, passes_directives.clone(), Show), + CommandTree::terminal("hide", None, passes_directives.clone(), Hide), CommandTree::nonterm("total-time", None, vec![ - CommandTree::terminal_act("on", None, vec![], TotalTimeOn), - CommandTree::terminal_act("off", None, vec![], TotalTimeOff), + CommandTree::terminal("on", None, vec![], TotalTimeOn), + CommandTree::terminal("off", None, vec![], TotalTimeOff), ]), CommandTree::nonterm("stage-times", Some("Computation time per-stage"), vec![ - CommandTree::terminal_act("on", None, vec![], StageTimeOn), - CommandTree::terminal_act("off", None, vec![], StageTimeOff), + CommandTree::terminal("on", None, vec![], StageTimeOn), + CommandTree::terminal("off", None, vec![], StageTimeOff), ]) ] ), @@ -42,7 +37,7 @@ pub fn directives_from_pass_names(pass_names: &Vec) -> CommandTree { CommandTree::nonterm("go", None, vec![]), ] ), - CommandTree::terminal_act("doc", Some("Get language-specific help for an item"), vec![], Doc), + CommandTree::terminal("doc", Some("Get language-specific help for an item"), vec![], Doc), ]) } diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 48a03d4..9efeb83 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -8,7 +8,7 @@ ComputationRequest, ComputationResponse, DebugAsk, LangMetaResponse, LangMetaRequest}; mod command_tree; -use self::command_tree::{CommandTree, BoxedCommandFunction}; +use self::command_tree::CommandTree; mod repl_options; use repl_options::ReplOptions; mod directive_actions;