Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
harshdoesdev authored and Heulitig committed Feb 20, 2024
1 parent 4c77b17 commit 7b8d6b2
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions fastn-expr/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,29 @@ pub fn tokenize(input: &str) -> Result<Vec<Token>, TokenizerError> {
tokens.push(get_token(&current_token));
current_token.clear();
}
} else if (((c == '.' || c == '_') && !current_token.is_empty()) || c.is_alphanumeric())
|| (c == '-' && current_token.is_empty())
{
current_token.push(c);
} else if c == '"' {
in_string_literal = true;
} else if !current_token.is_empty() {
tokens.push(get_token(&current_token));
current_token.clear();
} else {
return Err(TokenizerError::UnexpectedToken {
token: c,
position: pos,
});
match c {
'.' | '_' if !current_token.is_empty() => {
current_token.push(c);
}
'-' if current_token.is_empty() => {
current_token.push(c);
}
'"' => in_string_literal = true,
_ => {
if c.is_alphanumeric() {
current_token.push(c);
} else if !current_token.is_empty() {
tokens.push(get_token(&current_token));
current_token.clear();
} else {
return Err(TokenizerError::UnexpectedToken {
token: c,
position: pos,
});
}
}
}
}
}

Expand Down

0 comments on commit 7b8d6b2

Please sign in to comment.