| 1 |
#!/usr/bin/env python |
| 2 |
""" |
| 3 |
Checker for whitespace tokens |
| 4 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5 |
|
| 6 |
Helper script to find whitespace which is not of token type `Whitespace` |
| 7 |
|
| 8 |
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS. |
| 9 |
:license: BSD, see LICENSE for details. |
| 10 |
""" |
| 11 |
import argparse |
| 12 |
import sys |
| 13 |
import re |
| 14 |
|
| 15 |
from utility import unpack_output_file, process_output_files |
| 16 |
|
| 17 |
|
| 18 |
def check_file(path): |
| 19 |
whitespace_re = re.compile('\\s+') |
| 20 |
|
| 21 |
for value, token, linenumber in unpack_output_file(path): |
| 22 |
if whitespace_re.fullmatch(value): |
| 23 |
# We allow " " if it's inside a Literal.String for example |
| 24 |
if 'Literal' in token: |
| 25 |
continue |
| 26 |
|
| 27 |
# If whitespace is part of a comment, we accept that as well, |
| 28 |
# as comments may be similarly highlighted to literals |
| 29 |
if 'Comment' in token: |
| 30 |
continue |
| 31 |
|
| 32 |
if 'Whitespace' in token: |
| 33 |
continue |
| 34 |
|
| 35 |
print(f'{path}:{linenumber}') |
| 36 |
return False |
| 37 |
|
| 38 |
if 'Whitespace' in token and value != '': |
| 39 |
print(f'{path}:{linenumber} - ' |
| 40 |
'Incorrectly marked as whitespace') |
| 41 |
return False |
| 42 |
return True |
| 43 |
|
| 44 |
|
| 45 |
def main(): |
| 46 |
parser = argparse.ArgumentParser() |
| 47 |
parser.add_argument('TEST_ROOT', |
| 48 |
help='Root directory containing the tests') |
| 49 |
args = parser.parse_args() |
| 50 |
|
| 51 |
if process_output_files(args.TEST_ROOT, check_file) > 0: |
| 52 |
return 1 |
| 53 |
return 0 |
| 54 |
|
| 55 |
|
| 56 |
if __name__ == '__main__': |
| 57 |
sys.exit(main()) |