public int findClosingPeer(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 prevToken = NOT_FOUND;
        int offset = start;
        while (true) {
            token = nextToken(offset, document.getLength());
            offset = getPosition();

            if (token == SQLIndentSymbols.TokenEOF) {
                return NOT_FOUND;
            }

            if (token == openingPeer && prevToken != headCancelToken) {
                depth++;
            } else if ((closingPeerEnd == UNBOUND && token == closingPeer) || (prevToken == closingPeer && token == closingPeerEnd)) {
                depth--;
            }

            if (depth == 0) {
                return offset;
            }
            
            prevToken = token;
        }
    }
Returns the position of the closing peer token (forward search). Any scopes introduced by opening 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 opening peer, but to the first
token being searched.</p>

@param start       the start position
@param blockInfo information about opening peer character (e.g. 'begin'), closing peer character (e.g. 'end') and 
@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