def _check_token_spans(token, token_start, token_end, prev_index):
    """Check that token fits into its span; output a helpful message is it doesn't."""
    if len(token) > token_end - token_start:
        raise ValueError(
            'Token is longer than its allocated span.\nToken: {}\nSpan: ({}, {})'
            .format(token, token_start, token_end))
    if token_start < prev_index:
        raise ValueError('Overlapping token spans.\nToken: {}\nSpan: ({}, {})'
            .format(token, token_start, token_end))
