def parse_error_report(text, errstart, errstop, formatdesc):
    errmsg = 'Error: parsing %s failed' % formatdesc

    linenr, column, line = linenr_column_line(text, errstart)
    if line is None:
        return 1, 1, errmsg

    if errstop >= len(text):
        return linenr, column, errmsg + ', reached end of text before completing the grammar'

    # Use a line in which all printables are replaced by spaces
    # as a prefix to position the caret under the error position.
    blankline = re.sub(r'\S', ' ', line)
    blankline = blankline[:column-1]

    # We count each tab as four spaces and report the
    # column number after this expansion as this is common
    # in the column display of text editors.
    countingline = blankline.replace('\t', '    ')
    column = len(countingline) + 1

    # Draw squiggles under the offending token that
    # follows after the error position.
    errtoken = text[errstart:errstop]
    errtoken = errtoken.replace('\t', '    ')
    caretline = blankline + '^' + '~' * (len(errtoken) - 1)
    errortext = line.rstrip() + '\n' + caretline + '\n'
    errortext += errmsg

    return linenr, column, errortext
dataset/ETHPy150Open mikr/xcodeprojer/xcodeprojer.py/parse_error_report/original