sbool tok_recordDecls_autoWithToList = true; static void tok_recordDecls(L tok) { int i; bool re = false; jreplace(tok, "record {", "record $2() {"); jreplace(tok, "record implements", "record $2() implements"); while ((i = jfind_any(tok, "record (", "record <")) >= 0) { int argsFrom = smartIndexOf(tok, i, "(")+2; int argsTo = findCodeTokens(tok, argsFrom, 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, ""); bool withToList = eq(get(tok, i-2), "withToList"); if (withToList) tok.set(i-2, ""); withToList = withToList || tok_recordDecls_autoWithToList; new StringBuilder buf; L tArgs = subList(tok, argsFrom-1, argsTo); LPairS args = tok_typesAndNamesOfParams(tArgs, typelessMeansObject := true); L contents = subList(tok, idx+1, j); for (Pair p : args) buf.append("\n " + jreplace(p.a, "...", "[]") + " " + p.b + ";"); if (nempty(args)) 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)); } if (withToList) buf.append(tok_genRecordFieldsToList(args)); tok.set(idx, (!withToList ? "" : (contains(subList(tok, argsTo, idx), "implements") ? "," : "implements") + " IFieldsToList ") + "{" + 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); }