svoid tok_embeddedFunctions(L tok) { int i; while ((i = jfind(tok, "embedded ")) >= 0) { int j = tok_findEndOfMethodDecl(tok, i); // points to N after function S functionName = tok_functionName(subList(tok, i)); S className = makeVar("C"), varName = makeVar(); // drop keyword, rewrite function to class, create object //tok.set(i, "/* make final to optimize */ class " + className + " {"); tok.set(i, "final class " + className + " {"); tokAppend(tok, j-1, " } " + " final " + className + " " + varName + " = new " + className + "();"); // redirect calls to object int end = findEndOfBlock(tok, j)-1; for (j |= 1; j < end; j += 2) if (eq(tok.get(j), functionName) && eqGet(tok, j+2, "(")) tokPrepend(tok, j, varName + "."); reTok(tok, i, end); } }