// out: func(L tok, int cIndex) -> S // condition: func(L tok, int nIndex) -> S [yeah it's inconsistent] static S jreplace_dyn(S s, S in, O out) { ret jreplace_dyn(s, in, out, null); } sS jreplace_dyn(S s, S in, O out, O condition) { L tok = javaTok(s); jreplace_dyn(tok, in, out, condition); ret join(tok); } // leaves tok properly tokenized // returns true iff anything was replaced sbool jreplace_dyn(LS tok, S in, O out) { ret jreplace_dyn(tok, in, out, false, true, null); } sbool jreplace_dyn(LS tok, S in, IF0 out) { ret jreplace_dyn(tok, in, if0ToIF2(out)); } sbool jreplace_dyn(LS tok, S in, ITokCondition cond, IF0 out) { ret jreplace_dyn(tok, in, cond, if0ToIF2(out)); } sbool jreplace_dyn(LS tok, S in, IF1 out) { ret jreplace_dyn(tok, in, (_tok, cIdx) -> out.get(cIdx)); } sbool jreplace_dyn(LS tok, S in, IF2 out) { ret jreplace_dyn(tok, in, (O) out); } sbool jreplace_dyn(LS tok, S in, IF2 out, IF2 condition) { ret jreplace_dyn(tok, in, (O) out, (O) condition); } static boolean jreplace_dyn(L tok, S in, O out, O condition) { ret jreplace_dyn(tok, in, out, false, true, condition); } static boolean jreplace_dyn(L tok, S in, O out, boolean ignoreCase, boolean reTok, O condition) { L tokin = javaTok(in); jfind_preprocess(tokin); S[] toks = toStringArray(codeTokensOnly(tokin)); boolean anyChange = false; for (int n = 0; n < 10000; n++) { int i = findCodeTokens(tok, 1, ignoreCase, toks, condition); if (i < 0) ret anyChange; S expansion = cast callF(out, tok, i); int end = i+l(tokin)-2; clearAllTokens(tok, i, end); // C to C tok.set(i, unnull(expansion)); if (reTok) // would this ever be false?? reTok(tok, i, end); anyChange = true; } throw fail("woot? 10000! " + quote(in) + " => " + quote(out)); }