rune/parse/
expectation.rs
1use core::fmt;
2
3#[derive(Debug, Clone, Copy)]
5#[non_exhaustive]
6pub enum Expectation {
7 Description(&'static str),
9 Keyword(&'static str),
11 Delimiter(&'static str),
13 Punctuation(&'static str),
15 Syntax(&'static str),
17 OpenDelimiter,
19 Boolean,
21 Literal,
23 Expression,
25 Shebang,
27 Comment,
29}
30
31impl fmt::Display for Expectation {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 match self {
34 Expectation::Description(s) => s.fmt(f),
35 Expectation::Keyword(k) => write!(f, "`{k}` keyword"),
36 Expectation::Delimiter(d) => write!(f, "`{}` delimiter", d),
37 Expectation::Punctuation(p) => write!(f, "`{}`", p),
38 Expectation::OpenDelimiter => write!(f, "`(`, `[`, or `{{`"),
39 Expectation::Boolean => write!(f, "true or false"),
40 Expectation::Literal => write!(f, r#"literal like `"a string"` or 42"#),
41 Expectation::Expression => write!(f, "expression"),
42 Expectation::Shebang => write!(f, "shebang"),
43 Expectation::Comment => write!(f, "comment"),
44 Expectation::Syntax(s) => s.fmt(f),
45 }
46 }
47}
48
49pub(crate) trait IntoExpectation {
51 fn into_expectation(self) -> Expectation;
53}
54
55impl IntoExpectation for Expectation {
56 fn into_expectation(self) -> Expectation {
57 self
58 }
59}
60
61impl IntoExpectation for &'static str {
62 fn into_expectation(self) -> Expectation {
63 Expectation::Description(self)
64 }
65}