Print parse record in REPL as TraceArtifact
This commit is contained in:
parent
6c5dbac406
commit
5ecd28d057
@ -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;
|
||||
}
|
||||
|
@ -333,6 +333,7 @@ impl ParseError {
|
||||
|
||||
pub type ParseResult<T> = Result<T, ParseError>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParseRecord(String);
|
||||
|
||||
struct Parser {
|
||||
@ -711,9 +712,11 @@ fn parse_binary(digits: String) -> ParseResult<u64> {
|
||||
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);
|
||||
parser.program()
|
||||
let ast = parser.program();
|
||||
let trace = format!("Parse record: {:?}", parser.parse_record);
|
||||
(ast, trace)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
Reference in New Issue
Block a user