Debug stages from command line
This commit is contained in:
parent
7f21b70e3f
commit
c11ae3b50d
@ -86,7 +86,9 @@ impl ProgrammingLanguageInterface for Schala {
|
||||
match self.type_context.add_top_level_types(&ast) {
|
||||
Ok(()) => (),
|
||||
Err(msg) => {
|
||||
evaluation.add_artifact(TraceArtifact::new("type_check", msg));
|
||||
if options.debug.type_checking {
|
||||
evaluation.add_artifact(TraceArtifact::new("type_check", msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -111,7 +111,18 @@ impl FinishedComputation {
|
||||
}
|
||||
pub fn to_noninteractive(&self) -> Option<String> {
|
||||
match self.text_output {
|
||||
Ok(_) => None,
|
||||
Ok(_) => {
|
||||
let mut buf = String::new();
|
||||
for stage in ["tokens", "parse_trace", "ast", "symbol_table", "type_check"].iter() {
|
||||
if let Some(artifact) = self.artifacts.get(&stage.to_string()) {
|
||||
let color = artifact.text_color;
|
||||
let stage = stage.color(color).bold();
|
||||
let output = artifact.debug_output.color(color);
|
||||
write!(&mut buf, "{}: {}\n", stage, output).unwrap();
|
||||
}
|
||||
}
|
||||
if buf == "" { None } else { Some(buf) }
|
||||
},
|
||||
Err(ref s) => Some(format!("{} {}", "Error: ".red().bold(), s))
|
||||
}
|
||||
}
|
||||
|
@ -62,13 +62,20 @@ pub fn repl_main(generators: Vec<PLIGenerator>) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
let mut options = EvalOptions::default();
|
||||
if let Some(ref ltrs) = option_matches.opt_str("debug") {
|
||||
options.debug.tokens = ltrs.contains("l");
|
||||
options.debug.ast = ltrs.contains("a");
|
||||
options.debug.parse_tree = ltrs.contains("r");
|
||||
options.debug.symbol_table = ltrs.contains("s");
|
||||
}
|
||||
|
||||
let language_names: Vec<String> = languages.iter().map(|lang| {lang.get_language_name()}).collect();
|
||||
let initial_index: usize =
|
||||
option_matches.opt_str("lang")
|
||||
.and_then(|lang| { language_names.iter().position(|x| { x.to_lowercase() == lang.to_lowercase() }) })
|
||||
.unwrap_or(0);
|
||||
|
||||
let mut options = EvalOptions::default();
|
||||
options.execution_method = match option_matches.opt_str("eval-style") {
|
||||
Some(ref s) if s == "compile" => ExecutionMethod::Compile,
|
||||
_ => ExecutionMethod::Interpret,
|
||||
@ -368,5 +375,9 @@ fn program_options() -> getopts::Options {
|
||||
options.optflag("w",
|
||||
"webapp",
|
||||
"Start up web interpreter");
|
||||
options.optopt("d",
|
||||
"debug",
|
||||
"Debug a stage (l = tokenizer, a = AST, r = parse trace, s = symbol table)",
|
||||
"[l|a|r|s]");
|
||||
options
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user