def column(lexdata, lexpos):
    """ Calculate the (1-indexed) column number given the input data and the current position. """
    last_cr = lexdata.rfind('\n', 0, lexpos)
    if last_cr < 0:
        return lexpos + 1
    else:
        return lexpos - last_cr