summaryrefslogtreecommitdiff
path: root/scripts/find_error.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-02-21 21:32:39 +0100
committerGeorg Brandl <georg@python.org>2010-02-21 21:32:39 +0100
commit29262b9dd70478e3caccb7bcf7480a18eb0b0338 (patch)
tree54db12757643e1663e03b96fac10a401862564a3 /scripts/find_error.py
parent95148c179c14de2e82935641a3072893812572e3 (diff)
downloadpygments-29262b9dd70478e3caccb7bcf7480a18eb0b0338.tar.gz
Add an option to show all tokens.
Diffstat (limited to 'scripts/find_error.py')
-rwxr-xr-xscripts/find_error.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/scripts/find_error.py b/scripts/find_error.py
index 82914b50..82a74de0 100755
--- a/scripts/find_error.py
+++ b/scripts/find_error.py
@@ -21,10 +21,9 @@ except ImportError:
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
-from pygments import highlight
from pygments.lexer import RegexLexer
from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
-from pygments.token import Error, _TokenType
+from pygments.token import Error, Text, _TokenType
class DebuggingRegexLexer(RegexLexer):
@@ -104,17 +103,21 @@ def main(fn):
text = text.decode('latin1')
ntext = []
states = []
+
+ def show_token(tok):
+ reprs = map(repr, tok)
+ print ' ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0],
+ if debug_lexer:
+ print ' ' + ' ' * (29-len(reprs[0])) + repr(states[i]),
+ print
+
for type, val in lx.get_tokens(text):
lno += val.count('\n')
if type == Error:
print 'Error parsing', fn, 'on line', lno
print 'Previous tokens' + (debug_lexer and ' and states' or '') + ':'
for i in range(len(ntext) - num, len(ntext)):
- reprs = map(repr, ntext[i])
- print ' ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0],
- if debug_lexer:
- print ' ' + ' ' * (29-len(reprs[0])) + repr(states[i]),
- print
+ show_token(ntext[i])
print 'Error token:'
l = len(repr(val))
print ' ' + repr(val),
@@ -126,16 +129,24 @@ def main(fn):
ntext.append((type,val))
if debug_lexer:
states.append(lx.statestack[:])
+ if showall:
+ for tok in ntext:
+ show_token(tok)
return 0
num = 10
+showall = False
if __name__ == '__main__':
- if sys.argv[1][:2] == '-n':
- num = int(sys.argv[1][2:])
- del sys.argv[1]
+ import getopt
+ opts, args = getopt.getopt(sys.argv[1:], 'n:a')
+ for opt, val in opts:
+ if opt == '-n':
+ num = int(val)
+ elif opt == '-a':
+ showall = True
ret = 0
- for f in sys.argv[1:]:
+ for f in args:
ret += main(f)
sys.exit(bool(ret))