(e: &ParserError)
| 4 | use codespan_reporting::term::{self, termcolor::StandardStream}; |
| 5 | |
| 6 | fn report(e: &ParserError) -> Diagnostic<()> { |
| 7 | use lalrpop_util::ParseError::*; |
| 8 | let mut diag = Diagnostic::error().with_message("parser error"); |
| 9 | let label = match e { |
| 10 | User { error } => Label::primary((), error.span.clone()).with_message(&error.err), |
| 11 | InvalidToken { location } => { |
| 12 | Label::primary((), *location..location + 1).with_message("Invalid token") |
| 13 | } |
| 14 | UnrecognizedEof { location, expected } => { |
| 15 | diag = diag.with_notes(report_expected(expected)); |
| 16 | Label::primary((), *location..location + 1).with_message("Unexpected EOF") |
| 17 | } |
| 18 | UnrecognizedToken { token, expected } => { |
| 19 | diag = diag.with_notes(report_expected(expected)); |
| 20 | Label::primary((), token.0..token.2).with_message("Unexpected token") |
| 21 | } |
| 22 | ExtraToken { token } => Label::primary((), token.0..token.2).with_message("Extra token"), |
| 23 | }; |
| 24 | diag.with_labels(vec![label]) |
| 25 | } |
| 26 | |
| 27 | fn report_expected(expected: &[String]) -> Vec<String> { |
| 28 | if expected.is_empty() { |
no test coverage detected