## prettyprint-description-g.pkg
## All rights reserved.
# Compiled by:
#
src/lib/prettyprint/big/src/prettyprinting.sublib# This generic implements a declarative way to specify pretty-printing
# (see prettyprint-description.api).
generic package prettyprint_description_g (s: Prettyprint_Stream) # Prettyprint_Stream is from
src/lib/prettyprint/big/src/prettyprint-stream.api: (weak) Prettyprint_Description # Prettyprint_Description is from
src/lib/prettyprint/big/src/prettyprint-description.api{
package pps = s;
Token = pps::Token;
Style = pps::Style;
Indent = pps::Indent;
# The Prettyprint_Description type is a
# concrete representation
# of a pp layout:
Prettyprint_Description
= HORIZONTAL_BOX List( Prettyprint_Description )
| VERTICAL_BOX ((Indent, List( Prettyprint_Description )) )
| HORIZONTAL_ELSE_VERTICAL_BOX ((Indent, List( Prettyprint_Description )) )
| WRAP_BOX ((Indent, List( Prettyprint_Description )) )
| BOX ((Indent, List( Prettyprint_Description )) )
| TOKEN Token
| STRING String
| STYLE ((Style, List( Prettyprint_Description )) )
| BREAK { spaces: Int, indent_on_wrap: Int }
| NEW_LINE
| NBSPACE Int
| CONTROL (pps::Device -> Void);
# Prettyprint a description:
fun description (stream, ppd)
=
{ fun prettyprint (HORIZONTAL_BOX l) => { pps::begin_horizontal_box stream; prettyprint_list l; pps::end_box stream;};
prettyprint (VERTICAL_BOX (i, l)) => { pps::begin_indented_vertical_box stream i; prettyprint_list l; pps::end_box stream;};
prettyprint (HORIZONTAL_ELSE_VERTICAL_BOX (i, l)) => { pps::begin_indented_horizontal_else_vertical_box stream i; prettyprint_list l; pps::end_box stream;};
prettyprint (WRAP_BOX (i, l)) => { pps::begin_indented_wrap_box stream i; prettyprint_list l; pps::end_box stream;};
prettyprint (BOX (i, l)) => { pps::begin_indented_wrap'_box stream i; prettyprint_list l; pps::end_box stream;};
prettyprint (TOKEN tok) => pps::token stream tok;
prettyprint (STRING s) => pps::string stream s;
prettyprint (STYLE (sty, l)) => { pps::push_style (stream, sty); prettyprint_list l; pps::pop_style stream;};
prettyprint (BREAK brk) => pps::break stream brk;
prettyprint NEW_LINE => pps::newline stream;
prettyprint (NBSPACE n) => pps::nonbreakable_spaces stream n;
prettyprint (CONTROL ctl_g) => pps::control stream ctl_g;
end
also
fun prettyprint_list [] => ();
prettyprint_list (item ! r) => { prettyprint item; prettyprint_list r;};
end;
prettyprint ppd;
};
# Exported pp description constructors:
horizontal_box = HORIZONTAL_BOX;
vertical_box = VERTICAL_BOX;
horizontal_else_vertical_box = HORIZONTAL_ELSE_VERTICAL_BOX;
wrap_box = WRAP_BOX;
box = BOX;
token = TOKEN;
string = STRING;
style = STYLE;
break = BREAK;
fun space n = BREAK { spaces => n, indent_on_wrap => 0 };
cut = BREAK { spaces => 0, indent_on_wrap => 0 };
newline = NEW_LINE;
nonbreakable_spaces = NBSPACE;
control = CONTROL;
};
## COPYRIGHT (c) 2005 John Reppy (http://www.cs.uchicago.edu/~jhr)
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2013,
## released per terms of SMLNJ-COPYRIGHT.