Skip to content

Commit e193dd3

Browse files
committed
Print source snippet for lookahead value of rr-conflicts
1 parent 6444cf6 commit e193dd3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lrpar/src/lib/diagnostics.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,14 @@ impl<'a> SpannedDiagnosticFormatter<'a> {
267267
let (_r1_prod_names, _r1_prod_spans) = pidx_prods_data(ast, *r1_prod_idx);
268268
let (_r2_prod_names, _r2_prod_spans) = pidx_prods_data(ast, *r2_prod_idx);
269269

270-
let t_name = grm.token_name(*t_idx).unwrap_or("$");
270+
let (t_name, t_span) = if let Some(name) = grm.token_name(*t_idx) {
271+
(name, grm.token_span(*t_idx))
272+
} else {
273+
(
274+
"$",
275+
grm.token_idx("$").and_then(|t_idx| grm.token_span(t_idx)),
276+
)
277+
};
271278
let r1_rule_idx = grm.prod_to_rule(*r1_prod_idx);
272279
let r2_rule_idx = grm.prod_to_rule(*r2_prod_idx);
273280
let r1_span = grm.rule_name_span(r1_rule_idx);
@@ -287,6 +294,9 @@ impl<'a> SpannedDiagnosticFormatter<'a> {
287294
);
288295
out.pushln(self.underline_span_with_text(r1_span, "First reduce".to_string(), '^'));
289296
out.pushln(self.underline_span_with_text(r2_span, "Second reduce".to_string(), '-'));
297+
if let Some(t_span) = t_span {
298+
out.pushln(self.underline_span_with_text(t_span, "Lookahead".to_string(), '+'));
299+
}
290300
out.push('\n');
291301
}
292302
for (s_tok_idx, r_prod_idx, _st_idx) in c.sr_conflicts() {

0 commit comments

Comments
 (0)