Print parse record in REPL as TraceArtifact

This commit is contained in:
greg 2017-09-15 16:35:45 -07:00
parent 6c5dbac406
commit 5ecd28d057
2 changed files with 10 additions and 6 deletions

View File

@ -2,7 +2,7 @@ use language::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, ReplOut
mod parsing; mod parsing;
pub struct Schala { pub struct Schala {
} }
impl Schala { impl Schala {
@ -32,14 +32,15 @@ impl ProgrammingLanguageInterface for Schala {
} }
let ast = match parsing::parse(tokens) { let ast = match parsing::parse(tokens) {
Ok(ast) => { (Ok(ast), trace) => {
if options.debug_parse { 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))); output.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast)));
} }
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)); output.add_output(format!("Parse error: {:?}\n", err.msg));
return output; return output;
} }

View File

@ -333,6 +333,7 @@ impl ParseError {
pub type ParseResult<T> = Result<T, ParseError>; pub type ParseResult<T> = Result<T, ParseError>;
#[derive(Debug)]
pub struct ParseRecord(String); pub struct ParseRecord(String);
struct Parser { struct Parser {
@ -711,9 +712,11 @@ fn parse_binary(digits: String) -> ParseResult<u64> {
Ok(result) Ok(result)
} }
pub fn parse(input: Vec<Token>) -> Result<AST, ParseError> { pub fn parse(input: Vec<Token>) -> (Result<AST, ParseError>, String) {
let mut parser = Parser::new(input); let mut parser = Parser::new(input);
parser.program() let ast = parser.program();
let trace = format!("Parse record: {:?}", parser.parse_record);
(ast, trace)
} }
#[cfg(test)] #[cfg(test)]