Skip to content

Commit 31c64db

Browse files
committed
First attempt at dealing with multiple errors
1 parent 8fed8bd commit 31c64db

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

lrlex/src/lib/ctbuilder.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,14 @@ where
546546
closure_lexerdef.set_rule_ids(&owned_map);
547547
yacc_header.mark_used(&"test_files".to_string());
548548
let test_glob = yacc_header.get("test_files");
549+
let mut err_str = None;
550+
let add_error_line = |err_str: &mut Option<String>, line| {
551+
if let Some(err_str) = err_str {
552+
err_str.push_str(&format!("{}\n", line));
553+
} else {
554+
let _ = err_str.insert(format!("{}\n", line));
555+
}
556+
};
549557
match test_glob {
550558
Some(HeaderValue(_, Value::Setting(Setting::Array(test_globs, _, _)))) => {
551559
for setting in test_globs {
@@ -559,22 +567,33 @@ where
559567
if let Some(ext) = path.extension() {
560568
if let Some(ext) = ext.to_str() {
561569
if ext.starts_with("grm") {
562-
Err(ErrorString("test_files extensions beginning with `grm` are reserved.".into()))?
570+
add_error_line(&mut err_str, "test_files extensions beginning with `grm` are reserved.".into());
563571
}
564572
}
565573
}
566574
let input = fs::read_to_string(&path)?;
567575
let l: LRNonStreamingLexer<LexerTypesT> =
568576
closure_lexerdef.lexer(&input);
569-
for e in rtpb.parse_map(&l, &|_| (), &|_, _| ()).1 {
570-
Err(format!("parsing {}: {}", path.display(), e))?
577+
let errs = rtpb.parse_map(&l, &|_| (), &|_, _| ()).1;
578+
if errs.len() > 1 {
579+
add_error_line(&mut err_str, format!("While parsing {}:", path.display()));
580+
for e in errs {
581+
add_error_line(&mut err_str, format!("\t{}", e));
582+
}
583+
} else if !errs.is_empty() {
584+
add_error_line(&mut err_str, format!("parsing {}: {}", path.display(), errs[0]));
571585
}
572586
}
573587
}
574-
_ => return Err("Invalid value for setting 'test_files'".into()),
588+
_ => return Err("Invalid value for setting 'test_files'".into()),
575589
}
576590
}
577-
Ok(())
591+
if let Some(err_str) = err_str {
592+
Err(ErrorString(err_str))?
593+
} else {
594+
Ok(())
595+
}
596+
578597
}
579598
Some(_) => Err("Invalid value for setting 'test_files'".into()),
580599
None => Ok(()),

0 commit comments

Comments
 (0)