From 4dcd9d019801de699f9d659b2ed2fca5c880f830 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 22 Oct 2019 02:11:49 -0700 Subject: [PATCH] Some more parse trace improvements --- schala-lang/language/src/parsing.rs | 9 ++++++++- schala-lang/language/src/tokenizing.rs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index da97c3c..f78911c 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -263,12 +263,19 @@ impl Parser { pub fn format_parse_trace(&self) -> String { let mut buf = String::new(); buf.push_str("Parse productions:\n"); + let mut next_token = None; for r in self.parse_record.iter() { let mut indent = String::new(); for _ in 0..r.level { 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 } diff --git a/schala-lang/language/src/tokenizing.rs b/schala-lang/language/src/tokenizing.rs index 7939f31..e4abbd0 100644 --- a/schala-lang/language/src/tokenizing.rs +++ b/schala-lang/language/src/tokenizing.rs @@ -86,7 +86,7 @@ lazy_static! { }; } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Token { pub kind: TokenKind, pub line_num: usize,