From fc7c86be1ac5343b12123535221f819eb1be38a9 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 15 Oct 2018 21:46:27 -0700 Subject: [PATCH] nonterminal() constructor function --- schala-repl/src/repl/command_tree.rs | 10 ++++++++ schala-repl/src/repl/mod.rs | 37 +++++++++++++++------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/schala-repl/src/repl/command_tree.rs b/schala-repl/src/repl/command_tree.rs index e742c1d..4ba5167 100644 --- a/schala-repl/src/repl/command_tree.rs +++ b/schala-repl/src/repl/command_tree.rs @@ -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::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(), diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index 1d81c59..b288c68 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -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")), ]) }