The format part (right hand side) of a Ppml rule expresses the concrete layout of patterns. Formatting directives may be any of the following:
N.B. Recursive calls on atomic values that
are not trees causes a fatal error during execution. The following
rule will provoke such an error:
id *x -> [
The type of a box determines how each element- terminal, variable, or other boxes- will be aligned. Ppml provides five types of boxes:
The type of a box, also called the global operator, determines the spacing of all elements at the current level. It does not indicate how to format the elements found within nested boxes. In the following example:
[
the results of the instantiation of *x, *y, the
inner
We format the plus operator as follows:
[
Ppml provides a device to treat lists -the parentheses operator. We
may indicate, between parentheses, how to arrange tokens and elements
of a list, and we may even use the ``case'' instruction to select
formatting for different operators in the list. Suppose for our
operator exp_s we simply want to line up all expressions
vertically. We would write:
[
The next box separates expressions horizontally, unless the list
is too long, in which case it separates them vertically:
[
Note that the following construction:
[
does not separate the elements vertically with a ``;''
at the end of each expression, but arranges everything vertically
since the global operator
[
The
Note that this rule corresponds to Exp's concrete syntax
definition -expressions are separated by semi-colons. Another
concrete syntax definition might have specified that each expression
terminates with a semi-colon, in which case we would format each
expression with:
[
and a list of expressions with:
[
In this case, the expression rule prints the semi-colon. If
we send an expression to a textual editor, both the expression and the
semi-colon appear in the editor. Since the concrete syntax definition
requires that each expression be terminated by a semi-colon, we may
immediately reparse the expression. Using this rule to pretty print
Exp expressions would produce visually similar text, but pretty
printed expressions would not be reparsable. The basic pretty
printer should always format text so that it is reparsable.
In the above examples, we use default values for the different separators. It
is often desirable to override these values locally. The Ppml
reference manual explains the meaning of each separator's parameters.
The
[
We have everything we need for a simple pretty printer, though we will
discuss other techniques and shortcuts presently.