Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 91213ddcfbe7f54821d42c2d9e091326 > files > 53

gap-system-packages-4.4.12-5mdv2010.0.i586.rpm

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (GAPDoc) - Chapter 4: Distributing a Document into Several Files</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
</head>
<body>


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chapA.html">A</a>  <a href="chapB.html">B</a>  <a href="chapC.html">C</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">Top of Book</a>&nbsp;  &nbsp;<a href="chap3.html">Previous Chapter</a>&nbsp;  &nbsp;<a href="chap5.html">Next Chapter</a>&nbsp;  </div>

<p><a id="X7A3355C07F57C280" name="X7A3355C07F57C280"></a></p>
<div class="ChapSects"><a href="chap4.html#X7A3355C07F57C280">4 <span class="Heading">Distributing a Document into Several Files</span></a>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap4.html#X7CE078A07E8256DC">4.1 <span class="Heading">The Conventions</span></a>
</div>
<div class="ContSect"><span class="nocss">&nbsp;</span><a href="chap4.html#X81E07B0F83EBDA5F">4.2 <span class="Heading">A Tool for Collecting a Document</span></a>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X857D77557D12559D">4.2-1 ComposedDocument</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap4.html#X86D1141E7EDCAAC8">4.2-2 OriginalPositionDocument</a></span>
</div>
</div>

<h3>4 <span class="Heading">Distributing a Document into Several Files</span></h3>

<p>In <strong class="pkg">GAPDoc</strong> there are facilities to distribute a single document over several files. This is for example interesting, if one wants to store the documentation of some code in the same file as the code itself. Or, if one just wants to store chapters of a document in separate files. There is a set of conventions how this is done and some tools to collect the text for further processing.</p>

<p>The technique can also be used to distribute and collect other types of documents into respectively from several files (e.g., source code, examples).</p>

<p><a id="X7CE078A07E8256DC" name="X7CE078A07E8256DC"></a></p>

<h4>4.1 <span class="Heading">The Conventions</span></h4>

<p>In this description we use the string <code class="code">GAPDoc</code> for marking pieces of a document to collect.</p>

<p>Pieces of documentation that shall be incorporated into another document are marked as follows:</p>


<table class="example">
<tr><td><pre>
##  &lt;#GAPDoc Label="MyPiece"&gt;
##  &lt;E&gt;This&lt;/E&gt; is the piece.
##  The hash characters are removed.
##  &lt;#/GAPDoc&gt;
</pre></td></tr></table>

<p>This piece is then included into another file by a statement like: <code class="code">&lt;#Include Label="MyPiece"&gt;</code> Here are the exact rules, how pieces are gathered:</p>


<ul>
<li><p>All lines up to a line containing the character sequence "<code class="code">&lt;#GAPDoc Label="</code>" (exactly one space character) are ignored. The characters on the same line before this sequence are stored as "prefix". The characters after the sequence up to the next double quotes character are stored as "label". All other characters in the line are ignored.</p>

</li>
<li><p>The following lines up to a line containing the character sequence "<code class="code">&lt;#/GAPDoc&gt;</code>" are stored under the label. These lines are processed as follows: The longest possible substring from the beginning of the line that equals the corresponding substring of the prefix is removed.</p>

</li>
</ul>
<p>Having stored a list of labels and pieces of text gathered as above this can be used as follows.</p>


<ul>
<li><p>In <strong class="pkg">GAPDoc</strong> documentation files all statements of the form "<code class="code">&lt;#Include Label="Key"&gt;</code>" are replaced by the sequence of lines stored under the label <code class="code">Key</code>.</p>

</li>
<li><p>Additionally, every occurrence of a statement of the form "<code class="code">&lt;#Include SYSTEM "Filename"&gt;</code>" is replaced by the whole file stored under the name <code class="code">Filename</code> in the file system.</p>

</li>
<li><p>These substitutions are done recursively (although one should probably avoid to use this extensively).</p>

</li>
</ul>
<p>Here is another example:</p>


<table class="example">
<tr><td><pre>
# # &lt;#GAPDoc Label="AnotherPiece"&gt;  some characters
# # This text is not indented.
#  This text is indented by one blank.
#Not indented.
#&lt;#/GAPDoc&gt;
</pre></td></tr></table>

<p>replaces <code class="code">&lt;#Include Label="AnotherPiece"&gt;</code> by</p>


<table class="example">
<tr><td><pre>
This text is not indented.
 This text is indented by one blank. 
Not indented.
</pre></td></tr></table>

<p>Since these rules are very simple it is quite easy to write a program in almost any programming language which does this gathering of text pieces and the substitutions. In <strong class="pkg">GAPDoc</strong> there is the <strong class="pkg">GAP</strong> function <code class="func">ComposedDocument</code> (<a href="chap4.html#X857D77557D12559D"><b>4.2-1</b></a>) which does this.</p>

<p>Note that the XML-tag-like markup we have used here is not a legal XML markup, since the hash character is not allowed in element names. The mechanism described here is a preprocessing step which composes a document.</p>

<p><a id="X81E07B0F83EBDA5F" name="X81E07B0F83EBDA5F"></a></p>

<h4>4.2 <span class="Heading">A Tool for Collecting a Document</span></h4>

<p><a id="X857D77557D12559D" name="X857D77557D12559D"></a></p>

<h5>4.2-1 ComposedDocument</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ComposedDocument</code>( <var class="Arg">tagname, path, main, source[, info]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; ComposedXMLString</code>( <var class="Arg">path, main, source[, info]</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>a document as string, or a list with this string and information about the source positions</p>

<p>The argument <var class="Arg">tagname</var> is the string used for the pseudo elements which mark the pieces of a document to collect. (In <a href="chap4.html#X7CE078A07E8256DC"><b>4.1</b></a> we used <code class="code">GAPDoc</code> as <var class="Arg">tagname</var>. The second function <code class="func">ComposedXMLString</code><code class="code">( ... )</code> is an abbreviation for <code class="func">ComposedDocument</code><code class="code">("GAPDoc", ... )</code>.</p>

<p>The argument <var class="Arg">path</var> must be a path to some directory (as string or directory object), <var class="Arg">main</var> the name of a file in this directory and <var class="Arg">source</var> a list of file names, all of these relative to <var class="Arg">path</var>. The document is constructed via the mechanism described in Section <a href="chap4.html#X7CE078A07E8256DC"><b>4.1</b></a>.</p>

<p>First the files given in <var class="Arg">source</var> are scanned for chunks of the document marked by <code class="code">&lt;#<var class="Arg">tagname</var> Label="..."&gt;</code> and <code class="code">&lt;/#<var class="Arg">tagname</var>&gt;</code> pairs. Then the file <var class="Arg">main</var> is read and all <code class="code">&lt;#Include ... &gt;</code>-tags are substituted recursively by other files or chunks of documentation found in the first step, respectively. If the optional argument <var class="Arg">info</var> is given and set to <code class="keyw">true</code> this function returns a list <code class="code">[str, origin]</code>, where <code class="code">str</code> is a string containing the composed document and <code class="code">origin</code> is a sorted list of entries of the form <code class="code">[pos, filename, line]</code>. Here <code class="code">pos</code> runs through all character positions of starting lines or text pieces from different files in <code class="code">str</code>. The <code class="code">filename</code> and <code class="code">line</code> describe the origin of this part of the collected document. Without the fourth argument only the string <code class="code">str</code> is returned.</p>


<table class="example">
<tr><td><pre>
gap&gt; doc := ComposedDocument("GAPDoc", "/my/dir", "manual.xml", 
&gt; ["../lib/func.gd", "../lib/func.gi"], true);;
</pre></td></tr></table>

<p><a id="X86D1141E7EDCAAC8" name="X86D1141E7EDCAAC8"></a></p>

<h5>4.2-2 OriginalPositionDocument</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&gt; OriginalPositionDocument</code>( <var class="Arg">srcinfo, pos</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><b>Returns: </b>A pair <code class="code">[filename, linenumber]</code>.</p>

<p>Here <var class="Arg">srcinfo</var> must be a data structure as returned as second entry by <code class="func">ComposedDocument</code> (<a href="chap4.html#X857D77557D12559D"><b>4.2-1</b></a>) called with <var class="Arg">info</var>=<code class="keyw">true</code>. It returns for a given position <var class="Arg">pos</var> in the composed document the file name and line number from which that text was collected.</p>


<div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">Top of Book</a>&nbsp;  &nbsp;<a href="chap3.html">Previous Chapter</a>&nbsp;  &nbsp;<a href="chap5.html">Next Chapter</a>&nbsp;  </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chapA.html">A</a>  <a href="chapB.html">B</a>  <a href="chapC.html">C</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>