DIRECTORY TiogaNode; TiogaPathOps: CEDAR DEFINITIONS = BEGIN Ref: TYPE = TiogaNode.Ref; Path: TYPE = TiogaNode.Path; Offset: TYPE = TiogaNode.Offset; Location: TYPE = TiogaNode.Location; nullPath: Path = TiogaNode.nullPath; Parent: PROC [p: Path] RETURNS [Path]; -- returns NIL if p is root node Root: PROC [p: Path] RETURNS [Path]; Next: PROC [p: Path] RETURNS [nxt: Path] ; FirstSibling: PROC [p: Path, parent: Path _ nullPath] RETURNS [sib: Path] ; LastSibling: PROC [p: Path] RETURNS [sib: Path] ; Previous: PROC [p: Path, parent: Path _ nullPath] RETURNS [sib: Path] ; LastWithin: PROC [p: Path] RETURNS [Path]; StepForward: PROC [p: Path] RETURNS [nx: Path] = INLINE { [nx,] _ Forward[p] }; Forward: PROC [p: Path] RETURNS [nx: Path, levelDelta: INTEGER]; ForwardClipped: PROC [p: Path, maxLevel: INTEGER, nodeLevel: INTEGER _ 0] RETURNS [nx: Path, nxLevel: INTEGER]; StepForwardNode: PROC [p: Path] RETURNS [nx: Path]; StepBackward: PROC [p: Path, parent: Path _ nullPath] RETURNS [back: Path] = INLINE { [back,,] _ Backward[p,parent] }; Backward: PROC [p: Path, parent: Path _ nullPath] RETURNS [back: Path, backparent: Path, levelDelta: INTEGER]; BackwardClipped: PROC [ p: Path, maxLevel: INTEGER, parent: Path _ nullPath, nodeLevel: INTEGER _ 0] RETURNS [back: Path, backparent: Path, backLevel: INTEGER]; StepBackwardNode: PROC [p: Path, parent: Path _ nullPath] RETURNS [back, backparent: Path]; LastLocWithin: PROC [p: Path] RETURNS [Location]; LocRelative: PROC [ location: Location, count: Offset, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [Location]; LocWithin: PROC [ p: Path, count: Offset, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [Location] = INLINE { RETURN [LocRelative[[p,0],count,break,skipCommentNodes]] }; LocOffset: PROC [loc1, loc2: Location, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [count: Offset]; BadArgs: ERROR; LocNumber: PROC [at: Location, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [count: Offset]; BackLoc: PROC [loc: Location] RETURNS [new: Location]; ForwardLoc: PROC [loc: Location] RETURNS [new: Location]; Equal: PROC [p1, p2: Path] RETURNS [BOOL] ; Contents: PROC [p: Path] RETURNS [Path] ; BranchChild: PROC [p: Path] RETURNS [Path] ; Level: PROC [p: Path] RETURNS [level: INTEGER]; -- Level[Root[x]] is 0 Apply: PROC [span: TiogaNode.Span, proc: ApplyProc]; ApplyProc: TYPE = PROC [p: Path, start, len: Offset] RETURNS [stop: BOOL]; END. TiogaPathOps.mesa; Written by Paxton, July 1983 edited by Paxton, July 12, 1983 9:31 am Tree traversal procedures Note: If you use these routines to access the tree, you don't need to worry about converting branches to internal representation. It will be done automatically. The root is found by taking Parent until get a node with parent=NIL. This returns the next sibling, or NIL if p is the last sibling. Returns p if p is the first sibling Returns p if p is the last sibling Returns NIL if p=FirstSibling[p] Runs faster if you can supply the parent. But ok to default it too. returns the last node within p. goes down into contents of the last branch. Moving forward returns next branch p in standard tree walk order returns next branch in standard tree walk order levelDelta is level(p)-level(nx), where level is depth in tree levelDelta = 0 if nx and p are siblings levelDelta = 1 if nx is child of p levelDelta < 0 if do Parent* and Next to reach nx from p 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[p]] Like StepForward, but visits contents of branches as well as children. Moving backward returns preceeding branch p in standard tree walk order runs faster if can supply parent; parent can be branch, box, or list p. for backing through tree levelDelta same as for Forward like Backward, but limits how deep will go in tree backLevel = Level[back] <= MAX[maxLevel,Level[p]] Like StepBackward, but visits contents of branches as well as children. Location procedures returns the last location within the branch count is interpreted as a character offset from given location returns 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 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 returns character offset of location relative to root Miscellaneous Branches, boxes, and lists have contents. Returns nullPath if p doesn't point to a branch Apply the proc to each node in the span until complete span or proc returns TRUE. ʘJšœ/™/Jšœ'™'J˜šÏk ˜ Jšœ ˜ J˜—Jšœœ œ˜'J˜Jšœœ˜Jšœœ˜Jšœœ˜ Jšœ œ˜$Jšœ$˜$J˜™J™J™¡J˜šÏnœœ œ Ïc ˜GJ˜—šžœœ œ˜$J™DJ˜—šžœœ œ˜*J™?J˜—šž œœ$œ˜KJ™#J˜—šž œœ œ˜1J™"J˜—šžœœ$œ˜GJšœœ™ J™DJ˜—šž œœ œ˜*JšœL™L—J˜—™J™šž œœ œœ˜OJšœ Ïbœ™1J˜—šžœœ œœ˜@Jšœ  œ™/šœ>™>Jšœ'™'Jšœ"™"Jšœ8™8J˜——šžœœœ œ˜IJšœœ˜%Jšœ1™1Jšœ4™4Jšœ-™-J™—šžœœ œ ˜3J™F—J˜—™J™šž œœ$œœ˜UJšœ œ™7JšœG™GJ˜ J˜—šžœœ#˜1Jšœ,œ˜™>Jšœ5™5Jšœ-™-JšœB™BJ˜—šž œœ˜Jšœœœœ˜Gšœœ˜Jšœ5˜;—J˜—šž œœ˜&Jš œœœœœ˜HJšœ;™;Jšœ!™!Jšœ=™=JšœB™BJ˜—šžœœ˜J˜—š ž œœœœœ˜NJšœ˜Jšœ5™5J˜—šžœœœ˜6J˜—Jšž œœœ˜9J˜—™ J˜šžœœœœ˜+J˜—šžœœ œ ˜)J™)J˜—šž œœ œ ˜,J™/J˜—š žœœ œ œŸ˜FJ˜—šžœœ)˜4J™Q—˜Jš ž œœœœœ˜J——J˜Jšœ˜J˜J˜—…— °Š