just/src/keyword.rs

60 lines
987 B
Rust
Raw Normal View History

use super::*;
#[derive(Debug, Eq, PartialEq, IntoStaticStr, Display, Copy, Clone, EnumString)]
#[strum(serialize_all = "kebab_case")]
pub(crate) enum Keyword {
Alias,
2022-02-14 18:37:06 -08:00
AllowDuplicateRecipes,
AllowDuplicateVariables,
2024-05-14 18:55:32 -07:00
Assert,
DotenvFilename,
DotenvLoad,
DotenvPath,
DotenvRequired,
Else,
Export,
Fallback,
False,
If,
IgnoreComments,
Import,
2023-12-27 20:27:15 -08:00
Mod,
PositionalArguments,
Quiet,
Set,
Shell,
Tempdir,
True,
Unexport,
2022-01-18 11:02:15 -08:00
WindowsPowershell,
2022-05-31 13:01:59 -07:00
WindowsShell,
2024-05-18 22:41:38 -07:00
X,
}
impl Keyword {
pub(crate) fn from_lexeme(lexeme: &str) -> Option<Keyword> {
lexeme.parse().ok()
}
pub(crate) fn lexeme(self) -> &'static str {
self.into()
}
}
impl<'a> PartialEq<&'a str> for Keyword {
fn eq(&self, other: &&'a str) -> bool {
self.lexeme() == *other
}
}
2024-05-18 22:41:38 -07:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn keyword_case() {
assert_eq!(Keyword::X.lexeme(), "x");
assert_eq!(Keyword::IgnoreComments.lexeme(), "ignore-comments");
}
}