Infinite Pretty-printing in eXene
Allen Stoughton · 2001
Abstract. We describe the design and implementation of a Standard ML of New Jersey library for the interactive pretty-printing of possibly infinite syntax trees. The library handles elision in a novel way, and is implemented using Concurrent ML and the eXene X Window System toolkit. 1 Pretty-printing with Elision In the modern approach to pretty-printing, as developed by Oppen [Opp80] and others [Mik81, MCC86, Hug95, Wad98], and featured in Paulson’s textbook [Pau96], prettyprinting of abstract syntax is a two-stage process: • First, an abstract syntax tree is converted into a pretty-printing tree that abstractly describes how the syntax tree should be formatted. Pretty-printing trees are made up of strings, potential line-break points, and various kinds of blocks [Opp80, Pau96] or boxes [Mik81, MCC86, Hug95, Wad98]. • Then, the pretty-printing tree is turned into a sequence of lines that will fit in a window (or file) with a specified width. When a block must be printed at a given indentation-level, the entire block is printed on the current line, if it fits. Otherwise, the block is printed on multiple lines, by converting some or all of the block’s potential line-breaks into actual line-breaks. For example, Figure 1 shows three ways in which the block corresponding to a list might be pretty-printed, depending upon the available line-width. Option (b), in which two block entries are combined on a single line, would be forbidden with some block styles. If a syntax tree can’t be pretty-printed in a window with a given width, then some parts of the tree must be elided, i.e., suppressed. One approach to elision is to elide all subtrees of the syntax tree that are deeper than some level, convert the abbreviated tree to a pretty-printing tree, and then print this tree in the normal way [MCC86]. Unfortunately, with this approach, it is difficult to figure out the best depth at which a given tree should be elided; and, uniform elision at a particular depth may make poor use of the window’s width.