!752 p { L tok = javaTok(loadSnippet("#1002095")); replaceToken(tok, "push_back", "add"); jreplace(tok, "int main()", "p"); // throw away stuff jreplace(tok, "using namespace std;", ""); jreplace(tok, "#include <*>", ""); // list, vector jreplace(tok, "list<", "new LinkedList<"); jreplace(tok, "vector<", "new ArrayList<"); jreplace(tok, "deque<*> *;", "LinkedList<$3> $4 = cppLinkedList("); // TODO jreplace(tok, "*.resize(", "resizeCollection($1, 0,"); jreplace(tok, "copy(*.begin(), *.end(), *.begin())", "cppCopy($3, $15)"); // cout jreplace(tok, "cout << * << endl", "print($4)"); print(); print("!752\n\n" + join(tok)); } static void jreplace(L tok, S in, S out) { L tokin = javaTok(in); for (int n = 0; n < 10000; n++) { int i = findCodeTokens(tok, toStringArray(codeTokensOnly(tokin))); if (i < 0) { replaceCollection(tok, javaTok(tok)); ret; } L subList = tok.subList(i-1, i+l(tokin)); S expansion = expandRefs(out, subList); clearAllTokens(tok.subList(i, i+l(tokin)-2)); tok.set(i, expansion); } throw fail("woot? 10000!"); } // "$1" is first code token, "$2" second code token etc. static S expandRefs(S s, L tokref) { L tok = javaTok(s); for (int i = 1; i < l(tok)-2; i += 2) { if (tok.get(i).startsWith("$") && isInteger(tok.get(i).substring(1))) { S x = tokref.get(-1+parseInt(tok.get(i).substring(1))*2); tok.set(i, x); } } ret join(tok); }