!7 static void tok_recordDecls(L tok) { int i; bool re = false; while ((i = jfind(tok, "record (")) >= 0) { int argsFrom = i+6, argsTo = findCodeTokens(tok, i, false, ")"); int idx = findCodeTokens(tok, argsTo, false, "{"); int j = findEndOfBracketPart(tok, idx); S name = tok.get(i+2); bool noEq = eq(get(tok, i-2), "noeq"); if (noEq) tok.set(i-2, ""); bool noToString = eq(get(tok, i-2), "noToString"); if (noToString) tok.set(i-2, ""); new StringBuilder buf; L tArgs = subList(tok, argsFrom-1, argsTo); L> args = tok_typesAndNamesOfParams(tArgs); L contents = subList(tok, idx+1, j); for (Pair p : args) buf.append("\n " + jreplace(p.a, "...", "[]") + " " + p.b + ";"); buf.append("\n *() {}"); buf.append("\n *(" + joinWithComma(map(args, func(Pair p) -> S { dropPrefix("new ", p.a) + " *" + p.b })) + ") {}"); if (!noToString && !(jfind(contents, "toString {") >= 0 || jfind(contents, "toString()") >= 0)) buf.append("\n toString { ret " + quote(name + "(") + " + " + join([[ + ", " + ]], secondOfPairs(args)) + " + \")\"; }"); if (!noEq) { //buf.append("\n [stdEq]"); buf.append(tok_genEqualsAndHashCode(name, args)); } tok.set(idx, "{" + buf); tok.set(i, "class"); clearTokens(tok, argsFrom-2, argsTo+1); reTok(tok, i, idx+1); tok_addFieldOrder(tok, i); set re; } if (re) reTok(tok); } static bool allVarNames_debug = true; static L allVarNames(L tok) { print(join(tok)); bool debug = allVarNames_debug; Map bracketMap = getBracketMap(tok); new L varNames; for (int i = 3; i < tok.size(); i += 2) { S t = tok.get(i); print("Got token: " + t); if (eqOneOf(t, "=", ";", ",")) { S v = tok.get(i-2); if (isIdentifier(v)) varNames.add(v); if (eq(t, "=")) { i = scanToEndOfInitializer(tok, bracketMap, i)+1; assertTrue(odd(i)); } } else if (eq(t, "<")) { i = findEndOfTypeArgs(tok, i)+1; if (debug) print("Skipped type args: " + struct(subList(tok, i))); } else if (eqOneOf(t, "{", "(")) { int j = findEndOfBracketPart(tok, i)-1; // skip function/class bodies if (debug) print("Skipping body " + (j-i)/2); i = j; } } return varNames; } p-exp { LS tok = javaTok([[record Definition(S word, S definition) {}]]); tok_recordDecls(tok); print(join(tok)); assertTrue(join(tok).contains([[_fieldOrder = "word definition"]])); print("OK"); }