rune/parse/
expectation.rsuse core::fmt;
#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
pub enum Expectation {
Description(&'static str),
Keyword(&'static str),
Delimiter(&'static str),
Punctuation(&'static str),
Syntax(&'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) => write!(f, "`{k}` keyword"),
Expectation::Delimiter(d) => write!(f, "`{}` delimiter", 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"),
Expectation::Syntax(s) => s.fmt(f),
}
}
}
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)
}
}