chiark / gitweb /
Dollar doubling feature
[secnet.git] / tests / filter / extract-doctest
index b7da9ac72d3701d1b429b3346a90b95a72613c00..b63f309e87f5875465399c15d2fd560298299a69 100755 (executable)
@@ -41,8 +41,8 @@ while (<>) {
     # parse: rely on looking for => (and .. on subsequent lines)
     next unless m{\=\>} or ($cent and m{ \.\. });
     my $mapop = '=>';
-    # adhoc: special case STUFF here so we recognise things in changequote
-    if (s{^(\s*)(\&\S+|STUFF\S+|\$)\s+(\=\>|\.\.)\s+(\S+)\s+}{} ||
+    # adhoc: special case NEWQUOTE here so we recognise things in changequote
+    if (s{^(\s*)(\&\S+|NEWQUOTE\S+|\$)\s+(\=\>|\.\.)\s+(\S+)\s+}{} ||
        s{^()(\&\:\w+(?: \S+)*)\s{2,}(\=\>)\s{2,}($withspcs)$}{} ||
         $cent && s{^()($withspcs)\s{2,}(\.\.)\s{2,}($withspcs)$}{}) {
        # adhoc: expected indented iff in changequote part
@@ -56,8 +56,13 @@ while (<>) {
            $e->{OutTop} = $1 eq 'nothing' ? '' : $1;
        } elsif (# parse: expect other wordish things to be comments
                 m{^(?!or\b)\w{2,} }) {
+       } elsif (m/^$/) {
+       } else {
+           confess "unk rhs $_ ?";
        }
        $e->{CQ} = $in_changequote;
+       # adhoc: rely on this specific section title
+       $e->{DD} = $csection =~ m{^while dollar[- ]doubling}i;
     } else {
        confess "$_ ?";
     }
@@ -104,6 +109,7 @@ sub write_permode ($$$$$;$$) {
        my $rubric = $e->{In};
        $rubric =~ s/\&/AMP /g;
        $rubric =~ s/\$/DOLLAR /g;
+       $rubric =~ s/NEWQUOTE/NEW_QUOTE /g;
        my $f = $e->{In} =~ m/\n/
                ? "\n# %s:\n%s\n\n"
                : "%-30s: %s.\n";
@@ -126,11 +132,30 @@ sub writeout ($) {
     oh "# doctest starts $dir_prefix\n";
     write_permode($dir_prefix,
                  '','','', 'normal',
-                sub { !$_[0]{CQ} } );
+                sub { !$_[0]{DD} && !$_[0]{CQ} } );
+    write_permode($dir_prefix,
+                 '&$+', '&$-', "\n",
+                 'dollar doubling',
+                 sub {
+                     my ($e) = @_;
+                     return 0 if $e->{CQ};
+                     return $e->{DD} || !grep {
+                         # If there are two entries with the same In,
+                         # use only the one from the `while dollar
+                         # doubling' section.  So entries there override
+                         # entries in the rest o the file.
+                         $_ ne $e && $_->{In} eq $e->{In}
+                     } @exp;
+                 },
+                 sub {
+                     $_=$_[0];
+                     s/\$/\$\$/g unless $_[1]{DD};
+                     $_;
+                 } );
     write_permode($dir_prefix,
-                 "&:changequote STUFF",
-                 "STUFF:changequote &",
-                 "\n",
+                 "&:changequote NEWQUOTE\n",
+                 "NEWQUOTE:changequote &\n",
+                 "",
                  'changequote',
                  sub { $_[0]{CQ} } );
     oh "# doctest ends\n";