From a9dadb108d096ed19e40dd04d9a2feb03670c7a3 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 16 Feb 2015 02:20:28 -0500 Subject: [PATCH] "Unskip" comments in make-skeleton --- README.rst | 12 +++++++++++- make-skeleton.pl | 27 ++++++++++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 9f87535..d165aff 100644 --- a/README.rst +++ b/README.rst @@ -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 :: diff --git a/make-skeleton.pl b/make-skeleton.pl index ecacca3..1a01247 100755 --- a/make-skeleton.pl +++ b/make-skeleton.pl @@ -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 = ) { # @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 = ) { 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 = ) { 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; -- 2.50.1