nonterminal() constructor function

This commit is contained in:
greg 2018-10-15 21:46:27 -07:00
parent 77e0d639c2
commit fc7c86be1a
2 changed files with 30 additions and 17 deletions

View File

@ -19,6 +19,16 @@ impl CommandTree {
pub fn term(s: &str, help: Option<&str>) -> CommandTree { pub fn term(s: &str, help: Option<&str>) -> CommandTree {
CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: None } CommandTree::Terminal {name: s.to_string(), help_msg: help.map(|x| x.to_string()), function: None }
} }
pub fn nonterm(s: &str, help: Option<&str>, children: Vec<CommandTree>) -> CommandTree {
CommandTree::NonTerminal {
name: s.to_string(),
help_msg: help.map(|x| x.to_string()),
children,
function: None,
}
}
pub fn get_cmd(&self) -> &str { pub fn get_cmd(&self) -> &str {
match self { match self {
CommandTree::Terminal { name, .. } => name.as_str(), CommandTree::Terminal { name, .. } => name.as_str(),

View File

@ -137,23 +137,26 @@ impl Repl {
CommandTree::term("exit", Some("exit the REPL")), CommandTree::term("exit", Some("exit the REPL")),
CommandTree::term("quit", Some("exit the REPL")), CommandTree::term("quit", Some("exit the REPL")),
CommandTree::term("help", Some("Print this help message")), CommandTree::term("help", Some("Print this help message")),
CommandTree::NonTerminal { name: format!("debug"), children: vec![ CommandTree::nonterm("debug",
CommandTree::term("passes", None), Some("show or hide pass debug info for a given pass, or display the names of all passes, or turn timing on/off"),
CommandTree::NonTerminal { name: format!("show"), children: passes_directives.clone(), help_msg: None, function: None }, vec![
CommandTree::NonTerminal{ name: format!("hide"), children: passes_directives.clone(), help_msg: None, function: None}, CommandTree::term("passes", None),
CommandTree::NonTerminal { name: format!("timing"), children: vec![ CommandTree::nonterm("show", None, passes_directives.clone()),
CommandTree::term("on", None), CommandTree::nonterm("hide", None, passes_directives.clone()),
CommandTree::term("off", None), CommandTree::nonterm("timing", None, vec![
], help_msg: None, function: None }, CommandTree::term("on", None),
], help_msg: Some(format!("show or hide pass debug info for a given pass, or display the names of all passes, or turn timing on/off")), CommandTree::term("off", None),
function: None ])
}, ]
CommandTree::NonTerminal{ name: format!("lang"), children: vec![ ),
CommandTree::term("next", None), CommandTree::nonterm("lang",
CommandTree::term("prev", None), Some("switch between languages, or go directly to a langauge by name"),
CommandTree::NonTerminal{ name: format!("go"), children: vec![], help_msg: None, function: None }, vec![
], help_msg: Some(format!("switch between languages, or go directly to a langauge by name")), CommandTree::term("next", None),
function: None }, CommandTree::term("prev", None),
CommandTree::nonterm("go", None, vec![]),
]
),
CommandTree::term("doc", Some("Get language-specific help for an item")), CommandTree::term("doc", Some("Get language-specific help for an item")),
]) ])
} }