]> hydra-www.ietfng.org Git - grade/commitdiff
"Unskip" comments in make-skeleton
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Mon, 16 Feb 2015 07:20:28 +0000 (02:20 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Wed, 18 Feb 2015 00:53:42 +0000 (19:53 -0500)
README.rst
make-skeleton.pl

index 9f875355cfceefabe4787753c989e74817af2a83..d165aff28fd077d401e62268b85397eef70035d0 100644 (file)
@@ -187,7 +187,17 @@ introduce many flags, a simple "see the note below" in the prose has
 sufficed.  Of course, this is up to judgement and taste.
 
 Lines that begin with ``#`` and not ``#!`` will be copied into the skeleton.
-Lines beginning with ``#!`` will be ignored entirely.
+Lines beginning with ``#!`` will be ignored entirely, except for some
+additional advanced handling:
+
+* ``#!\n`` (yes, a literal backslash) will cause an empty line to be emitted
+  into the skeleton if the containing section is not being skipped.
+
+* ``#!noskip`` will cause subsequent comment lines in a skipped section to
+  to be emitted.  In a non-skipped section, it has no effect.
+
+* ``#!reskip`` will cause subsequent comment lines to be skipped if the
+  containing section is skipped.  It has no effect otherwise.
 
 Continuing the example above, the corresponding ``defines.conf`` contains,
 among other defines ::
index ecacca35b133c3ba2ae75ac9d69da6cb4bdc3689..1a0124736d391b358d5dcefc2ec94d2f8adb9212 100755 (executable)
@@ -7,8 +7,10 @@
 use strict;
 use warnings;
 
+my $sawsec = 0;
 my $section = undef;
 my $skipsec = 0;
+my $skipcom = 0;
 
 sub comments() {
   print "\n\$BEGIN_COMMENTS\n\n\$END_COMMENTS\n\n";
@@ -19,24 +21,35 @@ while(my $line = <STDIN>) {
 
   # @section directive?
   if ($line =~ /^@(\S+)\s+(\S+)\s+/) {
+    $sawsec = 1;
     comments() if defined $section and not $skipsec;
-    $section = $1;
-    $skipsec = 0;
-    if ($2 =~ /^!/) { $skipsec = 1; next; }
-    print "\@$section\n";
+    if ($2 =~ /^!/) {
+      $skipsec = 1;
+      $skipcom = 1;
+      $section = undef;
+      next;
+    } else {
+      $skipsec = 0;
+      $skipcom = 0;
+      $section = $1;
+      print "\@$section\n";
+    }
   }
 
   # :define directive?
   elsif ($line =~ /^(:\S+)\s+/) {
-    die "Directive not within section" if not defined $section;
+    die "Directive not within section" if not defined $section and not $skipsec;
     print "#$1\n" if not $skipsec;
     while (my $cline = <STDIN>) { chomp $cline; last if $cline eq "."; }
   }
 
   # "#..." and not "#!..." get passed to template
   elsif ($line =~ /^\s*#/) {
+    if ($line =~ /^\s*#!\\n$/) { print "\n" if not $skipcom; }
+    if ($line =~ /^\s*#!noskip$/) { $skipcom = 0; }
+    if ($line =~ /^\s*#!reskip$/) { $skipcom = $skipsec; }
     if ($line !~ /^\s*#!/) {
-      print "$line\n" if not $skipsec;
+      print "$line\n" if not $skipcom;
     }
   }
 
@@ -45,5 +58,5 @@ while(my $line = <STDIN>) {
   else { die "Unknown line in definition file ($line)"; }
 }
 
-die "No sections encountered" if not defined $section;
+die "No sections encountered" if not $sawsec;
 comments() if not $skipsec;