schala/schala-repl/src/repl/directives.rs

56 lines
2.5 KiB
Rust
Raw Normal View History

2019-06-02 00:27:12 -07:00
use crate::repl::command_tree::CommandTree;
use crate::repl::directive_actions::DirectiveAction;
2019-06-01 13:11:07 -07:00
pub fn directives_from_pass_names(pass_names: &Vec<String>) -> CommandTree {
2019-05-22 03:32:00 -07:00
let passes_directives: Vec<CommandTree> = pass_names.iter()
2019-06-22 12:13:43 -07:00
.map(|pass_name| {
if pass_name == "parsing" {
CommandTree::nonterm(pass_name, None, vec![
CommandTree::nonterm_no_further_tab_completions("compact", None),
CommandTree::nonterm_no_further_tab_completions("expanded", None),
CommandTree::nonterm_no_further_tab_completions("trace", None),
])
} else {
CommandTree::nonterm_no_further_tab_completions(pass_name, None)
}
})
2019-05-22 03:32:00 -07:00
.collect();
2019-06-05 02:48:45 -07:00
CommandTree::Top(get_list(&passes_directives, true))
}
2019-05-22 03:32:00 -07:00
2019-06-05 02:48:45 -07:00
fn get_list(passes_directives: &Vec<CommandTree>, include_help: bool) -> Vec<CommandTree> {
use DirectiveAction::*;
vec![
2019-06-02 00:48:59 -07:00
CommandTree::terminal("exit", Some("exit the REPL"), vec![], QuitProgram),
CommandTree::terminal("quit", Some("exit the REPL"), vec![], QuitProgram),
2019-06-05 02:48:45 -07:00
CommandTree::terminal("help", Some("Print this help message"), if include_help { get_list(passes_directives, false) } else { vec![] }, Help),
2019-05-22 03:32:00 -07:00
CommandTree::nonterm("debug",
Some("Configure debug information"),
vec![
2019-06-02 00:48:59 -07:00
CommandTree::terminal("list-passes", Some("List all registered compiler passes"), vec![], ListPasses),
CommandTree::terminal("show-immediate", None, passes_directives.clone(), ShowImmediate),
2019-06-05 02:36:08 -07:00
CommandTree::terminal("show", Some("Show debug output for a specific pass"), passes_directives.clone(), Show),
CommandTree::terminal("hide", Some("Hide debug output for a specific pass"), passes_directives.clone(), Hide),
2019-05-22 03:32:00 -07:00
CommandTree::nonterm("total-time", None, vec![
2019-06-02 00:48:59 -07:00
CommandTree::terminal("on", None, vec![], TotalTimeOn),
CommandTree::terminal("off", None, vec![], TotalTimeOff),
2019-05-25 22:21:52 -07:00
]),
CommandTree::nonterm("stage-times", Some("Computation time per-stage"), vec![
2019-06-02 00:48:59 -07:00
CommandTree::terminal("on", None, vec![], StageTimeOn),
CommandTree::terminal("off", None, vec![], StageTimeOff),
2019-05-22 03:32:00 -07:00
])
]
),
CommandTree::nonterm("lang",
Some("switch between languages, or go directly to a langauge by name"),
vec![
CommandTree::nonterm_no_further_tab_completions("next", None),
CommandTree::nonterm_no_further_tab_completions("prev", None),
CommandTree::nonterm("go", None, vec![]),
]
),
2019-06-02 00:48:59 -07:00
CommandTree::terminal("doc", Some("Get language-specific help for an item"), vec![], Doc),
2019-06-05 02:48:45 -07:00
]
2019-05-22 03:32:00 -07:00
}