!752 answer { if (!attn()) ret null; if (jmatchStart("tree", s, m)) { S snl = m.rest().trim(); L tok = codeTokensOnly(nlTok(snl)); //new L out; //printTree(tok, i, out); //ret slackSnippet(out); ret structure(getTree(tok)); ] } static Lisp tree(L tok) { ret tree(tok, 0, l(tok)); } static Lisp tree(L tok, int i, int j) { ret lisp(join(" ", subList(tok, 0, i))); } static Lisp getTree(L tok) { if (empty(tok)) ret lisp("_empty"); int i = indexOfOperator(tok, 0); if (i >= l(tok)) ret tree(tok); S op = tok.get(i); if (eq(op, "<")) { ret lisp("* < *", getTree(subList(tok, 0, i)), getTree(subList(tok, i+1)); } else if (eq(op, ">")) { ret lisp("* > *", getTree(subList(tok, 0, i)), getTree(subList(tok, i+1)); } else if (eq(op, "[")) { int j = snlEndOfBrackets(tok, i); } } // i must point at the opening bracket (any of the 2 types, not type parameters) // index returned is index of closing bracket + 1 static int snlEndOfBrackets(List tok, int i) { int j = i+1, level = 1; while (j < tok.size()) { if (litlist("[", "(").contains(tok.get(j))) ++level; else if (litlist("]", ")").contains(tok.get(j))) --level; if (level == 0) retj+1; ++j; } return l(tok); } /* static void printTree(L tok, int indent, L out) { if (empty(tok)) ret; int i = indexOfOperator(tok, 0); if (i >= l(tok)) { out.add(indent(indent) + join(" ", tok)); ret; } S op = tok.get(i); if (eq(op, "<")) { out.add(indent(indent) + join(" ", subList(tok, 0, i))); printTree(subList(tok, i+1)); } else if (eq(op, ">")) { out.add(indent(indent) + join(" ", subList(tok, 0, i))); printTree(subList(tok, i+1)); } }*/ static static int indexOfOperator(L tok, int i) { while (i < l(tok) && !isOperator(tok.get(i))) ++i; ret i; } static L operators = litlist("<", ">", "[", "]", "(", ")"); static boolean isOperator(S t) { ret operators.contains(t); }