From 5ecd28d0572d7f7ef6d005ffd02ce21cc392a8c4 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 15 Sep 2017 16:35:45 -0700 Subject: [PATCH] Print parse record in REPL as TraceArtifact --- src/schala_lang/mod.rs | 9 +++++---- src/schala_lang/parsing.rs | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index 9b60e8d..3607562 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -2,7 +2,7 @@ use language::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, ReplOut mod parsing; -pub struct Schala { +pub struct Schala { } impl Schala { @@ -32,14 +32,15 @@ impl ProgrammingLanguageInterface for Schala { } let ast = match parsing::parse(tokens) { - Ok(ast) => { + (Ok(ast), trace) => { if options.debug_parse { - output.add_artifact(TraceArtifact::new("Recursive descent calls:", format!("{:?}", "OI"))); + output.add_artifact(TraceArtifact::new("Recursive descent calls:", trace)); output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))); } ast }, - Err(err) => { + (Err(err), trace) => { + output.add_artifact(TraceArtifact::new("Recursive descent calls:", 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 8159b55..e6bddcd 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -333,6 +333,7 @@ impl ParseError { pub type ParseResult = Result; +#[derive(Debug)] pub struct ParseRecord(String); struct Parser { @@ -711,9 +712,11 @@ fn parse_binary(digits: String) -> ParseResult { Ok(result) } -pub fn parse(input: Vec) -> Result { +pub fn parse(input: Vec) -> (Result, String) { let mut parser = Parser::new(input); - parser.program() + let ast = parser.program(); + let trace = format!("Parse record: {:?}", parser.parse_record); + (ast, trace) } #[cfg(test)]