diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-27 14:25:50 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-27 14:25:50 +0800 |
| commit | 3280c4844e09bed808f08ce6f42932c0cf33e4d6 (patch) | |
| tree | 84ed1ec40db0184b273faabdb7c7be522271eb43 /src/tokenizer.rs | |
init
Diffstat (limited to 'src/tokenizer.rs')
| -rw-r--r-- | src/tokenizer.rs | 34 |
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) +} |
