SchemePrettyRead.mesa
Copyright Ó 1990, 1992 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on March 16, 1992 11:24 am PST
DIRECTORY IntToIntTab, IO, Rope, Scheme, TextNode;
SchemePrettyRead: CEDAR DEFINITIONS
=
BEGIN OPEN Scheme;
ROPE: TYPE ~ Rope.ROPE;
Commented: TYPE ~ REF CommentedRep;
CommentedRep: TYPE ~ RECORD [
prefix, postfix: Vector--of Comment, CommentNode, or Linebreaks--,
nonComment: Any
];
Comment: TYPE ~ ROPE;
CommentNode: TYPE ~ TextNode.Ref;
Implicitly carries its terminating linebreak.
Its preceeding linebreak appears explicitly in the Vector.
Linebreaks: TYPE ~ REF LinebreaksRep;
LinebreaksRep: TYPE ~ RECORD [num: INT];
emptyVector: Vector;
VectorAsList: TYPE ~ REF VectorAsListRep;
VectorAsListRep: TYPE ~ RECORD [list: Pair];
FakeAtom: TYPE ~ ROPE;
SourceFilter: TYPE ~ PACKED ARRAY SourceKind OF BOOL;
SourceKind: TYPE ~ {compound, comment, eof, other};
noSource: SourceFilter ~ ALL[FALSE];
allButOther: SourceFilter ~ [compound: TRUE, comment: TRUE, eof: TRUE, other: FALSE];
FormToSource: TYPE ~ IntToIntTab.Table;
key is LOOPHOLE[form]; val is index at start of form.
Read: PROC [from: Port, stackBase: INT, posnsToNote: SourceFilter ¬ allButOther, interrupt: REF BOOL ¬ NIL, addTo: FormToSource ¬ NIL, deltaIndex: INT ¬ 0] RETURNS [form, nonCommented: Any, posns: FormToSource, maxStack: INT];
May raise Complain or Warning.
Returns structure built from: ATOM, FakeAtom, Pair, VectorAsList, Commented; might even return Commented endOfFile. nonCommented=form, unless form is a Commented, in which case nonCommented is the nonComment part.
posns=NIL iff from does not support GetIndex.
If addTo#NIL and from supports GetIndex, then posns=addTo. Value stored in addTo is from.GetIndex[]+delaIndex.
Pass in stackBase an address in a cool part of the stack; maxStack is the largest number of bytes the stack grew beyond stackBase during Read (excluding calls outside the impl). This is for debugging stack overlow problems.
TiogaRead: PROC [start: TextNode.Location, stackBase: INT, posnsToNote: SourceFilter ¬ allButOther, interrupt: REF BOOL ¬ NIL, addTo: FormToSource ¬ NIL, deltaIndex: INT ¬ 0] RETURNS [form, nonCommented: Any, posns: FormToSource, maxStack: INT, next: TextNode.Location, nextIndex: INT];
Like Read, but from a Tioga document. The index of the first char in the span is deltaIndex.
Warning: SIGNAL [message: ROPE];
InfoPrint: PROC [to: IO.STREAM, form: Any];
AffixVector: PROC [to: Any, v: Vector--of Comment, CommentNode, or Linebreaks--] RETURNS [Any];
Returns a Commented, whose postfix ends in v.
END.