Hi!

I'm writing a parser using pyparsing and I would like to augment the ParserException tracebacks with information about the actual error line *in the parsed text*. Pyparsing provides me with everything I need (parsed line and column), but is there a way to push that information on the traceback?


To make it a bit clearer, tracebacks currently look like this:

Traceback (most recent call last):
 ...
  File "/usr/lib/python2.4/site-packages/pyparsing.py", line 456, in parse
    loc,tokens = self.parseImpl( instring, loc, doActions )
  File "/usr/lib/python2.4/site-packages/pyparsing.py", line 727, in parseImpl
    raise exc
ParseException: Expected "SOMEOTHERTERM" (146), (5,9)


I want them to look like this:

Traceback (most recent call last):
 ...
  File "/usr/lib/python2.4/site-packages/pyparsing.py", line 456, in parse
    loc,tokens = self.parseImpl( instring, loc, doActions )
  File "/usr/lib/python2.4/site-packages/pyparsing.py", line 727, in parseImpl
    raise exc
  PyParsing, line 5, in SomeStatement
    PARSER TEST FOR TESTING MISSING TERM
ParseException: Expected "SOMEOTHERTERM" (146), (5,9)


where "PARSER TEST FOR TESTING MISSING TERM" is a line parsed by pyparsing that leads to raising a ParseException. I wouldn't mind too much not having the original traceback, though I'd prefer it. I remember having read somewhere that there is a way to embed an exceptions in another one, that might help.


How can I alter or create such Tracebacks?

Thanks,
Stefan
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to