// places must be sorted static L reTok_multi(L tok, L> places) { if (empty(places)) ret tok; L orig = cloneList(tok); new L> places2; for (Pair p : places) { p = pair(p.a & ~1, p.b | 1); if (nempty(places2) && p.a <= last(places2).b) last(places2).b = p.b; else places2.add(p); } ifdef reTok_multi_debug printStruct("places: ", places); endifdef int iPlace = 0, n = l(orig); Pair p = get(places, iPlace); tok.clear(); int i = 0, next = p.a; while (i < n) if (i < next) tok.add(orig.get(i++)); else { int j = p.b; S s = joinSubList(orig, i, j); ifdef reTok_multi_debug printStruct("retokking: ", s); endifdef tok.addAll(javaTok(s)); i = j; p = get(places, ++iPlace); if (p == null) break; next = p.a; } while (i < n) tok.add(orig.get(i++)); ret tok; }