public int findOpeningPeer(int start, SQLBlockCompletionInfo blockInfo) {
        assert (start < document.getLength());
        int openingPeer = blockInfo.getHeadTokenId();
        int closingPeer = blockInfo.getTailTokenId();
        int closingPeerEnd = blockInfo.getTailEndTokenId() != null ? blockInfo.getTailEndTokenId() : UNBOUND;
        int headCancelToken = blockInfo.getHeadCancelTokenId() != null ? blockInfo.getHeadCancelTokenId() : UNBOUND;
        
        int depth = 1;
        start += 1;
        int token;
        int nextToken = NOT_FOUND;
        int offset = start;
        int nextTokenOffset = NOT_FOUND;
        do {
            token = previousToken(offset, UNBOUND);
            offset = getPosition();
            if (token == closingPeer && (closingPeerEnd == UNBOUND || nextToken == closingPeerEnd)) {
                depth++;
            } else if ((headCancelToken == UNBOUND && token == openingPeer) || (headCancelToken != UNBOUND && (
                (headCancelToken != token && nextToken == openingPeer)
            ))) {
                depth--;
            }

            if (depth == 0) {
                if (offset == -1) {
                    return 0;
                }
                return headCancelToken == UNBOUND ? offset : nextTokenOffset;
            }
            nextToken = token;
            nextTokenOffset = offset;
        } while (token != SQLIndentSymbols.TokenEOF);
        return NOT_FOUND;
    }
Returns the position of the opening peer token (backward search). Any scopes introduced by closing peers are
skipped. All peers accounted for must reside in the default partition.
<p/>
<p>
Note that <code>start</code> must not point to the closing peer, but to the first token being searched.
</p>

@param start the start position
@param blockInfo information about completion block
@return the matching peer character position, or <code>NOT_FOUND</code>
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLHeuristicScanner.java