Some more parse trace improvements

This commit is contained in:
greg 2019-10-22 02:11:49 -07:00
parent 7ac63160c5
commit 4dcd9d0198
2 changed files with 9 additions and 2 deletions

View File

@ -263,12 +263,19 @@ impl Parser {
pub fn format_parse_trace(&self) -> String { pub fn format_parse_trace(&self) -> String {
let mut buf = String::new(); let mut buf = String::new();
buf.push_str("Parse productions:\n"); buf.push_str("Parse productions:\n");
let mut next_token = None;
for r in self.parse_record.iter() { 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('.');
} }
buf.push_str(&format!("{}`{}`, next token: {}\n", indent, r.production_name, r.next_token)) let effective_token = if next_token == Some(&r.next_token) {
"".to_string()
} else {
next_token = Some(&r.next_token);
format!(", next token: {}", r.next_token)
};
buf.push_str(&format!("{}`{}`{}\n", indent, r.production_name, effective_token));
} }
buf buf
} }

View File

@ -86,7 +86,7 @@ lazy_static! {
}; };
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct Token { pub struct Token {
pub kind: TokenKind, pub kind: TokenKind,
pub line_num: usize, pub line_num: usize,