From 3280c4844e09bed808f08ce6f42932c0cf33e4d6 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 27 Sep 2025 14:25:50 +0800 Subject: init --- src/tokenizer.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/tokenizer.rs (limited to 'src/tokenizer.rs') 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) +} -- cgit v1.2.3