def print_error(input, err, scanner):
    """This is a really dumb long function to print error messages nicely."""
    p = err.pos
    line = '\n'.count(input[:p])
    print(err.msg + ' on line ' + repr(line + 1) + ':')
    text = input[max(p - 80, 0):p + 80]
    p = p - max(p - 80, 0)
    i = text[:p].rfind('\n')
    j = text[:p].rfind('\r')
    if i < 0 or 0 <= j < i:
        i = j
    if 0 <= i < p:
        p = p - i - 1
        text = text[i + 1:]
    i = text.find('\n', p)
    j = text.find('\r', p)
    if i < 0 or 0 <= j < i:
        i = j
    if i >= 0:
        text = text[:i]
    while len(text) > 70 and p > 60:
        text = '...' + text[10:]
        p = p - 7
    print('> ', text)
    print('> ', ' ' * p + '^')
    print('List of nearby tokens:', scanner)
