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
use std::fmt;
#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
pub enum Expectation {
Description(&'static str),
Keyword(&'static str),
Delimiter(&'static str),
Punctuation(&'static str),
OpenDelimiter,
Boolean,
Literal,
Expression,
Shebang,
Comment,
}
impl fmt::Display for Expectation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expectation::Description(s) => s.fmt(f),
Expectation::Keyword(k) => k.fmt(f),
Expectation::Delimiter(d) => write!(f, "`{}`", d),
Expectation::Punctuation(p) => write!(f, "`{}`", p),
Expectation::OpenDelimiter => write!(f, "`(`, `[`, or `{{`"),
Expectation::Boolean => write!(f, "true or false"),
Expectation::Literal => write!(f, r#"literal like `"a string"` or 42"#),
Expectation::Expression => write!(f, "expression"),
Expectation::Shebang => write!(f, "shebang"),
Expectation::Comment => write!(f, "comment"),
}
}
}
pub(crate) trait IntoExpectation {
fn into_expectation(self) -> Expectation;
}
impl IntoExpectation for Expectation {
fn into_expectation(self) -> Expectation {
self
}
}
impl IntoExpectation for &'static str {
fn into_expectation(self) -> Expectation {
Expectation::Description(self)
}
}