thp/src/syntax/utils.rs

16 lines
471 B
Rust
Raw Normal View History

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),
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,
}
}