code: public boolean isBalanced(RecoveryMode mode, CSSLexerState state, CSSToken t) {
          if (mode == RecoveryMode.BALANCED)
              return !aposOpen && !quotOpen && curlyNest == 0 && parenNest == 0 && sqNest == 0;
          else if (mode == RecoveryMode.FUNCTION)
              return parenNest == 0 && sqNest == 0;
          else if (mode == RecoveryMode.RULE)
              return !aposOpen && !quotOpen && parenNest == 0 && sqNest == 0;
          else if (mode == RecoveryMode.DECL) {
              if (t.getType() == CSSLexer.RCURLY) //if '}' is processed the curlyNest has been already decreased
                  return !aposOpen && !quotOpen && parenNest == 0 && sqNest == 0 && curlyNest == state.curlyNest - 1;
              else
                  return !aposOpen && !quotOpen && parenNest == 0 && sqNest == 0 && curlyNest == state.curlyNest;
          } else
              return true;
      }
docs: Checks whether some pair characters are balanced. Modes are:
  <ul>
  <li>BALANCED - everything must be balanced: single and double quotatation marks, curly braces, parentheses
  <li>FUNCTION - within the function arguments: parentheses must be balanced
  <li>RULE - within the CSS rule: all but curly braces
  <li>DECL - within declaration: all, keep curly braces at desired state
  </ul>
  
  @param mode  the desired recovery node
  @param state the required lexer state (used for DECL mode)
  @param t     the token that is being processed (used for DECL mode)