The formatting machine

The Ppml formatter operates as follows. Given a compiled Ppml specification and an abstract syntax tree, it traverses the tree, in search of a rule whose pattern matches the current tree node. The formatting machine observes the modular pretty printer mechanism, so it looks for a matching rule in the first pretty printer component. If it finds no appropriate rule, the second pretty printer in the list is consulted, and so on. The last pretty printer, which is always present and never fails, is the generic pretty printer, which displays the tree as we saw when we read an Exp program before having defined a pretty printer.

Once a rule has been found, the formatting machine resumes its tree traversal and consults the modular pretty printer's first component for a matching rule, etc. If any pretty printer components are themselves modular, the search for a rule continues recursively.


Tutorial