Tasks related to generating output



The `Separator' module supplies functions to insert
separator characters into the generated output in a context dependent
fashion.
It provides the function Separator which is meant to be
embedded in PTG patterns, e.g.
loop: "while" [Separator] $1 [Separator] $2 [Separator]
The insertions of Separator mark the positions in the
generated output texts, where separator characters might be placed.
The decision whether a separator is needed must be made by
the user-supplied function Sep_Print :
Sep_Print(PtgFilePtr file, char *last, char *next)
/* On entry-
* file points to the output file
* last points to the last string printed
* next points to the string about to be printed
* On exit-
* An appropriate separator has been added to the output file
***/@end example
Based on the textual context
Sep_Print should decide whether a separator character is required
and, if so, must insert an appropriate separator into the
output stream.
The `Separator' module provides the following output functions
which must be used instead of the corresponding PTG functions
(see Output Functions of PTG: Pattern-based Text Generator):
PTGNode Sep_Out(PTGNode root);
PTGNode Sep_OutFile(char *filename, PTGNode root);
PTGNode Sep_OutFPtr(FILE *fptr, PTGNode root);
The `Separator' module is used in conjunction with the Unparser Generator
`Idem' (see Abstract Syntax Tree Unparsing of Abstract Syntax Tree Unparsing)
to simplify
pretty-printing of the output. Idem inserts calls to Separator after
every literal and terminal symbol in the templates corresponding to the
grammar rules.
Usage
To include this module into your
specification simply add the following line to one of
your `.specs'-files:
$/Output/Separator.fw
An example of a Sep_Print function that works well with
a C-like language is provided as `C_Separator.fw':
a newline is added after any of ; { },
no separator is added after any of ( [ . ++
--,
no separator is added before any of [ ] , . ;
++ --,
and a single space added in all other cases.
`C_Separator.fw' can be included in your specifications by putting
$/Output/C_Separator.fw
into a `.specs'-file.
`C_Separator.fw' is also useful as an example how to
develop your own Sep_Print functions
if none of the available modules is satisfactory.
The simplest approach is to modify `C_Separator.fw'.
Here is a sequence of Eli requests that will extract
`C_Separator.fw' as file `My_Separator.fw',
make `My_Separator.fw'
writable, and initiate an editor session on it:
-> $elipkg/Output/C_Separator.fw > My_Separator.fw
-> My_Separator.fw !chmod +w
-> My_Separator.fw <
In order to change the decision about what (if any) separator is to
be inserted in a given context, you need to change
`Sep_Print' function, as described above.
Restrictions
Since the `Separator' module uses its own PTG output functions
Sep_Out
Sep_OutFile
Sep_OutFPtr
as explained above, it cannot be combined with specifications that influence PTG
output by redefining the PTG output macros
(see Influencing PTG Output of PTG: Pattern-based Text Generation).
The memory for storing the last string printed for the `Sep_Print'
function is restricted to 1024 characters. If the last string printed
exceeds 1024 characters, only its last 1024 characters are stored and
passed to `Sep_Print'.



|