StructuredStreams.Mesa
last edited by Spreitzer September 19, 1985 4:41:40 pm PDT
DIRECTORY IO, Rope, TiogaAccess, UnparserBuffer;
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 (or TiogaAccess.Writer) 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
BufferOutput: TYPE = UnparserBuffer.BufferOutput;
Create: PROCEDURE [onTopOf: UnparserBuffer.Handle] RETURNS [ss: IO.STREAM];
If onTopOf.output is a stream, it will be ss's backingStream.
IsAnSS: PROCEDURE [s: IO.STREAM] RETURNS [BOOLEAN];
GetHandle: PROCEDURE [ss: IO.STREAM] RETURNS [UnparserBuffer.Handle];
Returns what the StructuredStream is layered on top of.
Returns NIL if ss is a non-structured stream.
Strip: PROCEDURE [ss: IO.STREAM] RETURNS [IO.STREAM];
If ss is a non-structured stream, returns ss, else
if ss's UnparserBuffer.Handle.output is a stream, returns that, else
returns NIL
CloseThrough: PROCEDURE [self: IO.STREAM];
Closes both self and the stream (if any) it is on top of.
For non-structured streams, = IO.Close[self].
IO.Close on a StructuredStream does not close the understream (if any).
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 (if any)).
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.