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 {
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 {
match self {
CommandTree::Terminal { name, .. } => name.as_str(),

View File

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