diff options
author | Georg Brandl <georg@python.org> | 2014-03-04 14:17:10 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-03-04 14:17:10 +0100 |
commit | 18348a61d7e90b03a624fdc78fafdcb46b92307d (patch) | |
tree | e4fe1541ad9e2ada2de394eb2e020e2a0916ce94 /scripts/find_error.py | |
parent | cd9c0b70635f2a6c65ea97d042537478a0a95b7a (diff) | |
parent | 27895fe85076d2f1b44e7d30387b3f459fc60281 (diff) | |
download | pygments-18348a61d7e90b03a624fdc78fafdcb46b92307d.tar.gz |
merge with raichoo/pygments-main (pull request #210)
Diffstat (limited to 'scripts/find_error.py')
-rwxr-xr-x | scripts/find_error.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/scripts/find_error.py b/scripts/find_error.py index 00923569..7aaa9bee 100755 --- a/scripts/find_error.py +++ b/scripts/find_error.py @@ -8,11 +8,14 @@ the text where Error tokens are being generated, along with some context. - :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -import sys, os +from __future__ import print_function + +import os +import sys # always prefer Pygments from source if exists srcpath = os.path.join(os.path.dirname(__file__), '..') @@ -104,36 +107,36 @@ def main(fn, lexer=None, options={}): # already debugged before debug_lexer = True lno = 1 - text = file(fn, 'U').read() + text = open(fn, 'U').read() text = text.strip('\n') + '\n' tokens = [] states = [] def show_token(tok, state): reprs = map(repr, tok) - print ' ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0], + print(' ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0], end=' ') if debug_lexer: - print ' ' + ' ' * (29-len(reprs[0])) + repr(state), - print + print(' ' + ' ' * (29-len(reprs[0])) + repr(state), end=' ') + 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 '') + ':' + print('Error parsing', fn, 'on line', lno) + print('Previous tokens' + (debug_lexer and ' and states' or '') + ':') if showall: for tok, state in map(None, tokens, states): show_token(tok, state) else: for i in range(max(len(tokens) - num, 0), len(tokens)): show_token(tokens[i], states[i]) - print 'Error token:' + print('Error token:') l = len(repr(val)) - print ' ' + repr(val), + print(' ' + repr(val), end=' ') if debug_lexer and hasattr(lx, 'statestack'): - print ' ' * (60-l) + repr(lx.statestack), - print - print + print(' ' * (60-l) + repr(lx.statestack), end=' ') + print() + print() return 1 tokens.append((type, val)) if debug_lexer: |