mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 11:19:32 -06:00
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
This commit is contained in:
169
src-3.0/haddock/haddock-check.perl
Normal file
169
src-3.0/haddock/haddock-check.perl
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
73
src-3.0/haddock/haddock-script.csh
Normal file
73
src-3.0/haddock/haddock-script.csh
Normal file
@@ -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
|
||||
|
||||
|
||||
10
src-3.0/haddock/resources/blank.html
Normal file
10
src-3.0/haddock/resources/blank.html
Normal file
@@ -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>
|
||||
14
src-3.0/haddock/resources/index.html
Normal file
14
src-3.0/haddock/resources/index.html
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user