MCPcopy Create free account
hub / github.com/dfinity/ic-repl / report

Function report

src/error.rs:6–25  ·  view source on GitHub ↗
(e: &ParserError)

Source from the content-addressed store, hash-verified

4use codespan_reporting::term::{self, termcolor::StandardStream};
5
6fn 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
27fn report_expected(expected: &[String]) -> Vec<String> {
28 if expected.is_empty() {

Callers 1

pretty_parseFunction · 0.85

Calls 1

report_expectedFunction · 0.85

Tested by

no test coverage detected