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) {
|
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;
|
||||||
}
|
}
|
||||||
|
@ -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)]
|
||||||
|
Loading…
Reference in New Issue
Block a user