From 89cf101362c16857ddc7317d8b19cc744f4166bf Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 16 Sep 2017 14:29:22 -0700 Subject: [PATCH] Refactoring prace trace infra --- src/language.rs | 12 +++++++++++- src/schala_lang/mod.rs | 4 ++-- src/schala_lang/parsing.rs | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/language.rs b/src/language.rs index 13d82a5..a4125f7 100644 --- a/src/language.rs +++ b/src/language.rs @@ -74,7 +74,17 @@ pub struct TraceArtifact { impl TraceArtifact { pub fn new(stage: &str, debug: String) -> TraceArtifact { - TraceArtifact { stage_name: stage.to_string(), debug_output: debug, text_color: "blue" } + let color = match stage { + "parse_trace" => "red", + "tokens" => "green", + _ => "blue", + }; + TraceArtifact { stage_name: stage.to_string(), debug_output: debug, text_color: color} + } + + pub fn new_parse_trace(trace: Vec) -> TraceArtifact { + let debug = format!("Parse trace: {:?}", trace); + TraceArtifact { stage_name: "parse_trace".to_string(), debug_output: debug, text_color: "red"} } } diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index 3607562..86cda20 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -34,13 +34,13 @@ impl ProgrammingLanguageInterface for Schala { let ast = match parsing::parse(tokens) { (Ok(ast), trace) => { if options.debug_parse { - output.add_artifact(TraceArtifact::new("Recursive descent calls:", trace)); + output.add_artifact(TraceArtifact::new_parse_trace(trace)); output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))); } ast }, (Err(err), trace) => { - output.add_artifact(TraceArtifact::new("Recursive descent calls:", trace)); + output.add_artifact(TraceArtifact::new_parse_trace(trace)); output.add_output(format!("Parse error: {:?}\n", err.msg)); return output; } diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 0ed4cbe..8754235 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -697,10 +697,10 @@ fn parse_binary(digits: String) -> ParseResult { Ok(result) } -pub fn parse(input: Vec) -> (Result, String) { +pub fn parse(input: Vec) -> (Result, Vec) { let mut parser = Parser::new(input); let ast = parser.program(); - let trace = format!("Parse record: {:?}", parser.parse_record); + let trace = parser.parse_record.into_iter().map(|r| r.0).collect(); (ast, trace) }