Refactoring prace trace infra

This commit is contained in:
greg 2017-09-16 14:29:22 -07:00
parent 66d10604ba
commit 89cf101362
3 changed files with 15 additions and 5 deletions

View File

@ -74,7 +74,17 @@ pub struct TraceArtifact {
impl TraceArtifact { impl TraceArtifact {
pub fn new(stage: &str, debug: String) -> 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<String>) -> TraceArtifact {
let debug = format!("Parse trace: {:?}", trace);
TraceArtifact { stage_name: "parse_trace".to_string(), debug_output: debug, text_color: "red"}
} }
} }

View File

@ -34,13 +34,13 @@ impl ProgrammingLanguageInterface for Schala {
let ast = match parsing::parse(tokens) { let ast = match parsing::parse(tokens) {
(Ok(ast), trace) => { (Ok(ast), trace) => {
if options.debug_parse { 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))); output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast)));
} }
ast ast
}, },
(Err(err), trace) => { (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)); output.add_output(format!("Parse error: {:?}\n", err.msg));
return output; return output;
} }

View File

@ -697,10 +697,10 @@ fn parse_binary(digits: String) -> ParseResult<u64> {
Ok(result) Ok(result)
} }
pub fn parse(input: Vec<Token>) -> (Result<AST, ParseError>, String) { pub fn parse(input: Vec<Token>) -> (Result<AST, ParseError>, Vec<String>) {
let mut parser = Parser::new(input); let mut parser = Parser::new(input);
let ast = parser.program(); 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) (ast, trace)
} }