// map: index of opening bracket -> index of closing bracket static Map getBracketMap(L tok) { ret getBracketMap(tok, getBracketMap_opening, getBracketMap_closing); } static Map getBracketMap(L tok, Collection opening, Collection closing) { new TreeMap map; new L stack; for (int i = 1; i < l(tok); i+= 2) { if (opening.contains(tok.get(i))) stack.add(i); else if (closing.contains(tok.get(i))) { if (!empty(stack)) map.put(liftLast(stack), i); } } ret map; } static Set getBracketMap_opening = lithashset("{", "("); static Set getBracketMap_closing = lithashset("}", ")");