static O ai_parse_toList(S parse) { ret ai_parse_toList(parse, curlySep()); } // returns L or S static O ai_parse_toList(S parse, Pair sep) { assertNempty(sep.a); assertNempty(sep.b); int i = 0; new L stack; new StringBuilder buf; new L out; while ping (i < l(parse)) { if (substringAtIs(parse, i, sep.a)) { if (nempty(buf)) out.add(getAndClearStringBuilder(buf)); i += l(sep.a); stack.add(i); } else if (substringAtIs(parse, i, sep.b)) { int j = popLast(stack); if (empty(stack)) //out.add(ll(substring(parse, j, i))); out.add(ll(ai_parse_toList(substring(parse, j, i)))); i += l(sep.b); } else if (empty(stack)) buf.append(parse.charAt(i++)); else i++; } //if (empty(out)) ret parse; if (nempty(buf)) out.add(getAndClearStringBuilder(buf)); ret recursivelyUnpackSingleElementList(out); }