Skip to content

Commit

Permalink
update group_while
Browse files Browse the repository at this point in the history
  • Loading branch information
schneedotdev committed Mar 7, 2024
1 parent d18ef0a commit dcc3444
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ impl<'a> Lexer<'a> {
}
}

fn group_while<F>(&mut self, start: char, condition: &F) -> String
fn group_while<F>(&mut self, start: char, condition: F) -> String
where
F: Fn(&char) -> bool,
F: Fn(char) -> bool,
{
let mut group = start.to_string();
while let Some(character) = self.input.next_if(condition) {
while let Some(character) = self.input.next_if(|&c| condition(c)) {
group.push(character)
}

Expand Down Expand Up @@ -48,11 +48,11 @@ impl<'a> Iterator for Lexer<'a> {
'<' => Token::LessThan,
'>' => Token::GreaterThan,
_ if c.is_alphabetic() => {
let value = self.group_while(c, &|next_char: &char| next_char.is_alphabetic());
let value = self.group_while(c, char::is_alphabetic);
Token::Ident(value)
}
_ if c.is_numeric() => {
let value = self.group_while(c, &|next_char: &char| next_char.is_numeric());
let value = self.group_while(c, char::is_numeric);

match value.parse() {
Ok(val) => Token::Int(val),
Expand Down

0 comments on commit dcc3444

Please sign in to comment.