import re


def parse_range(range_str):
    """
    Generates an object of type range for the specified range.

    Parameters
    ----------
    range_str : str
        A string indicating a range. Corresponds to either of the
        following formats.

        * '[0-9]+'
        * '[0-9]+-[0-9]+'

    Returns
    -------
    range
    """
    if r := re.fullmatch(r'([0-9]+)-([0-9]+)', range_str):
        begin = int(r.groups()[0])
        end = int(r.groups()[1])
        if begin > end:
            begin, end = end, begin
    elif r := re.fullmatch(r'([0-9]+)', range_str):
        begin = end = int(r.group())
    else:
        raise ValueError("Wrong range format.")
    return range(begin, end + 1)