Created
September 21, 2019 10:30
-
-
Save softprops/714fa5ca9732ad6bfe1570838e7ddafb 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
| struct Position { line: usize, col: usize } | |
| fn report<P>(path: P, content: &str, pos: &Position, error: &str) | |
| where | |
| P: AsRef<Path>, | |
| { | |
| let Position { line, col } = pos; | |
| println!( | |
| "{}", | |
| format!("--> {}:{}:{}", path.as_ref().display(), line, col).dimmed() | |
| ); | |
| for (idx, matched) in content.lines().enumerate().filter(|(idx, _)| (line-2..=*line).contains(idx)) { | |
| println!("{}{}", format!("{} |", idx).dimmed(), matched) | |
| } | |
| println!( | |
| "{}{}{}", | |
| format!("{}|", " ".repeat(line.to_string().len() + 1)).dimmed(), | |
| " ".repeat(*col), | |
| format!("^ error: {}", error).red() | |
| ); | |
| } |
Author
softprops
commented
Sep 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment