@classmethod
def _parse_error(cls, s, match, expecting):
    """
        Display a friendly error message when parsing a tree string fails.
        :param s: The string we're parsing.
        :param match: regexp match of the problem token.
        :param expecting: what we expected to see instead.
        """
    if match == 'end-of-string':
        pos, token = len(s), 'end-of-string'
    else:
        pos, token = match.start(), match.group()
    msg = '%s.parse(): expected %r but got %r\n%sat index %d.' % (cls.
        __name__, expecting, token, ' ' * 12, pos)
    s = s.replace('\n', ' ').replace('\t', ' ')
    offset = pos
    if len(s) > pos + 10:
        s = s[:pos + 10] + '...'
    if pos > 10:
        s = '...' + s[pos - 10:]
        offset = 13
    msg += '\n%s"%s"\n%s^' % (' ' * 16, s, ' ' * (17 + offset))
    raise ValueError(msg)
