Fixed trace parsing debug output

This commit is contained in:
greg 2019-08-12 09:32:04 -07:00
parent baf499ee5a
commit bf3dcc18d0
2 changed files with 18 additions and 9 deletions

View File

@ -245,14 +245,16 @@ impl Parser {
}
*/
pub fn format_parse_trace(self) -> Vec<String> {
self.parse_record.into_iter().map(|r| {
pub fn format_parse_trace(&self) -> String {
let mut buf = String::new();
for r in self.parse_record.iter() {
let mut indent = String::new();
for _ in 0..r.level {
indent.push(' ');
}
format!("{}Production `{}`, token: {}", indent, r.production_name, r.next_token)
}).collect()
buf.push_str(&format!("{}Production `{}`, token: {}\n", indent, r.production_name, r.next_token))
}
buf
}
}

View File

@ -95,16 +95,23 @@ fn tokenizing(input: &str, _handle: &mut Schala, comp: Option<&mut PassDebugArti
fn parsing(input: Vec<tokenizing::Token>, handle: &mut Schala, comp: Option<&mut PassDebugArtifact>) -> Result<ast::AST, String> {
use crate::parsing::Parser;
use ParsingDebugType::*;
let mut parser = handle.active_parser.take().unwrap_or_else(|| Parser::new(input));
let ast = parser.parse();
let trace = parser.format_parse_trace();
comp.map(|comp| {
let debug_info = match comp.parsing.as_ref().unwrap_or(&ParsingDebugType::CompactAST) {
ParsingDebugType::CompactAST => format!("{:?}", ast),
ParsingDebugType::ExpandedAST => format!("{:#?}", ast),
ParsingDebugType::Trace => format!("{}", trace[0]) //TODO fix this
let debug_format = comp.parsing.as_ref().unwrap_or(&CompactAST);
let debug_info = match debug_format {
CompactAST => match ast {
Ok(ref ast) => format!("{:?}", ast),
Err(_) => "Error - see output".to_string(),
},
ExpandedAST => match ast {
Ok(ref ast) => format!("{:#?}", ast),
Err(_) => "Error - see output".to_string(),
},
Trace => parser.format_parse_trace(),
};
comp.add_artifact(debug_info);
});