@SuppressWarnings("unchecked")
  Object getMatchResult(String args[], int idx, int cnt, String errMsg,
    int resultIdx) {
    boolean exceptionThrown = false;
    int k = 0;
    try {
      k = parser.matchArg(args, idx);
    } catch (Exception e) {
      exceptionThrown = true;
      checkException(e, errMsg);
    }
    if (!exceptionThrown) {
      verify(k == idx + cnt, "Expecting result index " + (idx + cnt) + ", got "
          + k);
      Object result = parser.getResultHolder(args[0]);
      if (resultIdx >= 0) {
        verify(result instanceof Vector<?>,
          "Expecting result to be stored in a vector");
        Vector<Object> vec = (Vector<Object>) result;
        verify(vec.size() == resultIdx + 1, "Expecting result vector size "
            + (resultIdx + 1));
        return vec.get(resultIdx);
      } else {
        return result;
      }
    } else {
      return null;
    }
  }