As we mentioned earlier, a literate programming (LP) tool allows the user to interleave documentation and code in whatever order is most appropriate for presentation. However, the tool must be able to extract and reorder the code ``chunks'' properly for the compiler. Like other LP tools, FunnelWeb accomplishes this feat with macros and automatic cross-referencing.
Each macro may contain some code as well as references to other
macros. During the code extraction phase, FunnelWeb, starting at the
``root'' macro
, extracts any code from the macro
and expands all references to other macros. The process continues
until there are no more references to expand and all of the code is
extracted. The macros and their cross-references also appear in the
typeset documentation so the reader can see how the code chunks fit
together.
We use two types of FunnelWeb macros:
macro name¯
[definition number]
![]()
The code to be processed appears here
call to another macro
[called macro's definition number]
This macro is invoked in definition n.
The letters M and Z may follow the definition number, indicating that the macro may be called many times or zero times, respectively. The numbers of the definitions that use a macro are listed in the last line. Macros that are invoked in a macro that is not defined in this document are invoked in external files as described by Section 3 of Chapter 13.
Here is an example of a simple macro.
procI<>edure example
[5]
![]()
procT
edure example is
Constants
[4]
begin
for iT
in 1..n loop
Write out first p powers of i
[8]
end loop;
end example;
This macro is invoked in definition 7.
This macro takes two parameters and the second is added to the first. The small diamonds (add¯
[6] (
2)M
![]()
1 +
2
This macro is invoked in definitions 3, 4 and 9.
double¯
[3](
1)M
![]()
add
[6](`
1',`
1')
This macro is invoked in definitions 10 and 11.