Georg Brandl avatar Georg Brandl committed b23a891

Allow giving lexer options to find_error script.

Comments (0)

Files changed (1)

scripts/find_error.py

 from pygments.lexer import RegexLexer
 from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
 from pygments.token import Error, Text, _TokenType
+from pygments.cmdline import _parse_options
 
 
 class DebuggingRegexLexer(RegexLexer):
                     break
 
 
-def main(fn, lexer=None):
+def main(fn, lexer=None, options={}):
     if lexer is not None:
         lx = get_lexer_by_name(lexer)
     else:
         try:
-            lx = get_lexer_for_filename(os.path.basename(fn))
+            lx = get_lexer_for_filename(os.path.basename(fn), **options)
         except ValueError:
             try:
                 name, rest = fn.split('_', 1)
-                lx = get_lexer_by_name(name)
+                lx = get_lexer_by_name(name, **options)
             except ValueError:
                 raise AssertionError('no lexer found for file %r' % fn)
     debug_lexer = False
     lno = 1
     text = file(fn, 'U').read()
     text = text.strip('\n') + '\n'
-    text = text.decode('latin1')
     tokens = []
     states = []
 
 num = 10
 showall = False
 lexer = None
+options = {}
 
 if __name__ == '__main__':
     import getopt
-    opts, args = getopt.getopt(sys.argv[1:], 'n:l:a')
+    opts, args = getopt.getopt(sys.argv[1:], 'n:l:aO:')
     for opt, val in opts:
         if opt == '-n':
             num = int(val)
             showall = True
         elif opt == '-l':
             lexer = val
+        elif opt == '-O':
+            options = _parse_options([val])
     ret = 0
     for f in args:
-        ret += main(f, lexer)
+        ret += main(f, lexer, options)
     sys.exit(bool(ret))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.