Show debug stages

This commit is contained in:
greg 2018-05-01 02:24:50 -07:00
parent aaf98db2b7
commit 27885500fd
2 changed files with 22 additions and 1 deletions

View File

@ -111,4 +111,14 @@ impl ProgrammingLanguageInterface for Schala {
]; ];
chain(input) chain(input)
} }
fn get_stages(&self) -> Vec<String> {
vec![
format!("tokenizing"),
format!("parsing"), //TODO handle both types of this
format!("symbol_table"),
format!("typechecking"),
format!("eval")
]
}
} }

View File

@ -22,6 +22,7 @@ use std::process::exit;
use std::default::Default; use std::default::Default;
use std::fmt::Write as FmtWrite; use std::fmt::Write as FmtWrite;
use itertools::Itertools;
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::Editor; use rustyline::Editor;
use self::colored::*; use self::colored::*;
@ -148,6 +149,10 @@ impl Repl {
} }
} }
fn get_cur_language(&self) -> &ProgrammingLanguageInterface {
self.languages[self.current_language_index].as_ref()
}
fn get_options() -> EvalOptions { fn get_options() -> EvalOptions {
File::open(".schala_repl") File::open(".schala_repl")
.and_then(|mut file| { .and_then(|mut file| {
@ -284,14 +289,20 @@ impl Repl {
} }
} }
fn handle_debug(&mut self, commands: Vec<&str>) -> Option<String> { fn handle_debug(&mut self, commands: Vec<&str>) -> Option<String> {
let stages = self.get_cur_language().get_stages();
match commands.get(1) { match commands.get(1) {
Some(&"stages") => Some(stages.into_iter().intersperse(format!(" -> ")).collect()),
b @ Some(&"show") | b @ Some(&"hide") => { b @ Some(&"show") | b @ Some(&"hide") => {
let show = b == Some(&"show"); let show = b == Some(&"show");
let debug_stage = match commands.get(2) { let debug_stage = match commands.get(2) {
Some(s) => s, Some(s) => s,
None => return Some(format!("Must specify a stage to debug")), None => return Some(format!("Must specify a stage to debug")),
}; };
None let maybe_debug = stages.iter().find(|stage_name| stage_name == debug_stage);
match maybe_debug {
Some(s) => Some(format!("Will debug {}", s)),
None => Some(format!("couldn't find it"))
}
}, },
_ => Some(format!("Unknown debug command")) _ => Some(format!("Unknown debug command"))
} }