summaryrefslogtreecommitdiff
path: root/src/tokenizer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tokenizer.rs')
-rw-r--r--src/tokenizer.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
new file mode 100644
index 0000000..085c1d3
--- /dev/null
+++ b/src/tokenizer.rs
@@ -0,0 +1,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)
+}