&& => && for convenience in shell runes
&\& => & general escaping mechanism
-&\$ => $
+&\$ => $ provided for $-doubling regimes
&\NEWLINE eats the newline and vanishes
&$VARIABLE => $(sub_dir_VARIABLE) or $(TOP_VARIABLE)
`all' is extra special: every directory has an `all'
target, which corresponds to &TARGETS.
+
+Dollar doubling and macro assistance
+------------------------------------
+
+&$+ Starts dollar-doubling
+&$- Stops dollar-doubling
+ Both are idempotent and local to the file or context.
+
+While dollar-doubling:
+- - - - - - - - - - -
+
+$ => $$ including $'s produced by other
+ &-expansions not mentioned here
+
+&\$ => $
+&$NN => $(NN) where N are digits
+&$( => $(
+
+
Subdirectory and variable naming
--------------------------------
print O @_ or die "error writing $writing_output.tmp: $!\n";
}
-sub od { # maybe $-doubled
+sub oud { # undoubled
if (defined $buffering_output) {
$buffering_output .= $_ foreach @_;
return;
oraw @_;
}
+our $ddbl;
+
+sub od { # maybe $-doubled
+ if (!$ddbl) {
+ oud @_;
+ return;
+ }
+ foreach (@_) {
+ my $e = $_;
+ $e =~ s{\$}{\$\$}g;
+ oud $e;
+ }
+}
+
sub start_output_file ($) {
close_any_output_file();
($writing_output) = @_;
);
$pfxmap{$_} = $srcdirmap{$_}.'/' foreach keys %srcdirmap;
+ local $ddbl;
+
while (<$input>) {
if (s#^\s*$esc\:changequote\s+(\S+)\s+$##) {
$$esclitr = $1;
$targets->{$t} //= [ ];
}
for (;;) {
+ die if $ddbl && defined $buffering_output;
unless (s{^(.*?)$esc}{}) { od $_; last; }
od $1;
if (s{^\\$esc}{}) { od "$$esclitr" }
- elsif (s{^\\\$}{}) { od '$' }
+ elsif (s{^\\\$}{}) { oud '$' }
elsif (s{^\\\s+$}{}) { }
elsif (s{^$esc}{}) { od "$$esclitr$$esclitr" }
elsif (m{^(?=$caps_re)}) { od $var_prefix }
elsif (s{^([~^]?)/}{}) { od $pfxmap{$1} }
elsif (s{^\.}{}) { od $dir_name }
elsif (s{^([~^])\.}{}) { od $srcdirmap{$1} }
+ elsif (s{^\$\-}{}) { $ddbl=undef; }
+ elsif (s{^\$\+}{}) { $ddbl=1; }
+ elsif (s{^\$\(}{}) { die unless $ddbl; oud "\$("; }
+ elsif (s{^\$(\d+)}{}) { die unless $ddbl; oud "\$($1)"; }
elsif (s{^([~^]?)(?=[ \t])}{}) {
my $prefix = $pfxmap{$1} // die;
my $after='';
confess "unk rhs $_ ?";
}
$e->{CQ} = $in_changequote;
+ # adhoc: rely on this specific section title
+ $e->{DD} = $csection =~ m{^while dollar[- ]doubling}i;
} else {
confess "$_ ?";
}
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 NEWQUOTE\n",
"NEWQUOTE:changequote &\n",