summaryrefslogtreecommitdiff
path: root/scripts/find_error.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/find_error.py')
-rw-r--r--scripts/find_error.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/find_error.py b/scripts/find_error.py
new file mode 100644
index 00000000..ac50a1d1
--- /dev/null
+++ b/scripts/find_error.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+ Lexing error finder
+ ~~~~~~~~~~~~~~~~~~~
+
+ For the source files given on the command line, display
+ the text where Error tokens are being generated, along
+ with some context.
+
+ :copyright: 2006 by Tim Hatch <tim@timhatch.com>.
+ :license: BSD, see LICENSE for more details.
+"""
+
+import sys
+
+from pygments import highlight
+from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
+from pygments.token import Error
+
+def main(fn):
+ try:
+ lx = get_lexer_for_filename(fn)
+ except ValueError:
+ try:
+ name, rest = fn.split("_", 1)
+ lx = get_lexer_by_name(name)
+ except ValueError:
+ raise AssertionError('no lexer found for file %r' % fn)
+ text = file(fn, 'U').read()
+ text = text.strip('\n') + '\n'
+ text = text.decode('latin1')
+ ntext = []
+ for type, val in lx.get_tokens(text):
+ if type == Error:
+ print "Error parsing", fn
+ print "\n".join([' ' + repr(x) for x in ntext[-5:]])
+ print `val` + "<<<"
+ return
+ ntext.append((type,val))
+
+
+if __name__ == "__main__":
+ for f in sys.argv[1:]:
+ main(f)