Skip to content

Commit 8b1c976

Browse files
committed
add lookup_ident in tokenizer
1 parent 18a6e98 commit 8b1c976

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/lexericals/lexer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ mod test {
7070
Token::new (Tokenkind::Rparen, String::from(")")),
7171
Token::new (Tokenkind::Lbrace, String::from("{")),
7272
Token::new (Tokenkind::Rbrace, String::from("}")),
73-
Token::new(Tokenkind::Comma, String::from(",")),
73+
Token::new (Tokenkind::Comma, String::from(",")),
7474
Token::new (Tokenkind::Semicolon,String::from(";")),
75-
Token::new(Tokenkind::Eof, String::new()), // Eof token
75+
Token::new (Tokenkind::Eof, String::new()), // Eof token
7676
];
7777
let mut lexer = Lexer::new(input);
7878
for (idx,exp_token) in expect_token.iter().enumerate() {

src/lexericals/tokenizer.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@ impl Display for Tokenkind {
8383
}
8484
}
8585

86-
86+
impl Tokenkind{
87+
pub fn lookup_ident(ident: &String) -> Self{
88+
match ident as &str {
89+
"fn" => Self::Function,
90+
"let" => Self::Let,
91+
"if" => Self::If,
92+
"else" => Self::Else,
93+
"return" => Self::Return,
94+
_ => Self::Ident,
95+
}
96+
}
97+
}
8798

8899
#[cfg(test)]
89100
mod test{
@@ -109,4 +120,6 @@ mod test{
109120
let token_kind = Tokenkind::Eof;
110121
assert_eq!(token_kind.to_string(), "Eof");
111122
}
123+
124+
112125
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ fn main() {
2222
}
2323

2424
// println!(" last Current character: {:?}", lexer.next_token());
25-
2625

27-
}
26+
}
27+

0 commit comments

Comments
 (0)