public function isNextToken($token, $ignoreSpaces = true)
    {
        if($this->pos >= $this->len) {
            return Tokens::T_END == $token;
        }
        switch($token) {
        case Tokens::T_END:
            return false;
        case Tokens::T_OPERATOR:
            return 
                    $this->isNextToken(Tokens::T_LOGICAL_OP, $ignoreSpaces) ||
                    $this->isNextToken(Tokens::T_COMPARISON_OP, $ignoreSpaces)
                ;
        case Tokens::T_QUOTE:
            return 
                    $this->isNextToken(Tokens::T_SINGLE_QUOTE, $ignoreSpaces) ||
                    $this->isNextToken(Tokens::T_DOUBLE_QUOTE, $ignoreSpaces)
                ;
        case Tokens::T_LOGICAL_OP:
            return 
                    $this->isNextToken(Tokens::T_AND, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_OR, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_NOT, $ignoreSpaces)
                ;
            break;
        case Tokens::T_COMPARISON_OP:
            return 
                    $this->isNextToken(Tokens::T_EQ, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_NE, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_GT, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_GE, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_LT, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_LE, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_IS_NULL, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_IS_ANY, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_IN, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_RANGE, $ignoreSpaces) || 
                    $this->isNextToken(Tokens::T_MATCH, $ignoreSpaces) 
                ;
            break;
        case Tokens::T_IDENTIFIER:
            $pos = $this->pos;
            if($ignoreSpaces) {
                $pos = $this->getPosAfterSpaces($pos);
            }

            // if alphabet or '_' is following, then identifier.
            return ctype_alpha($this->value[$pos]) || ('_' == $this->value[$pos]);
        default:
            $literal = $this->literals->getLiteralForToken($token);
            if($this->literals->isSpace($literal)) {
                $ignoreSpaces = false;
            }
            return $this->isNextLiteral($literal, $ignoreSpaces);
            break;
        }
    }