FILE: StructuredStreams.Mesa from [Indigo]<PreCedar>Top>StructuredStreams.DF
last edited by Spreitzer December 12, 1983 1:19 pm
DIRECTORY
Rope, IO;
Greg Nelson has implemented a package called UnparserBuffer for his use in formatting Juno programs. StructuredStreams is a streams interface to it. A StructuredStream is an output stream, layered on another stream which recieves the formatted characters. A StructuredStream takes in a stream of characters, delimited into nested objects, each of which has a beginning, an end, and some breakpoints. The StructuredStream delivers to its understream the characters, interspersed with various white space characters (carriage returns and spaces) according to the formatting rules (described in UnparserBuffer.Mesa). The rules are such that characters sent to a StructuredStream outside of any object delimiters will not get any white space inserted among them. Also, StructuredStreams has been defined so that an ordinary stream used in place of a StructuredStream gives no ill effects.
StructuredStreams: CEDAR DEFINITIONS =
BEGIN
Create: PROCEDURE [onTopOf: IO.STREAM, margin: INTEGER ← 69] RETURNS [ss: IO.STREAM];
"ss" has "onTopOf" as its backingStream.
IsAnSS: PROCEDURE [s: IO.STREAM] RETURNS [BOOLEAN];
UnderStream: PROCEDURE [ss: IO.STREAM] RETURNS [IO.STREAM];
Returns the stream the StructuredStream is layered on top of.
If ss is a non-structured stream, ss is returned.
CloseThrough: PROCEDURE [self: IO.STREAM];
Closes both self and the stream it is on top of.
For non-structured streams, = IO.Close[self].
IO.Close on a StructuredStream does not close the understream.
Although StructuredStreams have some buffering (between the earliest undecideable breakpoint and the current position), StructuredStreams pass on characters as soon as possible. Thus, IO.Flush on a StructuredStream is a no-op (except that it is called on the backingStream).
The following proc's, peculiar to StructuredStreams, are no-ops on non-structured streams:
Begin, End: PROCEDURE [ss: IO.STREAM];
Setb and Enb of UnparserBuffer
Bp: PROCEDURE [ss: IO.STREAM, united: BOOLEAN, offset: INTEGER];
A carriage-return sent to a StructuredStream becomes a call on Newlineb in UnparserBuffer.
ChangeMargin: PROCEDURE [ss: IO.STREAM, newMargin: INTEGER ← 69];
Should only be called immediately after a carriage-return.
END.