Skip to content

Commit 53799b9

Browse files
committed
Improve error message for issue #618
Also adds missing file information from the previous commit.
1 parent b95668e commit 53799b9

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

lrpar/src/lib/ctbuilder.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,20 @@ where
14591459
for i in 0..grm.prod(pidx).len() {
14601460
let argt = match grm.prod(pidx)[i] {
14611461
Symbol::Rule(ref_ridx) => {
1462-
str::parse::<TokenStream>(grm.actiontype(ref_ridx).as_ref().unwrap())?
1462+
if let Some(action_type) = grm.actiontype(ref_ridx).as_ref() {
1463+
str::parse::<TokenStream>(action_type)?
1464+
} else {
1465+
let mut s = String::from("\n");
1466+
let rule_span = grm.rule_name_span(ref_ridx);
1467+
s.push_str(&diag.file_location_msg("Error", Some(rule_span)));
1468+
s.push_str("\n");
1469+
s.push_str(&diag.underline_span_with_text(
1470+
rule_span,
1471+
"Rule missing action type".to_string(),
1472+
'^',
1473+
));
1474+
return Err(ErrorString(s).into());
1475+
}
14631476
}
14641477
Symbol::Token(_) => {
14651478
let lexemet =
@@ -1530,6 +1543,8 @@ where
15301543
let inner_span =
15311544
Span::new(span.start() + last + off + "$".len(), span.end());
15321545
let mut s = String::from("\n");
1546+
s.push_str(&diag.file_location_msg("Error", Some(inner_span)));
1547+
s.push_str("\n");
15331548
s.push_str(&diag.underline_span_with_text(
15341549
inner_span,
15351550
"Unknown text following '$'".to_string(),

0 commit comments

Comments
 (0)