static void tok_replaceWith(L tok) { int i; while ((i = jfind(tok, "replace with")) >= 0) { S token = tok.get(i+2); int repStart = i+6; int repEnd = smartIndexOf(tok, repStart, "."); S replacement = joinSubList(tok, repStart, repEnd-1); clearTokens(tok, i, repEnd+1); print("Replacing " + token + " with " + replacement + "."); int end = findEndOfBlock(repEnd)-1; for (int j = repEnd+2; j < end; j += 2) if (eq(tok.get(j), token)) tok.set(j, replacement); reTok(tok, i, end); } }