use crate::lexer::{Lexer, Token, TokenType};
use anyhow::Result;
impl Lexer {
pub fn rewrite_token_pairs(&self, tokens: Vec<Token>) -> Result<Vec<Token>> {
let mut result = Vec::new();
let mut i = 0;
while i < tokens.len() {
if i + 1 < tokens.len()
&& tokens[i].token_type == TokenType::Not
&& tokens[i + 1].token_type == TokenType::In
{
result.push(Token::simple(TokenType::NotIn));
i += 2; }
else if i + 1 < tokens.len()
&& tokens[i].token_type == TokenType::Is
&& tokens[i + 1].token_type == TokenType::Not
{
result.push(Token::simple(TokenType::IsNot));
i += 2; } else {
result.push(tokens[i].clone());
i += 1;
}
}
Ok(result)
}
}