Re: [Pyparsing] Salvaging a failed parse
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2008-03-25 05:19:41
|
Greg - >>> Does PyParsing expose a method to convert this to a line/column like the ParseException does, or should I just count up the CR's and do the math myself? >>> Yes, pyparsing has lineno(loc,string) and col(loc,string) methods for converting an absolute loc into line number and column number. You can see them in use in the body of this FAQ: http://pyparsing-public.wikispaces.com/FAQs#toc2. The line(loc,string) function will give you the line of text corresponding to the loc value. (Beware when using col() if there are tabs in your input text. Pyparsing expands tabs to 8-space tabstops by default so column numbers may end up different than you expect. Use parseWithTabs to change this default behavior. The html docs that come with pyparsing have more details on this issue.) There are also usage examples in http://pyparsing.wikispaces.com/space/showimage/linenoExample.py. Sorry to not respond sooner, I was out of the country on vacation, and just getting my head back together. -- Paul |