2023-09-09 01:17:46 +00:00
|
|
|
use crate::{
|
|
|
|
lexic::token::{Token, TokenType},
|
|
|
|
utils::Result3,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn try_token_type(tokens: &Vec<Token>, pos: usize, token_type: TokenType) -> Result3<&Token> {
|
|
|
|
match tokens.get(pos) {
|
|
|
|
Some(t) if t.token_type == token_type => Result3::Ok(t),
|
2023-09-10 16:16:34 +00:00
|
|
|
Some(t) if t.token_type == TokenType::NewLine || t.token_type == TokenType::EOF => {
|
2023-09-09 01:17:46 +00:00
|
|
|
Result3::None
|
|
|
|
}
|
|
|
|
Some(t) => Result3::Err(t),
|
|
|
|
None => Result3::None,
|
|
|
|
}
|
|
|
|
}
|