code: function countBrackets(str) {
      var lex = getLexer(str);
      var brackets = 0;
      var tok = lex.next();
      while (tok!==undefined) {
        if (tok.str=="(" || tok.str=="{" || tok.str=="[") brackets++;
        if (tok.str==")" || tok.str=="}" || tok.str=="]") brackets--;
        tok = lex.next();
      }
      return brackets;
    }
docs: Count brackets in a string - will be 0 if all are closed