Report position in source sequence on ParseError

Bug #566837 reported by Cory Dodt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PyMeta
Status tracked in Trunk
Trunk
Fix Released
Undecided
Unassigned

Bug Description

This fairly simple change is enormously helpful to me in debugging my grammars. I would like something like this in the standard apply implementation:

        try:
            return self.apply(rule)
        except ParseError:
            if DEBUG: # pragma: nocover
                _debugShow(self)
            raise

def _debugShow(parser):
    """
    Show where parsing failed
    """
    pos = parser.input.position
    data = parser.input.data
    left, right = map(''.join, [data[:pos], data[pos:]])
    lineno = left.count('\n')
    print lineno,
    if len(left) > 20:
        print repr('...' + left[-20:]),
    print '!!',
    if len(right) > 20:
        print repr(right[:20] + '...')

Of course this would have to be somewhat modified to handle non-string sequences.

Revision history for this message
Allen Short (washort) wrote :

I think ParseError.formatError addresses this now.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.