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
use super::*;
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum PError {
Mismatch,
Terminate(u64, String),
}
impl PError {
pub fn into_error(self, doc: &str) -> String {
match self {
Self::Mismatch => String::from("not matched"),
Self::Terminate(pos, name) => {
format!("invalid {}: \n\n{}", name, indicated_msg(doc, pos))
}
}
}
}
impl From<()> for PError {
fn from(_: ()) -> Self {
Self::Mismatch
}
}
impl Display for PError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.write_fmt(format_args!("{:?}", self))
}
}