From 71af45bfe199f1d17ad1daeea6917970f985d874 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 16 Feb 2015 01:00:21 -0500 Subject: [PATCH] Add !... section types to omit from skeleton --- README.rst | 4 +++- grade.pl | 1 + make-skeleton.pl | 13 ++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) mode change 100644 => 100755 grade.pl diff --git a/README.rst b/README.rst index 5c1f346..9f87535 100644 --- a/README.rst +++ b/README.rst @@ -143,7 +143,9 @@ where not contain whitespace. * ``type`` indicates to the ``grade.pl`` script how to interpret this - section. + section. If ``type`` begins with ``!``, the section will be omitted + from the generated skeleton and this initial ``!`` will be stripped + from the type before consulting the following choices. * Type ``0`` defines a section of define flags whose invoked scores are simply summed. ``extra`` is ignored for this type. This is the only diff --git a/grade.pl b/grade.pl old mode 100644 new mode 100755 index c5c92d1..45551ec --- a/grade.pl +++ b/grade.pl @@ -67,6 +67,7 @@ sub findDefinesSection($) { # {{{ my $secargs = $1; if ($secargs =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(.*)$/) { ($secty, $secmax, $secextra, $secname) = ($1,$2,$3,$4); + $secty =~ s/^!//; # strip no-skeleton directive } else { die "Malformed section line"; } return; } diff --git a/make-skeleton.pl b/make-skeleton.pl index 9226b8b..ecacca3 100755 --- a/make-skeleton.pl +++ b/make-skeleton.pl @@ -8,6 +8,7 @@ use strict; use warnings; my $section = undef; +my $skipsec = 0; sub comments() { print "\n\$BEGIN_COMMENTS\n\n\$END_COMMENTS\n\n"; @@ -17,23 +18,25 @@ while(my $line = ) { chomp $line; # @section directive? - if ($line =~ /^@(\S+)\s/) { - comments() if defined $section; + if ($line =~ /^@(\S+)\s+(\S+)\s+/) { + comments() if defined $section and not $skipsec; $section = $1; + $skipsec = 0; + if ($2 =~ /^!/) { $skipsec = 1; next; } print "\@$section\n"; } # :define directive? elsif ($line =~ /^(:\S+)\s+/) { die "Directive not within section" if not defined $section; - print "#$1\n"; + 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*#!/) { - print "$line\n"; + print "$line\n" if not $skipsec; } } @@ -43,4 +46,4 @@ while(my $line = ) { } die "No sections encountered" if not defined $section; -comments(); +comments() if not $skipsec; -- 2.50.1