36 Embelish Domain Exports with Short Descriptions

This Perl script takes a type name as a parameter and expects lines at standard input. The input file is supposed to be an Aldor source file that lists only the exports of the specific type together with their corresponding documentation as +++ pre-description. For further details see the calling sequence starting with the target generateexports.

This script extracts from the ++ description the addescription environment. If the corresponding Aldor code matches the form

FUNC:SIGNATURE;

the script translates such a line into

\item \adname[TYPE]{FUNC:SIGNATURE}\verb;: SIGNATURE;

followed by the above mentioned addescription environment. However, instead of the environment delimiters

\begin{addescription} ... \end{addescription}

it outputs

\begin{adshortdescription} ... \end{adshortdescription}

and thus takes care of the fact that in the exports list there should only appear the short description and the full description should be forgotten. The definition of the environment adshortdescription simply forgets the main contents and only outputs the short description.

Convention 24 In order to recognize exports lines, we require one semicolon at the end of the line.
ToDo 23 We cannot yet properly handle conditional exports in the exports list.

At the moment a form like

<<exports: TYPE>>=  
if SomeDomain has SomeCategory then {  
  <<exports: TYPE condition 1>>  
}  
@  
\begin{+++}  
...  
\end{+++}  
<<exports: TYPE condition 1>>=  
func1: Signature1;  
@  
\begin{+++}  
...  
\end{+++}  
<<exports: TYPE condition 1>>=  
func2: Signature2;  
@

works reasonably well, though.

495* 21+   486  499
#------------------------------------------------------------------
#---
#--- ALLPROSE
#--- Copyright (C) Ralf Hemmecke (ralf@hemmecke.de)
#--- http://www.hemmecke.de/aldor
#---
#------------------------------------------------------------------

$type=shift;
$inaddescription=0;
$doc = ’’;
@AldorDescription=();
while (<>) {
    chomp;
    treat +++ lines, store relevant information in @AldorDescription 496
    treat the actual exports code lines 497a
}

Defines:
AldorDescription, never used.

As can be seen from above, the input file is treated line by line. We associate a list of lines starting with +++ to the following line not starting by +++. Thus in the following code chunk we just store those line into the Perl variable AldorDescription. In fact, we do not store all the +++ lines but only those that correspond to an addescription environment, because we actually only need the short description for the documentation of the code lines.

496treat +++ lines, store relevant information in @AldorDescription 496  (495)
if (/^\s*\+\+\+ (.*)/) {
    $doc = $1;
    if ($doc =~ /^\s*\\begin{addescription}/) {
        $doc =~ s/^(\s*\\begin{ad)(description})/${1}short$2/;
        @AldorDescription = ($doc);
        $inaddescription=1;
    } elsif ($doc =~ /^\s*\\end{addescription}/) {
        $doc =~ s/^(\s*\\end{ad)(description})/${1}short$2/;
        push @AldorDescription, $doc;
        $inaddescription=0;
    } elsif ($inaddescription) {
        push @AldorDescription, $doc;
    }
    next;
}

Uses addescription 260.

Since we have treated the +++ lines with the code chunk above, it only remains to check for appropriate patterns in the remaining lines.

At the moment there are three types of lines corresponding to the if statements in the following code chunk:

  1. lines that match "FUNC: SIGNATURE;",
  2. lines that match "CATEGORYNAME;", and
  3. lines that do not match one of the above.

In the first and second case the lines are tagged with adname and adtype when outputting them.

497atreat the actual exports code lines 497a  (495)
print ’\item ’;
if (/^\s*(\S*?)\s*:\s*(.*);\s*$/) {
    $name=$1;
    $signature=$2;
    print "\\adname[$type]{$name:$signature}\\verb;: $signature;";
    print "\\qquad\n";

    if (scalar(@AldorDescription)>0) {
        for $doc (@AldorDescription) {print "$doc\n";}
        @AldorDescription = ();
    }
} elsif (/^\s*(constructor name regular expression 313)([^;]*);\s*$/) {
    print "\\adcode;\\adtype{$1}$2;;\n";
} else {
    s/;/;\\adcode|;|\\adcode;/g;
    print "\\adcode;$_;\n";
}

Note that we work here with the same regular expression as in Section 26.4.

497bconstructor name regular expression 313+   (304 314 497a 510)  313  509
[A-Z][a-zA-Z0-9]*[a-z][a-zA-Z0-9]*