LORAPrinting.Mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Spreitzer, January 22, 1986 7:29:21 pm PST
DIRECTORY Convert, IO, Rope, StructuredStreams, UnparserBuffer;
LORAPrinting: CEDAR PROGRAM
IMPORTS Convert, IO, StructuredStreams, UnparserBuffer
= {OPEN SS: StructuredStreams, UB: UnparserBuffer;
LORA: TYPE = LIST OF REF ANY;
ROPE: TYPE = Rope.ROPE;
breakLast: BOOLTRUE;
lastOffset: INT ← 0;
PrettyPrintREF: PROC [to: IO.STREAM, ra: REF ANY] = {
IF ra = NIL THEN to.PutRope["()"] ELSE WITH ra SELECT FROM
lora: LORA => {
to.PutChar['(];
SS.Begin[to];
{ENABLE UNWIND => SS.End[to];
FOR l: LORA ← lora, l.rest WHILE l # NIL DO
PrettyPrintREF[to, l.first];
IF l.rest # NIL THEN {to.PutChar[' ]; SS.Bp[to, FALSE, 0]}
ELSE IF breakLast THEN SS.Bp[to, FALSE, lastOffset];
ENDLOOP;
to.PutChar[')];
};
SS.End[to];
};
ri: REF INT => {
to.PutF["%g", [integer[ri^]]];
};
r: ROPE => {
to.PutRope[Convert.RopeFromRope[r]];
};
a: ATOM => {
to.PutF["%g", [atom[a]]];
};
ENDCASE => to.PutF["%g", [refAny[ra]]];
};
Print: PROC [to: IO.STREAM, ra: REF ANY] = {
ubh: UB.Handle = UB.NewHandle[[stream[to]]];
ss: IO.STREAM = SS.Create[ubh];
PrettyPrintREF[ss, ra];
ss.PutRope["\n"];
ss.Close[];
};
}.