diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index 77d4647..f0e3a75 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -137,21 +137,15 @@ fn parsing(input: Vec, handle: &mut Schala, comp: Option<&mut }; let ast = parser.parse(); - let _trace = parser.format_parse_trace(); + let trace = parser.format_parse_trace(); comp.map(|comp| { - comp.add_artifact(format!("{:#?}", ast)); - /* - //TODO need to control which of these debug stages get added - let opt = comp.cur_debug_options.get(0).map(|s| s.clone()); - match opt { - None => comp.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))), - Some(ref s) if s == "compact" => comp.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))), - Some(ref s) if s == "expanded" => comp.add_artifact(TraceArtifact::new("ast", format!("{:#?}", ast))), - Some(ref s) if s == "trace" => comp.add_artifact(TraceArtifact::new_parse_trace(trace)), - Some(ref x) => println!("Bad parsing debug option: {}", x), + let debug_info = match comp.parsing.as_ref().unwrap_or(&ParsingDebugType::CompactAST) { + ParsingDebugType::CompactAST => format!("{:?}", ast), + ParsingDebugType::ExpandedAST => format!("{:#?}", ast), + ParsingDebugType::Trace => format!("{}", trace[0]) //TODO fix this }; - */ + comp.add_artifact(debug_info); }); ast.map_err(|err| format_parse_error(err, handle)) } @@ -236,9 +230,17 @@ impl SourceReference { } } +enum ParsingDebugType { + CompactAST, + ExpandedAST, + Trace +} + #[derive(Default)] struct PassDebugArtifact { + parsing: Option, artifacts: Vec + } impl PassDebugArtifact { fn add_artifact(&mut self, artifact: String) { @@ -276,7 +278,12 @@ impl ProgrammingLanguageInterface for Schala { { let stage_names = stage_names(); let ask = DebugAsk::ByStage { stage_name: stage_names[n].to_string() }; - let mut debug_artifact = tok.debug_requests.get(&ask).map(|_| PassDebugArtifact::default()); + let mut debug_artifact = tok.debug_requests.get(&ask).map(|_| + PassDebugArtifact { + parsing: if stage_names[n] == "parsing" { Some(ParsingDebugType::CompactAST) } else { None }, + ..Default::default() + } + ); let output = func(input, tok.schala, debug_artifact.as_mut()); tok.stage_durations.push((stage_names[n].to_string(), tok.sw.elapsed())); diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 161b30d..34542a1 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -38,7 +38,7 @@ pub struct GlobalOutputStats { #[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize, Serialize)] pub enum DebugAsk { Timing, - ByStage { stage_name: String }, + ByStage { stage_name: String, token: Option }, } pub struct DebugResponse { diff --git a/schala-repl/src/repl/directive_actions.rs b/schala-repl/src/repl/directive_actions.rs index bbac3c3..5dba398 100644 --- a/schala-repl/src/repl/directive_actions.rs +++ b/schala-repl/src/repl/directive_actions.rs @@ -52,15 +52,12 @@ impl DirectiveAction { 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() }); + let meta = LangMetaRequest::ImmediateDebug(DebugAsk::ByStage { stage_name: stage_name.clone(), token: None }); + let meta_response = cur_state.request_meta(meta); - let response = match cur_state.request_meta(meta) { - LangMetaResponse::ImmediateDebug(DebugResponse { ask, value }) => { - if (ask != DebugAsk::ByStage { stage_name: stage_name }) { - return Some(format!("Didn't get debug stage requested")); - } - value - }, + let response = match meta_response { + LangMetaResponse::ImmediateDebug(DebugResponse { ask: DebugAsk::ByStage { stage_name: this_stage_name, .. }, value }) if this_stage_name == stage_name => + value, _ => return Some(format!("Invalid language meta response")), }; Some(response) @@ -70,7 +67,7 @@ impl DirectiveAction { Some(s) => s.to_string(), None => return Some(format!("Must specify a stage to show")), }; - let ask = DebugAsk::ByStage { stage_name }; + let ask = DebugAsk::ByStage { stage_name, token: None }; repl.options.debug_asks.insert(ask); None }, @@ -79,7 +76,7 @@ impl DirectiveAction { Some(s) => s.to_string(), None => return Some(format!("Must specify a stage to hide")), }; - let ask = DebugAsk::ByStage { stage_name }; + let ask = DebugAsk::ByStage { stage_name, token: None }; repl.options.debug_asks.remove(&ask); None }, diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index c05ff69..32c339a 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -149,7 +149,7 @@ impl Repl { for debug_resp in response.debug_responses { let stage_name = match debug_resp.ask { - DebugAsk::ByStage { stage_name } => stage_name, + DebugAsk::ByStage { stage_name, .. } => stage_name, _ => continue, }; let s = format!("{} - {}\n", stage_name, debug_resp.value);