sbool matchDoubleRest(S pat, S s) {
  ret matchDoubleRest(pat, s, null);
}

// matches are as you expect, plus an extra item for half of the rest string
sbool matchDoubleRest(S pat, S s, Matches matches) {
  if (s == null) false;
  ret matchDoubleRest(pat, parse3_cachedInput(s), matches);
}
  
sbool matchDoubleRest(S pat, LS toks, Matches matches) {
  if (toks == null) false;
  LS tokpat = parse3_cachedPattern(pat);
  int n = toks.size(), nPat = tokpat.size();
  if (n <= nPat || odd((n-nPat)/2)) ret false;
  int nRest = (n-nPat)/4;
  ifdef matchDoubleRest_debug
    print(+nRest);
  endifdef
  S[] m = match2(tokpat, subList(toks, 0, nPat));
  if (m == null) false;
  for (int i = nPat; i < nRest*2; i += 2)
    if (neqic(toks.get(i), toks.get(i+nRest*2)))
      false;
      
  if (matches != null) {
    matches.m = new S[m.length+1];
    arraycopy(m, matches.m);
    matches.m[m.length] = joinSubList(toks, nPat, nPat+nRest*2-1); // for Matches.rest()
  }
  
  true;
}