TextNode.mesa
Copyright Ó 1985, 1986, 1991 by Xerox Corporation. All rights reserved.
written by Bill Paxton. December 1980
last written by Paxton. December 21, 1982 9:46 am
Last Edited by: Maxwell, January 5, 1983 12:37 pm
Rick Beach, March 27, 1985 1:08:21 pm PST
Michael Plass, October 4, 1989 1:09:19 am PDT
Doug Wyatt, February 27, 1992 2:51 pm PST
Node: TYPE ~ Tioga.Node;
Location: TYPE = Tioga.Location;
NodeItself: INT = Tioga.NodeItself;
nullLocation: Location = Tioga.nullLocation;
Span: TYPE = Tioga.Span;
nullSpan: Span = Tioga.nullSpan;
MaxLen: INT = INT.LAST;
Ref, RefTextNode: TYPE = Node; -- for compatibility
Offset: TYPE = INT; -- for compatibility
MakeNodeLoc:
PROC [n: Node]
RETURNS [Location]
~ INLINE { RETURN[[n, NodeItself]] };
MakeNodeSpan:
PROC [first, last: Node]
RETURNS [Span]
~ INLINE { RETURN[[MakeNodeLoc[first], MakeNodeLoc[last]]] };
NarrowToTextNode:
PROC [n: Node]
RETURNS [Node]
~ INLINE { RETURN[n] }; -- for compatibility
NewTextNode:
PROC
RETURNS [Node];
Parent:
PROC [n: Node]
RETURNS [Node];
Root:
PROC [n: Node]
RETURNS [Node];
Next:
PROC [n: Node]
RETURNS [Node];
returns next sibling of n
returns NIL if n is last sibling
Previous:
PROC [n: Node, parent: Node ¬
NIL]
RETURNS [nx: Node];
returns previous sibling of n
returns NIL if n is first sibling
runs faster if can supply parent
Forward:
PROC [node: Node]
RETURNS [nx: Node, levelDelta:
INTEGER];
returns next node in standard tree walk order
levelDelta is level(node)-level(nx), where level is depth in tree
levelDelta = 0 if nx and node are siblings
levelDelta = 1 if nx is child of node
levelDelta < 0 if do Parent* and Next to reach nx from node
Backward:
PROC [node: Node, parent: Node ¬
NIL]
RETURNS [back, backparent: Node, levelDelta: INTEGER];
for backing through tree
runs faster if can supply parent
levelDelta same as for Forward
StepForward:
PROC [node: Node]
RETURNS [Node];
returns next node in standard tree walk order
StepBackward:
PROC [node: Node, parent: Node ¬
NIL]
RETURNS [Node];
returns preceding node in standard tree walk order
Level:
PROC [node: Node]
RETURNS [level:
INTEGER];
Level[Root[x]] == 0; Level[FirstChild[n]]=Level[n]+1
ForwardClipped:
PROC [node: Node, maxLevel:
INTEGER, nodeLevel:
INTEGER ¬ 0]
RETURNS [nx: Node, nxLevel:
INTEGER];
like Forward, but limits how deep will go in tree
if pass nodeLevel=0, correct value will be computed
nxLevel = Level[nx] <= MAX[maxLevel,Level[node]]
BackwardClipped:
PROC [node: Node, maxLevel:
INTEGER, parent: Node ¬
NIL,
nodeLevel:
INTEGER ¬ 0]
RETURNS [back, backparent: Node, backLevel:
INTEGER];
like Backward, but limits how deep will go in tree
backLevel = Level[back] <= MAX[maxLevel,Level[node]]
LocRelative:
PROC [location: Location, count:
INT,
break:
NAT ¬ 1, skipCommentNodes:
BOOL ¬
FALSE]
RETURNS [Location];
count is interpreted as a character offset from given location
returns <node,offset> location corresponding to count
adds in break at the end of each text subnode
if skipCommentNodes is true, then ignores them in walking the tree
LocWithin:
PROC [n: Node, count:
INT, break:
NAT ¬ 1, skipCommentNodes:
BOOL ¬
FALSE]
RETURNS [Location];
LocOffset:
PROC [loc1, loc2: Location, break:
NAT ¬ 1, skipCommentNodes:
BOOL ¬
FALSE]
RETURNS [count:
INT];
returns character offset of location2 relative to location1
loc1 and loc2 can be in same node
but loc2 must not be in node before loc1 or get ERROR BadArgs
if skipCommentNodes is true, then ignores them in walking the tree
LocNumber:
PROC [at: Location, break:
NAT ¬ 1, skipCommentNodes:
BOOL ¬
FALSE]
RETURNS [count:
INT];
returns character offset of location relative to root
FirstSibling:
PROC [n: Node]
RETURNS [Node];
LastSibling:
PROC [n: Node]
RETURNS [Node];
LastWithin:
PROC [n: Node]
RETURNS [Node];
returns the last node within the branch
i.e., goes to last child of last child of last child ... until no child
LastLocWithin:
PROC [n: Node]
RETURNS [Location];
returns the last location within the branch
FirstChild:
PROC [n: Node]
RETURNS [Node];
LastChild:
PROC [n: Node]
RETURNS [Node];
NthChild:
PROC [n: Node, location:
INT ¬ 0]
RETURNS [child: Node];
NthSibling:
PROC [n: Node, cnt:
INT ¬ 0]
RETURNS [Node];
CountChildren:
PROC [n: Node]
RETURNS [count:
INT];
CountFollowing:
PROC [n: Node]
RETURNS [count:
INT];
CountToParent:
PROC [n: Node]
RETURNS [count:
INT, parent: Node];
CountToChild:
PROC [parent, child: Node]
RETURNS [count:
INT];
EndPos:
PROC [n: Node]
RETURNS [
INT];
DestroyTree:
PROC [root: Node];
sets all REFs in the tree to NIL