-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathkeyword.rs
63 lines (57 loc) · 1.03 KB
/
keyword.rs
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
63
use super::*;
#[derive(Debug, Eq, PartialEq, IntoStaticStr, Display, Copy, Clone, EnumString)]
#[strum(serialize_all = "kebab_case")]
pub(crate) enum Keyword {
Alias,
AllowDuplicateRecipes,
AllowDuplicateVariables,
Assert,
DotenvFilename,
DotenvLoad,
DotenvPath,
DotenvRequired,
Else,
Export,
Fallback,
False,
If,
IgnoreComments,
Import,
Mod,
NoExitMessage,
PositionalArguments,
Quiet,
ScriptInterpreter,
Set,
Shell,
Tempdir,
True,
Unexport,
Unstable,
WindowsPowershell,
WindowsShell,
WorkingDirectory,
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
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn keyword_case() {
assert_eq!(Keyword::X.lexeme(), "x");
assert_eq!(Keyword::IgnoreComments.lexeme(), "ignore-comments");
}
}