code: function selector(toks, i, n, allowSemi) {
      var s = i;
      // The definition of any above can be summed up as
      //   "any run of token except ('[', ']', '(', ')', ':', ';', '{', '}')
      //    or nested runs of parenthesized tokens or square bracketed tokens".
      // Spaces are significant in the selector.
      // Selector is used as (selector?) so the below looks for (any*) for
      // simplicity.
      var tok;
      // Keeping a stack pointer actually causes this to minify better since
      // ".length" and ".push" are a lo of chars.
      var brackets = [], stackLast = -1;
      for (;i < n; ++i) {
        tok = toks[i].charAt(0);
        if (tok === '[' || tok === '(') {
          brackets[++stackLast] = tok;
        } else if ((tok === ']' && brackets[stackLast] === '[') ||
                   (tok === ')' && brackets[stackLast] === '(')) {
          --stackLast;
        } else if (tok === '{' || tok === '}' || tok === ';' || tok === '@'
                   || (tok === ':' && !allowSemi)) {
          break;
        }
      }
      if (stackLast >= 0) {
        // Returns the bitwise inverse of i+1 to indicate an error in the
        // token stream so that clients can ignore it.
        i = ~(i+1);
      }
      return i;
    }
docs: selector    : any+; any         : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING | DELIM | URI | HASH | UNICODE-RANGE | INCLUDES | FUNCTION S* any* ')' | DASHMATCH | '(' S* any* ')' | '[' S* any* ']' ] S*; A negative return value, rv, indicates the selector was malformed and the index at which we stopped is ~rv.