## prettyprint-tree-g.pkg
#
# This generic implements a declarative way to specify pretty-printing.
# This lets one package construct a first-cut prettyprint representation
# of a document and then another packages refine it before finally
# shipping it off for actual rendering.
# Compiled by:
#
src/lib/prettyprint/big/prettyprinter.lib### "The difference between the true hacker
### and the mere power user is that the
### limits of what a power user can achieve
### are set by his tools, but the hacker is
### master of his tools, and lives in a
### world without limits.
###
### "Every true hacker is necessarily a compiler
### hacker at need, as well as an editor hacker,
### kernel hacker, and so forth.
###
### "True hackers are a rare breed. For every
### one of them, you will find a thousand
### power users posing as hackers, more often
### than not without even realizing the difference."
###
### -- Willy Simons
generic package prettyprint_tree_g (
# ==================
#
pp: Base_Prettyprinter # Base_Prettyprinter is from
src/lib/prettyprint/big/src/base-prettyprinter.api)
{
Traitful_Text = pp::Traitful_Text;
Texttraits = pp::Texttraits;
Left_Margin_Is = pp::typ::Left_Margin_Is;
# The Prettyprint_Tree type is
# a concrete representation
# of a prettyprint layout:
Prettyprint_Tree
= HORIZONTAL_BOX (Left_Margin_Is, List( Prettyprint_Tree ))
| VERTICAL_BOX (Left_Margin_Is, List( Prettyprint_Tree ))
| ALIGN_BOX (Left_Margin_Is, List( Prettyprint_Tree ))
| WRAP_BOX (Left_Margin_Is, List(Prettyprint_Tree))
| TRAITFUL_TEXT Traitful_Text
| TEXT String
| TEXTTRAITS (Texttraits, List(Prettyprint_Tree))
| BREAK { blanks: Int, indent_on_wrap: Int }
| NEW_LINE
| NBBLANK Int
| CONTROL (pp::Prettyprint_Output_Stream -> Void)
;
# Prettyprint a prettyprint tree:
#
fun prettyprint_tree (pp, tree)
=
prettyprint tree
where
fun prettyprint (HORIZONTAL_BOX (i, l)) => { pp::open_box (pp, i, pp::horizontal, 100); prettyprint_list l; pp::shut_box pp; };
prettyprint (VERTICAL_BOX (i, l)) => { pp::open_box (pp, i, pp::vertical, 100); prettyprint_list l; pp::shut_box pp; };
prettyprint (ALIGN_BOX (i, l)) => { pp::open_box (pp, i, pp::normal, 100); prettyprint_list l; pp::shut_box pp; };
prettyprint (WRAP_BOX (i, l)) => { pp::open_box (pp, i, pp::ragged_right, 100); prettyprint_list l; pp::shut_box pp; };
prettyprint (TRAITFUL_TEXT tok ) => pp::traitful_text pp tok;
prettyprint (TEXT s ) => pp::lit pp s;
prettyprint (TEXTTRAITS (tt, l) ) => { pp::push_texttraits (pp, tt); prettyprint_list l; pp::pop_texttraits pp; };
prettyprint (BREAK brk ) => pp::break pp brk;
prettyprint NEW_LINE => pp::newline pp;
prettyprint (NBBLANK n) => pp::nonbreakable_blanks pp n;
prettyprint (CONTROL control_fn) => pp::control pp control_fn;
end
also
fun prettyprint_list [] => ();
prettyprint_list (item ! rest) => { prettyprint item; prettyprint_list rest; };
end;
end;
cut = BREAK { blanks => 0, indent_on_wrap => 0 };
#
fun blank n
=
BREAK { blanks => n, indent_on_wrap => 0 };
};
## COPYRIGHT (c) 2005 John Reppy (http://www.cs.uchicago.edu/~jhr)
## All rights reserved.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.