def citation_grouper(paper):
    """
    Don't call this directly -- use one of the dictionary or database functions instead.
    Given a soupified XML paper, returns a list of the 'citation groups' within that paper.
    A citation group is all of the papers that are cited together at a certain point in the paper -- the bare stuff of inline co-citations.
    So, for example, a citation group might simply be [1], or it could be [2]-[10], or even [11], [13]-[17], [21].
    The elements within the returned list are themselves lists of soupified XML elements corresponding to citations and connectives.
    """
    groups = []
    cite = paper.find(attrs={'ref-type': 'bibr'})
    while cite:
        group = [cite]
        next = cite.next_sibling
        while next and (next.name == 'xref' and next['ref-type'] == 'bibr' or
            (next == ', ' or next == ',' or next == '–' or next == '-' or 
            next == '—' or next == ' ') and (next.next_sibling and next.
            next_sibling.name == 'xref' and next.next_sibling['ref-type'] ==
            'bibr')):
            group.append(next)
            next = next.next_sibling
        groups.append(group)
        try:
            cite = next.find_next(attrs={'ref-type': 'bibr'})
        except AttributeError:
            cite = cite.find_next(attrs={'ref-type': 'bibr'})
    return groups
