1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![forbid(unsafe_code)]
use pest::error::LineColLocation;
use pest::RuleType;
use std::fmt;
pub use parse::{parse_query, parse_schema};
pub use pos::{Pos, Positioned};
pub mod types;
mod parse;
mod pos;
#[derive(Debug, PartialEq)]
pub struct Error {
pub pos: Pos,
pub message: String,
}
impl Error {
pub fn new(message: impl Into<String>, pos: Pos) -> Self {
Self {
pos,
message: message.into(),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl std::error::Error for Error {}
impl<R: RuleType> From<pest::error::Error<R>> for Error {
fn from(err: pest::error::Error<R>) -> Self {
Error {
pos: {
match err.line_col {
LineColLocation::Pos((line, column))
| LineColLocation::Span((line, column), _) => Pos { line, column },
}
},
message: err.to_string(),
}
}
}
pub type Result<T> = std::result::Result<T, Error>;