Fixed trace parsing debug output
This commit is contained in:
parent
baf499ee5a
commit
bf3dcc18d0
@ -245,14 +245,16 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn format_parse_trace(self) -> Vec<String> {
|
pub fn format_parse_trace(&self) -> String {
|
||||||
self.parse_record.into_iter().map(|r| {
|
let mut buf = String::new();
|
||||||
|
for r in self.parse_record.iter() {
|
||||||
let mut indent = String::new();
|
let mut indent = String::new();
|
||||||
for _ in 0..r.level {
|
for _ in 0..r.level {
|
||||||
indent.push(' ');
|
indent.push(' ');
|
||||||
}
|
}
|
||||||
format!("{}Production `{}`, token: {}", indent, r.production_name, r.next_token)
|
buf.push_str(&format!("{}Production `{}`, token: {}\n", indent, r.production_name, r.next_token))
|
||||||
}).collect()
|
}
|
||||||
|
buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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> {
|
fn parsing(input: Vec<tokenizing::Token>, handle: &mut Schala, comp: Option<&mut PassDebugArtifact>) -> Result<ast::AST, String> {
|
||||||
use crate::parsing::Parser;
|
use crate::parsing::Parser;
|
||||||
|
use ParsingDebugType::*;
|
||||||
|
|
||||||
let mut parser = handle.active_parser.take().unwrap_or_else(|| Parser::new(input));
|
let mut parser = handle.active_parser.take().unwrap_or_else(|| Parser::new(input));
|
||||||
let ast = parser.parse();
|
let ast = parser.parse();
|
||||||
let trace = parser.format_parse_trace();
|
|
||||||
|
|
||||||
comp.map(|comp| {
|
comp.map(|comp| {
|
||||||
let debug_info = match comp.parsing.as_ref().unwrap_or(&ParsingDebugType::CompactAST) {
|
let debug_format = comp.parsing.as_ref().unwrap_or(&CompactAST);
|
||||||
ParsingDebugType::CompactAST => format!("{:?}", ast),
|
let debug_info = match debug_format {
|
||||||
ParsingDebugType::ExpandedAST => format!("{:#?}", ast),
|
CompactAST => match ast {
|
||||||
ParsingDebugType::Trace => format!("{}", trace[0]) //TODO fix this
|
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);
|
comp.add_artifact(debug_info);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user