diff options
| author | aarne <aarne@cs.chalmers.se> | 2008-05-21 09:26:44 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2008-05-21 09:26:44 +0000 |
| commit | 055c0d0d5a5bb0dc75904fe53df7f2e4f5732a8f (patch) | |
| tree | 0e63fb68c69c8f6ad0f78893c63420f0a3600e1c /src-3.0/haddock | |
| parent | 915a1de71783ab8446b1af9e72c7ba7dfbc12d3f (diff) | |
GF/src is now for 2.9, and the new sources are in src-3.0 - keep it this way until the release of GF 3
Diffstat (limited to 'src-3.0/haddock')
| -rw-r--r-- | src-3.0/haddock/haddock-check.perl | 169 | ||||
| -rw-r--r-- | src-3.0/haddock/haddock-script.csh | 73 | ||||
| -rw-r--r-- | src-3.0/haddock/resources/blank.html | 10 | ||||
| -rw-r--r-- | src-3.0/haddock/resources/index.html | 14 |
4 files changed, 266 insertions, 0 deletions
diff --git a/src-3.0/haddock/haddock-check.perl b/src-3.0/haddock/haddock-check.perl new file mode 100644 index 000000000..93647bac7 --- /dev/null +++ b/src-3.0/haddock/haddock-check.perl @@ -0,0 +1,169 @@ + +# checking that a file is haddocky: +# - checking if it has an export list +# - if there is no export list, it tries to find all defined functions +# - checking that all exported functions have type signatures +# - checking that the module header is OK + +# changes on files: +# - transforming hard space to ordinary space + +# limitations: +# - there might be some problems with nested comments +# - cannot handle type signatures for several functions +# (i.e. "a, b, c :: t") +# but on the other hand -- haddock has some problems with these too... + +$operChar = qr/[\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~]/; +$operCharColon = qr/[\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~\:]/; +$nonOperChar = qr/[^\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~]/; +$nonOperCharColon = qr/[^\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~\:]/; + +$operSym = qr/$operChar $operCharColon*/x; +$funSym = qr/[a-z] \w* \'*/x; +$funOrOper = qr/(?: $funSym | \($operSym\) )/x; + +$keyword = qr/(?: type | data | module | newtype | infix[lr]? | import | instance | class )/x; +$keyOper = qr/^(?: \.\. | \:\:? | \= | \\ | \| | \<\- | \-\> | \@ | \~ | \=\> | \. )$/x; + +sub check_headerline { + my ($title, $regexp) = @_; + if (s/^-- \s $title \s* : \s+ (.+?) \s*\n//sx) { + $name = $1; + push @ERR, "Incorrect ".lcfirst $title.": $name" + unless $name =~ $regexp; + return $&; + } else { + push @ERR, "Header missing: ".lcfirst $title.""; + } +} + +if ($#ARGV >= 0) { + @FILES = @ARGV; +} else { +# @dirs = qw{. api canonical cf cfgm compile for-ghc-nofud +# grammar infra notrace parsers shell +# source speech translate useGrammar util visualization +# GF GF/* GF/*/* GF/*/*/*}; + @dirs = qw{GF GF/* GF/*/* GF/*/*/*}; + @FILES = grep(!/\/(Par|Lex)(GF|GFC|CFG)\.hs$/, + glob "{".join(",",@dirs)."}/*.hs"); +} + +for $file (@FILES) { + $file =~ s/\.hs//; + + open F, "<$file.hs"; + $_ = join "", <F>; + close F; + + @ERR = (); + + # substituting hard spaces for ordinary spaces + $nchars = tr/\240/ /; + if ($nchars > 0) { + push @ERR, "!! > Substituted $nchars hard spaces"; + open F, ">$file.hs"; + print F $_; + close F; + } + + # the module header + $hdr_module = $module = ""; + + s/^ \{-\# \s+ OPTIONS \s+ -cpp \s+ \#-\} //sx; # removing ghc options (cpp) + s/^ \s+ //sx; # removing initial whitespace + s/^ (--+ \s* \n) +//sx; # removing initial comment lines + unless (s/^ -- \s \| \s* \n//sx) { + push @ERR, "Incorrect module header"; + } else { + $hdr_module = s/^-- \s Module \s* : \s+ (.+?) \s*\n//sx ? $1 : ""; + &check_headerline("Maintainer", qr/^ [\wåäöÅÄÖüÜ\s\@\.]+ $/x); + &check_headerline("Stability", qr/.*/); + &check_headerline("Portability", qr/.*/); + s/^ (--+ \s* \n) +//sx; + push @ERR, "Missing CVS information" + unless s/^(-- \s+ \> \s+ CVS \s+ \$ .*? \$ \s* \n)+//sx; + s/^ (--+ \s* \n) +//sx; + push @ERR, "Missing module description" + unless /^ -- \s+ [^\(]/x; + } + + # removing comments + s/\{- .*? -\}//gsx; + s/-- ($nonOperSymColon .*? \n | \n)/\n/gx; + + # removing \n in front of whitespace (for simplification) + s/\n+[ \t]/ /gs; + + # the export list + $exportlist = ""; + + if (/\n module \s+ ((?: \w | \.)+) \s+ \( (.*?) \) \s+ where/sx) { + ($module, $exportlist) = ($1, $2); + + $exportlist =~ s/\b module \s+ [A-Z] \w*//gsx; + $exportlist =~ s/\(\.\.\)//g; + + } elsif (/\n module \s+ ((?: \w | \.)+) \s+ where/sx) { + $module = $1; + + # modules without export lists + # push @ERR, "No export list"; + + # function definitions + while (/^ (.*? $nonOperCharColon) = (?! $operCharColon)/gmx) { + $defn = $1; + next if $defn =~ /^ $keyword \b/x; + + if ($defn =~ /\` ($funSym) \`/x) { + $fn = $1; + } elsif ($defn =~ /(?<! $operCharColon) ($operSym)/x + && $1 !~ $keyOper) { + $fn = "($1)"; + } elsif ($defn =~ /^($funSym)/x) { + $fn = $1; + } else { + push @ERR, "!! > Error in function defintion: $defn"; + next; + } + + $exportlist .= " $fn "; + } + } else { + push @ERR, "No module header found"; + } + + push @ERR, "Module names not matching: $module != $hdr_module" + if $hdr_module && $module !~ /\Q$hdr_module\E$/; + + # fixing exportlist (double spaces as separator) + $exportlist = " $exportlist "; + $exportlist =~ s/(\s | \,)+/ /gx; + + # removing functions with type signatures from export list + while (/^ ($funOrOper (\s* , \s* $funOrOper)*) \s* ::/gmx) { + $functionlist = $1; + while ($functionlist =~ s/^ ($funOrOper) (\s* , \s*)?//x) { + $function = $1; + $exportlist =~ s/\s \Q$function\E \s/ /gx; + } + } + + # reporting exported functions without type signatures + $reported = 0; + $untyped = ""; + while ($exportlist =~ /\s ($funOrOper) \s/x) { + $function = $1; + $exportlist =~ s/\s \Q$function\E \s/ /gx; + $reported++; + $untyped .= " $function"; + } + push @ERR, "No type signature for $reported function(s):\n " . $untyped + if $reported; + + print "-- $file\n > " . join("\n > ", @ERR) . "\n" + if @ERR; +} + + diff --git a/src-3.0/haddock/haddock-script.csh b/src-3.0/haddock/haddock-script.csh new file mode 100644 index 000000000..77b3761f8 --- /dev/null +++ b/src-3.0/haddock/haddock-script.csh @@ -0,0 +1,73 @@ +#!/bin/tcsh + +###################################################################### +# Author: Peter Ljunglöf +# Time-stamp: "2005-05-12, 23:17" +# CVS $Date: 2005/05/13 12:40:20 $ +# CVS $Author: peb $ +# +# a script for producing documentation through Haddock +###################################################################### + +set basedir = `pwd` +set docdir = haddock/html +set tempdir = haddock/.temp-files +set resourcedir = haddock/resources + +set files = (`find GF -name '*.hs'` GF.hs) + +###################################################################### + +echo 1. Creating and cleaning Haddock directory +echo -- $docdir + +mkdir -p $docdir +rm -rf $docdir/* + +###################################################################### + +echo +echo 2. Copying Haskell files to temporary directory: $tempdir + +rm -rf $tempdir + +foreach f ($files) + # echo -- $f + mkdir -p `dirname $tempdir/$f` + perl -pe 's/^#/-- CPP #/' $f > $tempdir/$f +end + +###################################################################### + +echo +echo 3. Invoking Haddock + +cd $tempdir +haddock -o $basedir/$docdir -h -t 'Grammatical Framework' $files +cd $basedir + +###################################################################### + +echo +echo 4. Restructuring to HTML framesets + +echo -- Substituting for frame targets inside html files +mv $docdir/index.html $docdir/index-frame.html +foreach f ($docdir/*.html) + # echo -- $f + perl -pe 's/<HEAD/<HEAD><BASE TARGET="contents"/; s/"index.html"/"index-frame.html"/; s/(<A HREF = "\S*index\S*.html")/$1 TARGET="index"/' $f > .tempfile + mv .tempfile $f +end + +echo -- Copying resource files: +echo -- `ls $resourcedir/*.*` +cp $resourcedir/*.* $docdir + +###################################################################### + +echo +echo 5. Finished +echo -- The documentation is located at: +echo -- $docdir/index.html + + diff --git a/src-3.0/haddock/resources/blank.html b/src-3.0/haddock/resources/blank.html new file mode 100644 index 000000000..63ab0b172 --- /dev/null +++ b/src-3.0/haddock/resources/blank.html @@ -0,0 +1,10 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+
+<!-- Time-stamp: "2005-02-03, 15:59" -->
+<HTML>
+<HEAD>
+<LINK HREF="haddock.css" REL=stylesheet>
+</HEAD>
+<BODY>
+</BODY>
+</HTML>
diff --git a/src-3.0/haddock/resources/index.html b/src-3.0/haddock/resources/index.html new file mode 100644 index 000000000..5d8822dc5 --- /dev/null +++ b/src-3.0/haddock/resources/index.html @@ -0,0 +1,14 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" + "http://www.w3.org/TR/html4/frameset.dtd"> + +<!-- Time-stamp: "2005-02-03, 15:53" --> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> +<title>Grammatical Framework programmer's documentation</title> +</head> +<frameset cols="1*,2*"> + <frame name="index" src="index-frame.html"> + <frame name="contents" src="blank.html"> +</frameset> +</html> |
