amarok_parser/
grammar.rs

1use amarok_syntax::{Diagnostic, Span};
2use pest_derive::Parser;
3
4#[derive(Parser)]
5#[grammar = "amarok.pest"]
6pub(crate) struct AmarokGrammar;
7
8pub(crate) fn pest_error_to_diagnostic(error: &pest::error::Error<Rule>) -> Diagnostic {
9    use pest::error::InputLocation;
10
11    let message = error.to_string();
12
13    let span = match error.location {
14        InputLocation::Span((start, end)) => Some(Span::new(start, end)),
15        InputLocation::Pos(pos) => Some(Span::new(pos, pos + 1)),
16    };
17
18    Diagnostic { message, span }
19}