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
|
use phf::{Map, phf_map};
#[derive(Clone, Copy, Debug)]
pub enum If {
If,
Else,
}
#[derive(Clone, Copy, Debug)]
pub enum Loop {
For,
While,
}
pub enum Keyword {
If(If),
Loop(Loop),
Throw,
IO,
}
pub static KEYWORDS: Map<&'static str, Keyword> = phf_map! {
"if" => Keyword::If(If::If),
"else" => Keyword::If(If::Else),
"for" => Keyword::Loop(Loop::For),
"while" => Keyword::Loop(Loop::While),
"throw" => Keyword::Throw,
"println" => Keyword::IO,
"print" => Keyword::IO,
};
pub fn parse(keyword: &str) -> Option<&Keyword> {
KEYWORDS.get(keyword)
}
|