From: David Wells Date: Thu, 5 Apr 2018 15:20:12 +0000 (-0400) Subject: Add the double word typo script. X-Git-Tag: v9.0.0-rc1~232^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=996d83bd3b3272d1a91d9896a95558d2ed4220f7;p=dealii.git Add the double word typo script. --- diff --git a/contrib/utilities/double_word_typos.py b/contrib/utilities/double_word_typos.py new file mode 100644 index 0000000000..444bae2fc4 --- /dev/null +++ b/contrib/utilities/double_word_typos.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# --------------------------------------------------------------------- +# +# Copyright (C) 2018 by the deal.II authors +# +# This file is part of the deal.II library. +# +# The deal.II library is free software; you can use it, redistribute +# it, and/or modify it under the terms of the GNU Lesser General +# Public License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# The full text of the license can be found in the file LICENSE at +# the top level of the deal.II distribution. +# +# --------------------------------------------------------------------- +"""A script that locates double word typos, e.g., from tria.h: + + This way it it possible to obtain neighbors across a periodic + +This script should be run as + + python double_word_typos.py /path/to/header.h + +or, in a loop, e.g., + + for FILE in $(find ./examples/ -name "*.dox") + do + python ./contrib/utilities/double_word_typos.py $FILE + done + +and will print lines containing double words (or double lines, if the first word +of the next line matches the last word of the previous line) to the screen. + +The output format used by this script is similar to GCC's and it can be run very +conveniently from inside emacs' compilation-mode. +""" +import sys + +# Skip the following tokens since they show up frequently but are not related to +# double word typos +SKIP = ["//", "*", "}", "|", "};", ">", "\"", "|", "/", + "numbers::invalid_unsigned_int,", "std::string,", "int,"] + +with open(sys.argv[1], 'r') as handle: + previous_line = "" + for line_n, line in enumerate(handle): + line = line.strip() + previous_words = previous_line.split() + words = line.split() + # ignore comment blocks '*' and comment starts '//' at the beginning of + # each line. + if len(words) == 0: + continue + if words[0] in ["*", "//"]: + words = words[1:] + + # See if the last word on the previous line is equal to the first word + # on the current line. + if len(previous_words) != 0: + if words[0] not in SKIP and previous_words[-1] == words[0]: + print(sys.argv[1] + ":{}: {}".format(line_n + 1, previous_line)) + print(sys.argv[1] + ":{}: {}".format(line_n + 2, line)) + previous_line = line + + for left_word, right_word in zip(words[:-1], words[1:]): + if left_word == right_word and left_word not in SKIP: + print(sys.argv[1] + ":{}: {}".format(line_n + 1, line))