scope tok_findRewrites sclass #Found { LS tok; S token; int repStart, repEnd; S replacement() { ret joinSubList(tok, repStart, repEnd-1); } } // rewrite [=|with|to] // - a global version of "replace with" svoid tok_findRewrites(LS tok, IVF1 callback, SS rewrites default null) { int i; while ((i = jfind(tok, "rewrite ", (_tok, nIdx) -> eqGetOneOf(_tok, nIdx+5, "with", "=", "to"))) >= 0) { new Found f; f.tok = tok; f.token = tok.get(i+2); f.repStart = i+6; f.repEnd = smartIndexOf(tok, f.repStart, "."); // TODO: allow expressions with brackets callF(callback, f); rewrites?.put(f.token, f.replacement()); } }