1use std::collections::HashSet;
2
3use codespan_reporting::diagnostic::{Diagnostic, Label};
4
5#[derive(Debug, PartialEq)]
6pub struct Location {
7 pub line: usize,
9
10 pub column: usize,
12
13 pub offset: usize,
15}
16
17#[derive(Debug, PartialEq)]
18pub struct ParserDiagnostic {
19 pub location: Location,
20 pub expected: HashSet<&'static str>,
21}
22
23impl From<ParserDiagnostic> for Diagnostic<()> {
24 fn from(pi: ParserDiagnostic) -> Self {
25 let start = pi.location.offset;
26 Diagnostic::error()
27 .with_message("parse error")
28 .with_code("E0001")
29 .with_labels(vec![
30 Label::primary((), start..start).with_message("parse error")
31 ])
32 .with_notes(vec![format!("expected: {:?}", pi.expected)])
33 }
34}