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
use std::{
error::Error,
fmt::{self, Display, Formatter},
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ParseRuleError {
Missing(char),
MissingNumber,
Unexpected(char),
ExtraJunk,
GenLessThan2,
NotMapRule,
Base64Error,
InvalidLength,
GenOverflow,
}
impl Display for ParseRuleError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
ParseRuleError::Missing(c) => write!(f, "Missing expected {:?}", c),
ParseRuleError::MissingNumber => write!(f, "Missing expected number"),
ParseRuleError::Unexpected(c) => write!(f, "Unexpected {:?}", c),
ParseRuleError::ExtraJunk => {
write!(f, "Extra unparsed junk at the end of the rule string")
}
ParseRuleError::GenLessThan2 => {
write!(f, "Number of states less than 2 in Generations rule")
}
ParseRuleError::NotMapRule => write!(f, "Not a MAP rule"),
ParseRuleError::Base64Error => {
write!(f, "An error occurs when decoding the base64 string")
}
ParseRuleError::InvalidLength => write!(f, "Invalid length for MAP rule"),
ParseRuleError::GenOverflow => {
write!(f, "Generations number overflow for Generations rule")
}
}
}
}
impl Error for ParseRuleError {}