// 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) { ret getBracketMap(tok, opening, closing, 0, l(tok)); } static Map getBracketMap(L tok, Cl opening, Cl closing, int from, int to) { new TreeMap map; new L stack; for (int i = from|1; i < to; i+= 2) { O t = tok.get(i); if (opening.contains(t)) stack.add(i); else if (closing.contains(t)) if (!empty(stack)) map.put(liftLast(stack), i); } ret map; } static Map getBracketMap(LS tok, IPred opening, IPred closing) { ret getBracketMap(tok, opening, closing, 0, l(tok)); } static Map getBracketMap(LS tok, IPred opening, IPred closing, int from, int to) { new TreeMap map; new L stack; for (int i = from|1; i < to; i+= 2) { S t = tok.get(i); if (opening.get(t)) stack.add(i); else if (closing.get(t)) if (!empty(stack)) map.put(liftLast(stack), i); } ret map; } static Set getBracketMap_opening = lithashset("{", "("); static Set getBracketMap_closing = lithashset("}", ")");