##################################################################### # This scripts process Literate Haskell Script itself to be process # by lhs2TeX with haddock comments. # use strict; use warnings; my @tag=(); while (<>) { if ($_ =~ /\\begin{(.*)}/) {push @tag => $1;} if ( elem("code",@tag) and /(.*)--(.*)/) { print $1 => '--' => # "\\begin{verbatim}" => $2 => "\\end{verbatim}" => "\n"; process($2) => "\n"; } elsif (elem("nocode",@tag)) {;} else { print; } if ($_ =~ /\\end{(.*)}/ and $1 eq $tag[@tag-1]) {pop @tag;} } ##################################################################### ####################################### sub process{ my ($input) = @_; $input =~ s/\\/\$\\backslash\$/g; $input =~ s/\|/\|\|/g; $input =~ s/\@/\@\@/g; $input =~ s/\^//g; $input =~ s/\"/\'/g; $input =~ s/_/\\_/g; return $input; } ####################################### sub elem { my ($x,@xs) = @_; my $res = 0; for (@xs) {$res=1 if $x eq $_} return $res; }