-
-
Save eddyb/a6f1176f265105105bbecbf4680a3a10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
use std::io::prelude::*; | |
fn main() { | |
let stdin = io::stdin(); | |
let mut stderr = io::stderr(); | |
let mut last_message = String::new(); | |
let mut last_loc = String::new(); | |
for line in stdin.lock().lines() { | |
let line = line.unwrap(); | |
let trimmed = line.trim(); | |
if trimmed.starts_with("Finished ") { | |
continue; | |
} | |
let message = std::mem::replace(&mut last_message, String::new()); | |
let loc_prefix = "--> "; | |
if trimmed.starts_with(loc_prefix) { | |
last_loc = trimmed[loc_prefix.len()..].to_string(); | |
if !message.is_empty() { | |
writeln!(stderr, "{}: {}", last_loc, message).unwrap(); | |
} | |
continue; | |
} | |
if !message.is_empty() { | |
writeln!(stderr, "{}", message).unwrap(); | |
} | |
if line.starts_with("error") || line.starts_with("warn") { | |
let after = line.trim_left_matches(char::is_alphabetic); | |
if after.starts_with("[") || after.starts_with(":") { | |
last_message.push_str(&line); | |
continue; | |
} | |
} | |
// Empty line, reset location. | |
if line.is_empty() { | |
last_loc.clear(); | |
} | |
// Source snippet. | |
if trimmed.starts_with(|c: char| c.is_digit(10)) { | |
continue; | |
} | |
// Weird thing in a source snippet. | |
if trimmed.starts_with("::: ") { | |
continue; | |
} | |
// Empty line. | |
if trimmed == "|" { | |
continue; | |
} | |
// Extra messages. | |
if line.starts_with(" ") && !last_loc.is_empty() { | |
let message = trimmed.trim_left_matches(&[' ', '|', '=', '_', '-', '^'][..]); | |
if !message.is_empty() { | |
writeln!(stderr, "{}: {}", last_loc, message).unwrap(); | |
} | |
continue; | |
} | |
writeln!(stderr, "{}", line).unwrap(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used with: