static LS findFunctionDefsAtCurlyLevel_indexed(int targetCurlyLevel, IContentsIndexedList2 tok) { new LS functions; new OrderedMultiIterator multiIterator; for (keyword : findFunctionDefs_keywords()) multiIterator.add(tok.indicesOf_treeSetOfHasIndex(keyword)); multiIterator.add(tok.indicesOf_treeSetOfHasIndex("{")); multiIterator.add(tok.indicesOf_treeSetOfHasIndex("}")); multiIterator.add(tok.indicesOf_treeSetOfHasIndex("meta")); int curlyLevel = 0; new BitSet ignore; while (multiIterator.hasNext()) { HasIndex idx = multiIterator.next(); int i = idx!; if (ignore.get(i)) continue; S t = tok.get(i); // Account for meta-for (don't change curly level) if (eq(t, "meta")) { if (eqSubList(tok, i+1, "", "-", "", "for")) { var r = tok_findFirstBlock(tok, i); ignore.set(r.start); ignore.set(r.end-1); } } else if (eq(t, "{")) ++curlyLevel; else if (eq(t, "}")) --curlyLevel; else // it's a function keyword if (curlyLevel == targetCurlyLevel) findFunctionDefs_step(tok, i, functions); } ret functions; }