diff --git a/schala-repl/src/command_tree.rs b/schala-repl/src/command_tree.rs index d84fc7d..9d94f6e 100644 --- a/schala-repl/src/command_tree.rs +++ b/schala-repl/src/command_tree.rs @@ -89,7 +89,7 @@ impl CommandTree { pub fn perform( &self, repl: &mut Repl, - arguments: &Vec<&str>, + arguments: &[&str], ) -> InterpreterDirectiveOutput { let mut dir_pointer: &CommandTree = self; let mut idx = 0; @@ -103,7 +103,7 @@ impl CommandTree { } => { let next_command = match arguments.get(idx) { Some(cmd) => cmd, - None => break Err(format!("Command requires arguments")), + None => break Err("Command requires arguments".to_owned()), }; idx += 1; match subcommands.iter().find(|sc| sc.get_cmd() == *next_command) { diff --git a/schala-repl/src/directive_actions.rs b/schala-repl/src/directive_actions.rs index a1fb5d9..00aade5 100644 --- a/schala-repl/src/directive_actions.rs +++ b/schala-repl/src/directive_actions.rs @@ -1,6 +1,6 @@ use crate::help::help; use crate::language::{ - DebugAsk, DebugResponse, LangMetaRequest, LangMetaResponse, ProgrammingLanguageInterface, + LangMetaRequest, LangMetaResponse, ProgrammingLanguageInterface, }; use crate::{InterpreterDirectiveOutput, Repl}; use std::fmt::Write as FmtWrite; @@ -11,9 +11,6 @@ pub enum DirectiveAction { Help, QuitProgram, ListPasses, - ShowImmediate, - Show, - Hide, TotalTimeOff, TotalTimeOn, StageTimeOff, @@ -45,7 +42,7 @@ impl DirectiveAction { }; let mut buf = String::new(); - for pass in pass_names.iter().map(|name| Some(name)).intersperse(None) { + for pass in pass_names.iter().map(Some).intersperse(None) { match pass { Some(pass) => write!(buf, "{}", pass).unwrap(), None => write!(buf, " -> ").unwrap(), @@ -53,60 +50,6 @@ impl DirectiveAction { } Some(buf) } - ShowImmediate => { - let stage_name = match arguments.get(0) { - Some(s) => s.to_string(), - None => return Some(format!("Must specify a thing to debug")), - }; - let meta = LangMetaRequest::ImmediateDebug(DebugAsk::ByStage { - stage_name: stage_name.clone(), - token: None, - }); - let meta_response = repl.language_state.request_meta(meta); - - let response = match meta_response { - LangMetaResponse::ImmediateDebug(DebugResponse { ask, value }) => match ask { - DebugAsk::ByStage { - stage_name: ref this_stage_name, - .. - } if *this_stage_name == stage_name => value, - _ => return Some(format!("Wrong debug stage")), - }, - _ => return Some(format!("Invalid language meta response")), - }; - Some(response) - } - Show => { - let this_stage_name = match arguments.get(0) { - Some(s) => s.to_string(), - None => return Some(format!("Must specify a stage to show")), - }; - let token = arguments.get(1).map(|s| s.to_string()); - repl.options.debug_asks.retain(|ask| match ask { - DebugAsk::ByStage { stage_name, .. } if *stage_name == this_stage_name => false, - _ => true, - }); - - let ask = DebugAsk::ByStage { - stage_name: this_stage_name, - token, - }; - repl.options.debug_asks.insert(ask); - None - } - Hide => { - let stage_name_to_remove = match arguments.get(0) { - Some(s) => s.to_string(), - None => return Some(format!("Must specify a stage to hide")), - }; - repl.options.debug_asks.retain(|ask| match ask { - DebugAsk::ByStage { stage_name, .. } if *stage_name == stage_name_to_remove => { - false - } - _ => true, - }); - None - } TotalTimeOff => { repl.options.show_total_time = false; None @@ -139,8 +82,8 @@ fn doc( let meta = LangMetaRequest::Docs { source }; match repl.language_state.request_meta(meta) { LangMetaResponse::Docs { doc_string } => Some(doc_string), - _ => Some(format!("Invalid doc response")), + _ => Some("Invalid doc response".to_owned()), } }) - .unwrap_or(Some(format!(":docs needs an argument"))) + .unwrap_or_else(|| Some(":docs needs an argument".to_owned())) } diff --git a/schala-repl/src/directives.rs b/schala-repl/src/directives.rs index 8fa073f..4e1c86d 100644 --- a/schala-repl/src/directives.rs +++ b/schala-repl/src/directives.rs @@ -1,7 +1,7 @@ use crate::command_tree::CommandTree; use crate::directive_actions::DirectiveAction; -pub fn directives_from_pass_names(pass_names: &Vec) -> CommandTree { +pub fn directives_from_pass_names(pass_names: &[String]) -> CommandTree { let passes_directives: Vec = pass_names .iter() .map(|pass_name| { @@ -23,7 +23,7 @@ pub fn directives_from_pass_names(pass_names: &Vec) -> CommandTree { CommandTree::Top(get_list(&passes_directives, true)) } -fn get_list(passes_directives: &Vec, include_help: bool) -> Vec { +fn get_list(passes_directives: &[CommandTree], include_help: bool) -> Vec { use DirectiveAction::*; vec![ @@ -50,24 +50,6 @@ fn get_list(passes_directives: &Vec, include_help: bool) -> Vec( arguments: &[&str], ) -> InterpreterDirectiveOutput { match arguments { - [] => return global_help(repl), + [] => global_help(repl), commands => { let dirs = repl.get_directives(); Some(match get_directive_from_commands(commands, &dirs) { @@ -73,7 +73,7 @@ fn global_help(repl: &mut Repl) -> Interpret .unwrap(); } - writeln!(buf, "").unwrap(); + writeln!(buf).unwrap(); writeln!( buf, "Language-specific help for {}", diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 993f120..b7923a0 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -10,7 +10,7 @@ pub trait ProgrammingLanguageInterface { fn request_meta(&mut self, _request: LangMetaRequest) -> LangMetaResponse { LangMetaResponse::Custom { - kind: format!("not-implemented"), + kind: "not-implemented".to_owned(), value: format!(""), } } @@ -50,15 +50,6 @@ pub enum DebugAsk { }, } -impl DebugAsk { - pub fn is_for_stage(&self, name: &str) -> bool { - match self { - DebugAsk::ByStage { stage_name, .. } if stage_name == name => true, - _ => false, - } - } -} - pub struct DebugResponse { pub ask: DebugAsk, pub value: String, diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index d73318d..f738484 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -29,10 +29,10 @@ pub use language::{ }; include!(concat!(env!("OUT_DIR"), "/static.rs")); -const VERSION_STRING: &'static str = "0.1.0"; +const VERSION_STRING: &str = "0.1.0"; -const HISTORY_SAVE_FILE: &'static str = ".schala_history"; -const OPTIONS_SAVE_FILE: &'static str = ".schala_repl"; +const HISTORY_SAVE_FILE: &str = ".schala_history"; +const OPTIONS_SAVE_FILE: &str = ".schala_repl"; type InterpreterDirectiveOutput = Option; @@ -112,7 +112,7 @@ impl Repl { self.line_reader.add_history_unique(input.to_string()); let mut chars = input.chars().peekable(); - let repl_responses = match chars.nth(0) { + let repl_responses = match chars.next() { Some(ch) if ch == self.sigil => { if chars.peek() == Some(&'{') { let mut buf = String::new(); @@ -125,14 +125,13 @@ impl Repl { break 'multiline; } else { buf.push_str(new_input); - buf.push_str("\n"); + buf.push('\n'); } } self.handle_input(&buf) } else { - match self.handle_interpreter_directive(input.get(1..).unwrap()) { - Some(directive_output) => println!("{}", directive_output), - None => (), + if let Some(output) = self.handle_interpreter_directive(input.get(1..).unwrap()) { + println!("{}", output); } continue; } @@ -159,7 +158,7 @@ impl Repl { PromptStyle::Multiline => ">| ", }; - self.line_reader.set_prompt(&prompt_str).unwrap(); + self.line_reader.set_prompt(prompt_str).unwrap(); } fn save_before_exit(&self) { @@ -172,7 +171,7 @@ impl Repl { fn handle_interpreter_directive(&mut self, input: &str) -> InterpreterDirectiveOutput { let arguments: Vec<&str> = input.split_whitespace().collect(); - if arguments.len() < 1 { + if arguments.is_empty() { return None; } @@ -245,14 +244,11 @@ impl Completer for TabCompleteHandler { loop { match words.next() { None => { - let top = match command_tree { - Some(CommandTree::Top(_)) => true, - _ => false, - }; + let top = matches!(command_tree, Some(CommandTree::Top(_))); let word = if top { word.get(1..).unwrap() } else { word }; for cmd in command_tree .map(|x| x.get_subcommands()) - .unwrap_or(vec![]) + .unwrap_or_default() .into_iter() { if cmd.starts_with(word) {