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