From c52bc65bb9986c047973cdd383e19d131f8a0623 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 2 Oct 2018 01:37:43 -0700 Subject: [PATCH] Change NonTerminal format --- schala-repl/src/repl.rs | 49 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/schala-repl/src/repl.rs b/schala-repl/src/repl.rs index 058b7e7..0b3d841 100644 --- a/schala-repl/src/repl.rs +++ b/schala-repl/src/repl.rs @@ -120,13 +120,14 @@ impl Repl { if pass_descriptor.debug_options.len() == 0 { CommandTree::term(name, None) } else { - let sub_opts: Vec = pass_descriptor.debug_options.iter() + let children: Vec = 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 Completer 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, function: Option Option)>>, }, - NonTerminal(String, Vec, Option), + NonTerminal { + name: String, + children: Vec, + help_msg: Option, + function: Option Option)>>, + }, Top(Vec), } @@ -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(), } }