How To Define Pretty Print Tables
XT -- A Bundle of Program Transformation Tools
Task
How to define pretty-print tables for use with
GPP.
Description
The utility
AsFixToAbox is a language-independent front-end for the pretty-print system
GPP. Instantiated with a set of language specific
formatting rules it becomes a formatter for a specific language.
These formatting rules (or pretty-print rules) define mappings from language constructs (specified as SDF productions) to BOX expressions. BOX is a language independent markup language to describe the intended layout of text. See
this paper for more information about pretty-print tables and the BOX markup language.
Pretty-print entries are defined in an ordered sequence of pretty-print tables.
This ordering allows overruling of pretty-print entries by defining overruling entries in tables with higher precedence.
Examples
A pretty-print entry for a language construct S1 S2 ... Sn -> S looks like:
S1 S2 ... Sn -> S -- H [ _1 _2 ... _n]
This entry defines a horizontal formatting (because of the H operator). The BOX expressions corresponding to the formatted non-terminal symbols S1 S2 ... Sn are refered to using the numbered place holders _1 _2 ... _n
A more advanced example which defines a formatting for an `if-then-else' construct is depicted below:
[
"if" Cond "then" StatSeq "else" StatSeq "fi" -> Stat --
V [ V is=3 [ H[ KW["if"] _1 KW["then"]
_2
]
V is=3 [ KW["else]"
_3
]
KW["fi"]
]
]
The following BOX operators are used in this example: `KW' to format keywords, `H' to layout boxes horizontally, and `V' to format sub-boxes vertically. Furthermore, the space option `is' is used to specify that the boxes in a vertical context should be indented to the right. This example defines that if-then-else constructs should be formatted as:
if Cond then
StatSeq
else
StatSeq
fi
See also
GPP,
HowToPrettyPrintAGrammar