main: print parse stats when parse errors
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -184,6 +184,13 @@ fn subst() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
fn plural(count: usize) -> &'static str {
|
||||
match count {
|
||||
1 => "",
|
||||
_ => "s",
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(document: &str) {
|
||||
let mut parser = Parser::new(Lexer::new(document));
|
||||
let verbose = !matches!(
|
||||
@@ -193,11 +200,21 @@ fn parse(document: &str) {
|
||||
for idx in 0.. {
|
||||
match parser.parse::<Expr>(0) {
|
||||
Err(e @ ParseError::EOF(s)) if s.tail == document.len() as _ => {
|
||||
println!("\x1b[92m{e} (total {} bytes)\x1b[0m", document.len());
|
||||
println!(
|
||||
"\x1b[92m{e} (total {} byte{}, {idx} expression{})\x1b[0m",
|
||||
document.len(),
|
||||
plural(document.len()),
|
||||
plural(idx),
|
||||
);
|
||||
break;
|
||||
}
|
||||
Err(e @ ParseError::EOF(_)) => {
|
||||
println!("\x1b[93m{e} (total {} bytes)\x1b[0m", document.len());
|
||||
println!(
|
||||
"\x1b[93m{e} (total {} byte{}, {idx} expression{})\x1b[0m",
|
||||
document.len(),
|
||||
plural(document.len()),
|
||||
plural(idx),
|
||||
);
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user