From ecf60198faf0d7c86cdaea6ccc3663e78702946b Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 2 Feb 2017 02:00:26 -0800 Subject: [PATCH] Can now switch between languages in the interpreter --- src/main.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 3fa1518..76762ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,6 +115,7 @@ struct Repl { show_parse: bool, show_llvm_ir: bool, languages: Vec>, + current_language_index: usize, interpreter_directive_sigil: char, reader: LineReader, } @@ -129,6 +130,7 @@ impl Repl { show_parse: false, show_llvm_ir: false, languages: languages, + current_language_index: 0, interpreter_directive_sigil: '.', reader: reader, } @@ -159,7 +161,7 @@ impl Repl { } fn input_handler(&mut self, input: &str) -> String { - let ref mut language = self.languages[0]; + let ref mut language = self.languages[self.current_language_index]; language.evaluate_in_repl(input, language::LanguageInterfaceOptions::default()) } @@ -189,6 +191,26 @@ impl Repl { println!("{}", item); } }, + "lang" => { + match commands[1] { + "show" => { + for (i, lang) in self.languages.iter().enumerate() { + if i == self.current_language_index { + println!("* {}", lang.get_language_name()); + } else { + println!("{}", lang.get_language_name()); + } + } + }, + "next" => { + self.current_language_index = (self.current_language_index + 1) % self.languages.len(); + } + "prev" | "previous" => { + self.current_language_index = if self.current_language_index == 0 { self.languages.len() - 1 } else { self.current_language_index - 1 } + }, + e => println!("Bad `lang` argument: {}", e), + } + }, "set" => { let show = match commands[1] { "show" => true,