code: private static void mergeTokens(List<Token> grouped, List<Integer> toMerge) {
      if (toMerge.size() > 0) {
        StringBuilder sb = new StringBuilder();
        int s = grouped.get(toMerge.get(0)).getSpan().getStart();
        int e = grouped.get(toMerge.get(toMerge.size() - 1)).getSpan().getEnd();
        for (int i = 0; i < toMerge.size(); i++) {
          int index = toMerge.get(i);
          sb.append(grouped.get(index).getLexeme() + "_");
        }
        String lexeme = sb.substring(0, sb.length() - 1);
        for (int i = toMerge.size() - 1; i > 0; i--) {
          grouped.remove(toMerge.get(i).intValue());
        }
        grouped.set(toMerge.get(0).intValue(), new TokenCogroo(lexeme, new Span(
            s, e)));
      }
    }
docs: /*  private static List<Token> groupTokens(List<Token> toks, List<Span> spans) {
  if (spans == null || spans.size() == 0) {
  return toks;
  }
  List<Token> grouped = new ArrayList<Token>(toks);
  int lastTokVisited = 0;
  List<Integer> toMerge = new ArrayList<Integer>();
  for (int i = 0; i < spans.size(); i++) {
  Span s = spans.get(i);
  boolean canStop = false;
  for (int j = lastTokVisited; j < toks.size(); j++) {
  Token t = toks.get(j);
  if (s.intersects(t.getSpan())) {
  toMerge.add(j);
  canStop = true;
  } else if (canStop) {
  lastTokVisited = j;
  break;
  }
  }
  }
  mergeTokens(grouped, toMerge);
  
  return grouped;
  }