StructuredStreamsTest.Mesa
Copyright Ó 1991 by Xerox Corporation. All rights reserved.
last edited by Spreitzer September 19, 1985 5:16:06 pm PDT
Mike Spreitzer February 21, 1990 10:05 am PST
Last tweaked by Mike Spreitzer on April 6, 1990 11:35 am PDT
Willie-s, September 26, 1991 1:58 pm PDT
Michael Plass, November 22, 1991 5:28 pm PST
DIRECTORY Commander, IO, Rope, StructuredStreams, UnparserBuffer;
StructuredStreamsTest: CEDAR PROGRAM
IMPORTS Commander, IO, StructuredStreams, UnparserBuffer
=
BEGIN OPEN SS:StructuredStreams, UB:UnparserBuffer;
Parse: PROC [from, to: IO.STREAM] RETURNS [level: INTEGER] = {
level ¬ 0;
WHILE NOT from.EndOf[] DO
c: CHAR ¬ from.GetChar[];
SELECT c FROM
'{ => {SS.Begin[to]; level ¬ level + 1};
'} => {SS.End[to]; level ¬ level - 1};
'< => {
cond: SS.XBreakCondition = SELECT from.GetChar[] FROM
'n => never,
'm => miser,
'w => width,
'l => lookLeft,
'u => united,
'a => always,
ENDCASE => ERROR;
offset: INTEGER = from.GetInt[];
sep: Rope.ROPE = from.GetRopeLiteral[];
SS.XBp[to, cond, offset, sep];
WHILE from.GetChar[] # '> DO NULL ENDLOOP;
};
ENDCASE => to.PutChar[c];
ENDLOOP;
level ¬ level;
};
Cmd: Commander.CommandProc ~ {
in: IO.STREAM ~ IO.RIS[cmd.commandLine];
margin: INT ~ in.GetInt[];
miserable: BOOL ~ in.GetBool[];
h: UB.Handle ~ UB.Create[[margin: margin, output: [stream[cmd.out]] ], miserable];
out: IO.STREAM ~ SS.Create[h];
cmd.out.PutF1["%l", [rope["f"]]];
[] ¬ Parse[in, out];
cmd.out.PutF1["%l", [rope[" "]]];
RETURN};
Commander.Register[key: "StructuredStreamsTest", proc: Cmd, doc: "margin miserable (char | '{ | '<('n|'m|'w|'l|'u|'a) int ropeLit> | '})*", interpreted: FALSE];
END.