Discussions of the Parallel Programming book
 help / color / mirror / Atom feed
From: Akira Yokosawa <akiyks@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: perfbook@vger.kernel.org, Akira Yokosawa <akiyks@gmail.com>
Subject: [PATCH -perfbook 06/11] periodcheck: Add colon-related checks
Date: Tue, 17 Aug 2021 19:29:23 +0900	[thread overview]
Message-ID: <5ba9d541-66d4-aefa-9de5-26cb54e77cbd@gmail.com> (raw)
In-Reply-To: <9f71d7d5-b9bb-ceeb-6acb-e889821eeeb9@gmail.com>

Excerpt of Paul's message:

    > If you have some preference, I can update the scripts to enforce
    > it.

    In this case, I prefer the simple British approach to that of my
    homeland, so please unconditionally capitalize after a colon.

    (Instead of the American approach of doing so only if the word following
    the colon begins a complete sentence, which is not something I want to
    be checking manually, let alone via a script!)

This means colons should always come at the end of LaTeX source lines.
Adding ":" to the existing regex in the check scripts can catch
violations to this convention.

As colons can lead a numbered list of sentences/clauses/phrases,
a colon-specific pattern is also added in cleverefcheck.pl.

Also add a couple of filters to ignore arguments of LaTeX macros
such as \caption{}, \paragraph{}, and \co{}.
Also add a pattern to ignore arguments of \QuickQuizChapter and
\OriginalPublished as these macros can't be broken in-between.

Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
---
 utilities/cleverefcheck.pl | 25 +++++++++++++++++------
 utilities/periodcheck.pl   | 42 +++++++++++++++++++++-----------------
 2 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/utilities/cleverefcheck.pl b/utilities/cleverefcheck.pl
index 87b373f2..c59e42d1 100755
--- a/utilities/cleverefcheck.pl
+++ b/utilities/cleverefcheck.pl
@@ -36,6 +36,13 @@ sub check_line {
 	    $line =~ s/$quoted_2//;
 	}
     }
+    if ($line =~ /\\[tq]?co\{([^\}]+)\}/) {# remove \co{} argument
+	while ($line && $line =~ /((\\[tq]?co\{)[^\}]+)\}/) {
+	    my $quoted_1 = quotemeta $1;
+	    my $quoted_2 = quotemeta $2;
+	    $line =~ s/$quoted_1/$quoted_2/;
+	}
+    }
     unless ($skip) {
 	$safe = 1;
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*\\ref\{/ ||
@@ -54,9 +61,9 @@ sub check_line {
 	}
 	if ($line =~ /^\s*\\Cref/ || $line =~ /^\s*\\Cpageref/ ||
 	    $line =~ /^\s*\\Clnref/) {
-	    if ($new_sentence) {
+	    if ($new_sentence == 1) {
 		$safe = 1;
-	    } else {
+	    } elsif ($new_sentence == 0) {
 		$safe = 0;
 	    }
 	}
@@ -68,8 +75,14 @@ sub check_line {
 		$safe = 1;
 	    }
 	}
-	if ($new_sentence == 1) {
-	    if ($line =~ /^\s*[a-z]/ ) {
+	if ($new_sentence) {
+	    if ($line =~ /^\s*`*[a-z]/ || $line =~ /^\s*\\acr/ ||
+		$line =~ /^\s*\\IX[^A\{]*\{[a-z]/ ) {
+		$safe = 0;
+	    }
+	}
+	if ($new_sentence == 2) { # after colon
+	    if ($line =~ /^\s*\([0-9a-z]\)[\s~][a-z]/ ) {
 		$safe = 0;
 	    }
 	}
@@ -87,14 +100,14 @@ sub check_line {
 	unless ($line =~ /\\begin\{fcvref\}/ || $line =~ /\\end\{fcvref\}/ ||
 		$line =~ /^\s*\}\s*$/ || $line =~ /^\s*%/) {
 	    if ($line =~ /^(?=[\s]*+[^%])[^%]*[\.\?!]\s*[\)\}\']*\s*(%.*)?$/ ||
-		$line =~ /^\s*$/ ||
+		$line =~ /^\s*$/ || $line =~ /\\begin\{quote\}/ ||
 		$line =~ /^\\E?QuickQuiz[BEM]?\{/ ||
 		$line =~ /\\E?QuickQuizAnswer[BEM]?\{/ ) {
 		$new_sentence = 1;
 	    } else {
 		$new_sentence = 0;
 		if ($line =~ /^(?=[\s]*+[^%])[^%]*:\s*[\)\}\']*\s*(%.*)?$/ ) {
-		    $new_sentence = 2;  # don't care
+		    $new_sentence = 2;  # colon
 		}
 	    }
 	}
diff --git a/utilities/periodcheck.pl b/utilities/periodcheck.pl
index 6ad90dcb..f46052c5 100755
--- a/utilities/periodcheck.pl
+++ b/utilities/periodcheck.pl
@@ -27,10 +27,8 @@ my $next_line;
 my $line_num = 0;
 my $skip = 0;
 my $safe = 0;
-my $Verbatim_begin = qr/\\begin\{Verbatim/ ;
-my $Verbatim_end = qr/\\end\{Verbatim/ ;
-my $tabular_begin = qr/\\begin\{tabula/ ;
-my $tabular_end = qr/\\end\{tabula/ ;
+my $Verbatim_begin = qr/\\begin\{(Verbatim|tabula|equation)/ ;
+my $Verbatim_end = qr/\\end\{(Verbatim|tabular|equation)/ ;
 my $label_ptn = qr/(^\s*|\{)(,?[a-z]{3,4}:([a-zMPS]+:)?[^\},]+)(\}|,)/ ;
 
 sub check_line {
@@ -42,23 +40,29 @@ sub check_line {
 	    $line =~ s/$quoted_2//;
 	}
     }
-    if ($line =~ /section\{([^\}]*)\}/ ) {
-	my $quoted_1 = quotemeta $1;
-	$line =~ s/$quoted_1//;
+    if ($line =~ /\\[tq]?co\{([^\}]*)\}/ ) {
+	while ($line && $line =~ /((\\[tq]?co\{)[^\}]+)\}/) {
+	    my $quoted_1 = quotemeta $1;
+	    my $quoted_2 = quotemeta $2;
+	    $line =~ s/$quoted_1/$quoted_2/;
+	}
+    }
+    # \QuickQuizChapter and \OriginalPublished don't allow line breaks in their
+    # arguments.
+    if ($line =~ /\\QuickQuizChapter\{/ ) {
+	$line = '\\QuickQuizChapter\{\}\{\}\{\}';
     }
-    if ($line =~ /caption\{([^\}]*)\}/ ) {
-	my $quoted_1 = quotemeta $1;
-	$line =~ s/$quoted_1//;
+    if ($line =~ /\\OriginallyPublished\{/ ) {
+	$line = '\\OriginallyPublised\{\}\{\}\{\}\{\}';
     }
-    if ($line =~ /$Verbatim_begin/ ||
-	$line =~ /$tabular_begin/) {  # exception (verbatim and tabular)
+    if ($line =~ /$Verbatim_begin/ ) {  # exception (verbatim ,tabular, equation)
 	$skip = 1;
     }
     unless ($skip) {
 	$safe = 1;
-	if ($line =~ /^(?=[\s]*+[^%])[^%]*[A-Z][\.\?\!][\)\}\']*$/ ||
-	    $line =~ /^(?=[\s]*+[^%])[^%]*[A-Z][\.\?\!]\\footnote/ ||
-	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]crm?\{.+\}[\.\?\!][\)\}\']*$/ ) {
+	if ($line =~ /^(?=[\s]*+[^%])[^%]*[A-Z][\.\?\!\:][\)\}\']*$/ ||
+	    $line =~ /^(?=[\s]*+[^%])[^%]*[A-Z][\.\?\!\:]\\footnote/ ||
+	    $line =~ /^(?=[\s]*+[^%])[^%]*[Aa]crm?\{.+\}[\.\?\!\:][\)\}\']*$/ ) {
 	    $safe = 0;
 	    if ($next_line =~ /^\s*$/ || $next_line =~ /^\s*%/ ||
 		$next_line =~ /\\item/ ||
@@ -68,7 +72,8 @@ sub check_line {
 		$safe = 1;
 	    }
 	}
-	if ($line =~ /^(?=[\s]*+[^%])[^%]*[a-z\}][\.\?\!][\)\}\']*\s[^\\]+/) {
+	if ($line =~ /^(?=[\s]*+[^%])[^%]*[a-z\}][\.\?\!][\)\}\']*\s[^\\]+/ ||
+	    $line =~ /^(?=[\s]*+[^%])[^%]*.*:[\)\}\']*\s[^\\]+/) {
 	    $safe = 0;
 	}
 	if ($line =~ /^(?=[\s]*+[^%])[^%]*[^~]\\cite/) {
@@ -77,15 +82,14 @@ sub check_line {
 		$safe = 1;
 	    }
 	}
-	if ($line =~ /^(?=[\s]*+[^%])[^%]*\\\@[\.\?\!][\)\}\']*\s+[^\s%]+/){
+	if ($line =~ /^(?=[\s]*+[^%])[^%]*\\\@[\.\?\!\:][\)\}\']*\s+[^\s%]+/){
 	    $safe = 0;
 	}
 	unless ($safe) {
 	    print $ARGV[0], ':', $line_num, ':', $line_raw;
 	}
     }
-    if ($line =~ /$Verbatim_end/ ||
-	$line =~ /$tabular_end/) {
+    if ($line =~ /$Verbatim_end/ ) {
 	$skip = 0;
     }
 }
-- 
2.17.1



  parent reply	other threads:[~2021-08-17 10:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 10:14 [PATCH -perfbook 00/11] Break and capitalize after colon, take four Akira Yokosawa
2021-08-17 10:16 ` [PATCH -perfbook 01/11] appendix, glossary: Break and capitalize after colon Akira Yokosawa
2021-08-17 10:18 ` [PATCH -perfbook 02/11] glossary: Put missing question mark Akira Yokosawa
2021-08-17 10:19 ` [PATCH -perfbook 03/11] treewide: Adjust punctuation convention Akira Yokosawa
2021-08-17 10:21 ` [PATCH -perfbook 04/11] Add \ignorespaces command to \IfEbookSize and \IfSansSerif Akira Yokosawa
2021-08-17 18:29   ` Paul E. McKenney
2021-08-17 20:22     ` Paul E. McKenney
2021-08-17 23:31     ` Akira Yokosawa
2021-08-17 23:50       ` Paul E. McKenney
2021-08-17 10:23 ` [PATCH -perfbook 05/11] datastruct: Use \tco{} inside inline enumerate list Akira Yokosawa
2021-08-17 10:29 ` Akira Yokosawa [this message]
2021-08-17 10:33 ` [PATCH -perfbook 07/11] cleverefcheck: Check lower-case word after \item Akira Yokosawa
2021-08-17 10:35 ` [PATCH -perfbook 08/11] periodcheck: Improve regex Akira Yokosawa
2021-08-17 10:37 ` [PATCH -perfbook 09/11] periodcheck: Use counter to prevent false negatives Akira Yokosawa
2021-08-17 10:39 ` [PATCH -perfbook 10/11] cleverefcheck: Add pattern to catch typo in indexing macros Akira Yokosawa
2021-08-17 10:40 ` [PATCH -perfbook 11/11] Makefile: Rename periodcheck --> punctcheck Akira Yokosawa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ba9d541-66d4-aefa-9de5-26cb54e77cbd@gmail.com \
    --to=akiyks@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=perfbook@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox