Improve html_toc.py parser error messages.
authorW. Trevor King <wking@drexel.edu>
Tue, 14 Sep 2010 17:38:29 +0000 (13:38 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 14 Sep 2010 17:38:29 +0000 (13:38 -0400)
_script/html_toc.py

index 0375deda4bf8e9b8bda7250a687cb0c5d1e79dd3..b530fad95a5f0cf0f2ddd12636e588513557828f 100755 (executable)
@@ -47,8 +47,12 @@ class ToCTree (object):
         tree = etree.parse(StringIO('\n'.join(lines)), parser=parser)
         if len(parser.error_log) > 0:
             print >> sys.stderr, '%s: parsing error' % self._path
-            print >> sys.stderr, '(listed lines offset by +2)'
-            print >> sys.stderr, parser.error_log
+            for error in parser.error_log:
+                print >> sys.stderr, '  '+'\n  '.join([
+                        '%s (line %d)' % (error.message, error.line-2),
+                        '  '+lines[error.line][:error.column],
+                        '  '+' '*error.column + lines[error.line][error.column:],
+                        ])
         return (tree, 2)
 
     def _page_title(self):