Eli   Documents Get Eli: Translator Construction Made Easy at SourceForge.net.
    Fast, secure and Free Open Source software downloads

General Information

 o Eli: Translator Construction Made Easy
 o Global Index
 o Frequently Asked Questions
 o Typical Eli Usage Errors

Tutorials

 o Quick Reference Card
 o Guide For new Eli Users
 o Release Notes of Eli
 o Tutorial on Name Analysis
 o Tutorial on Type Analysis
 o Typical Eli Usage Errors

Reference Manuals

 o User Interface
 o Eli products and parameters
 o LIDO Reference Manual
 o Typical Eli Usage Errors

Libraries

 o Eli library routines
 o Specification Module Library

Translation Tasks

 o Lexical analysis specification
 o Syntactic Analysis Manual
 o Computation in Trees

Tools

 o LIGA Control Language
 o Debugging Information for LIDO
 o Graphical ORder TOol

 o FunnelWeb User's Manual

 o Pattern-based Text Generator
 o Property Definition Language
 o Operator Identification Language
 o Tree Grammar Specification Language
 o Command Line Processing
 o COLA Options Reference Manual

 o Generating Unparsing Code

 o Monitoring a Processor's Execution

Administration

 o System Administration Guide

Mail Home

Tasks related to generating output

Previous Chapter Next Chapter Table of Contents


Pretty Printing

The module `PrettyPrint' supplies C functions that can be inserted in PTG patterns to handle line breaks properly. The functions try to break the current line at the last possible position that precedes the maximum line width. Furthermore, regions of text can be indented.

Functions exist to mark line breaks and the begin and end of an indentation region. These functions can be included into PTG pattern definitions.

PP_BreakLine
Specifies, that a line break can be inserted at this point. A line will only be broken at these points.

PP_Indent
PP_Exdent
PP_Indent marks the beginning of an indented region. Line feeds following this function call will not only begin a new line but also indent the next line by an indentation step, the width of indentation can be adjusted with a function discussed later. Indented regions can be nested and are terminated by a call to the PP_Exdent-pattern function.

PP_Newline
Forces a line feed thereby inserting the newline sequence. The next line will be indented properly. The newline character `"\n"' in a PTG pattern is a shortcut for a call to this output function.

Examples

The following PTG patterns can be used to yield different styles of indenting for blocks. Here { and } are the symbols that denote the beginning and end of a block, $ is the insertion point for the indented block. The first example sets those symbols in a new line at the indentation level of the outer block:

   Block:  "\n{" [PP_Indent] 
               "\n" $ [PP_Exdent] 
           "\n}"
   Stmt:   [PP_BreakLine] $ 

The next example also specifies an indented region. Here, the opening brace is set as last token outside the block, separated with whitespace instead of a newline:

   Block:  " " [PP_BreakLine] "{" [PP_Indent] 
              "\n" $ [PP_Exdent] 
           "\n}"

The third example uses the indentation style commonly known as the GNU indentation style. Here, the braces are set on a new line, indented two positions. The indented region then follows indented four positions. To use this, set the indentation width to two by one of the function calls discussed later. Then use the following pattern:

   Block:  [PP_Indent] "\n{" [PP_Indent] 
               "\n" $ [PP_Exdent] 
           "\n}" [PP_Exdent]

Additional functions

Additional functions exist to influence the behavior of the module.

PP_SetLineWidth(int width)
Sets the linewidth to the specified value. The default is 80.

PP_SetSoftBreakShortcut(char)
Assigns a character that should behave like a call to PP_LineBreak. A good choice for this would be the tab character. The default is set to the null character what disables substitution.

PP_SetIndentationWidth(int width)
Sets the amount to indent in one indentation level. Indentation is normally done by spaces. If a negative value is used, a tab character will be used for one indentation step (counting as 8 character positions).

PP_SetEndline(char *endline)
Assigns the given string to be used as end-of-line sequence. Default for this is `"\n"'. Another good choice would be `"\r\n"'.

All these functions need to be called prior to the start of the output with one of the following functions. They replace the PTG generated ones, if PrettyPrinting should be used.

PP_OutFPtr(FILE *f, PTGNode n)
Outputs the given `PTGNode' to the given file that must have been opened for output.

PP_OutFile(char *filename, PTGNode n)
Outputs the given `PTGNode' to the named file.

PP_Out(PTGNode n)
Outputs the given `PTGNode' to the standard output.

Usage of Module

To use the pretty printing module, simply include it's name in one of the .specs files:

   $/Output/PrettyPrint.fw

Restrictions

In two cases it is possible that an output line exceeds the given maximal length:

  • A sequence of characters longer than the specified linewidth is output without intermediate call to PP_LineBreak.
  • A PTG Pattern contains tab characters that will be counted to have a width of 1 which of course is not always true.

Additional information about this module and it's implementation can be obtained by the derivation

   $elipkg/Output/PrettyPrint.fw :fwTexinfo :display


Previous Chapter Next Chapter Table of Contents