Report position in source sequence on ParseError
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
raise
def _debugShow(parser):
"""
Show where parsing failed
"""
pos = parser.
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.
I think ParseError. formatError addresses this now.