Print depth

Another pattern matching technique used frequently concerns the print depth of the tree we want to pretty print. The Ppml environment allows us to specify how deep the pretty printer should descend when unparsing the tree. If, in the Centaur editor, we set the print level to 100, for example, the root of the tree will have a print level value of 100, its children 99, the grandchildren 98, etc. We may want to reduce the print depth if, for example, unparsing the whole tree would produce a lot of text, and we want see the overall structure of the tree, without scrolling. The operator ``!'' in the pattern section of a rule, indicates at what print level a rule should be applied. Thus, the pattern:

*x !0 -> ...

matches any node when the print level is zero. The complete rule:

*x !0 -> [ "..."] ;

tells the pretty printer to print ellipses when the print level is zero. This saves a lot of space on the screen. Additionally, this saves some time, since no recursive unparsing calls are made after encountering a node whose print level is zero. Recursive calls in the formatting section of a rule are explained below.

For all pattern matching techniques, whether by text, print level, or annotation, remember that:

The most specific rules should appear at the beginning of the pretty printer specification.


Tutorial