static void tok_doubleFor_v2(L tok) { for (int i : indexesOf(tok, "for (")) { int argsFrom = i+4; int iColon = indexOfAny(tok, argsFrom, ":", ")"); if (neq(get(tok, iColon), ":")) continue; tok_typesAndNamesOfParams_keepModifiers.set(true); L> args = tok_typesAndNamesOfParams(subList(tok, argsFrom-1, iColon-1)); if (l(args) != 2) continue; // simple for or a three-argument for (out of this world!) int iClosing = indexOf(tok, iColon+1, ")"); if (iClosing < 0) continue; int iCurly = iClosing+2; if (neq(get(tok, iCurly), "{")) fail("please use { with double for"); int iCurlyEnd = findEndOfStatement(tok, iCurly)-1; if (iCurlyEnd < 0) continue; // complicated expression? evaluate to variable first S exp = trimJoinSubList(tok, iColon+2, iClosing-1); if (!isIdentifier(exp)) { S expVar = makeVar(); tokPrepend(tok, i, "{ final " + expVar + " = " + exp + "; "); tokAppend(tok, iCurlyEnd, "}"); replaceTokens(tok, iColon+2, iClosing-1, expVar); exp = expVar; } tokAppend(tok, iColon, " keys("); tokPrepend(tok, iClosing, ")"); replaceTokens(tok, argsFrom, iColon-1, joinPairWithSpace(first(args))); tokAppend(iCurly, " " + joinPairWithSpace(second(args)) + " =" + exp + ".get(" + first(args).b + "); "); } }