Change NonTerminal format

This commit is contained in:
greg 2018-10-02 01:37:43 -07:00
parent 819c422cee
commit c52bc65bb9

View File

@ -120,13 +120,14 @@ impl Repl {
if pass_descriptor.debug_options.len() == 0 {
CommandTree::term(name, None)
} else {
let sub_opts: Vec<CommandTree> = pass_descriptor.debug_options.iter()
let children: Vec<CommandTree> = pass_descriptor.debug_options.iter()
.map(|o| CommandTree::term(o, None)).collect();
CommandTree::NonTerminal(
name.clone(),
sub_opts,
None
)
CommandTree::NonTerminal {
name: name.clone(),
children,
help_msg: None,
function: None,
}
}
}).collect();
@ -134,20 +135,23 @@ 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(format!("debug"), vec![
CommandTree::NonTerminal { name: format!("debug"), children: vec![
CommandTree::term("passes", None),
CommandTree::NonTerminal(format!("show"), passes_directives.clone(), None),
CommandTree::NonTerminal(format!("hide"), passes_directives.clone(), None),
CommandTree::NonTerminal(format!("timing"), vec![
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),
], None),
], 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::NonTerminal(format!("lang"), vec![
], 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(format!("go"), vec![], None)//TODO
], Some(format!("switch between languages, or go directly to a langauge by name"))),
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::term("doc", Some("Get language-specific help for an item")),
])
}
@ -329,7 +333,7 @@ impl<T: Terminal> Completer<T> for TabCompleteHandler {
Some(s) => {
let new_ptr: Option<&CommandTree> = command_tree.and_then(|cm| match cm {
CommandTree::Top(children) => children.iter().find(|c| c.get_cmd() == s),
CommandTree::NonTerminal(_, children, _) => children.iter().find(|c| c.get_cmd() == s),
CommandTree::NonTerminal { children, .. } => children.iter().find(|c| c.get_cmd() == s),
CommandTree::Terminal { .. } => None,
});
command_tree = new_ptr;
@ -350,7 +354,12 @@ enum CommandTree {
help_msg: Option<String>,
function: Option<Box<(fn() -> Option<String>)>>,
},
NonTerminal(String, Vec<CommandTree>, Option<String>),
NonTerminal {
name: String,
children: Vec<CommandTree>,
help_msg: Option<String>,
function: Option<Box<(fn() -> Option<String>)>>,
},
Top(Vec<CommandTree>),
}
@ -361,21 +370,21 @@ impl CommandTree {
fn get_cmd(&self) -> &str {
match self {
CommandTree::Terminal { name, .. } => name.as_str(),
CommandTree::NonTerminal(s, _, _) => s.as_str(),
CommandTree::NonTerminal {name, ..} => name.as_str(),
CommandTree::Top(_) => "",
}
}
fn get_help(&self) -> &str {
match self {
CommandTree::Terminal { help_msg, ..} => help_msg.as_ref().map(|s| s.as_str()).unwrap_or(""),
CommandTree::NonTerminal(_, _, h) => h.as_ref().map(|s| s.as_str()).unwrap_or(""),
CommandTree::NonTerminal { help_msg, .. } => help_msg.as_ref().map(|s| s.as_str()).unwrap_or(""),
CommandTree::Top(_) => ""
}
}
fn get_children(&self) -> Vec<&str> {
match self {
CommandTree::Terminal { .. } => vec![],
CommandTree::NonTerminal(_, children, _) => children.iter().map(|x| x.get_cmd()).collect(),
CommandTree::NonTerminal { children, .. } => children.iter().map(|x| x.get_cmd()).collect(),
CommandTree::Top(children) => children.iter().map(|x| x.get_cmd()).collect(),
}
}