DIRECTORY TextFind, TiogaNode, Rope; TreeFind: CEDAR DEFINITIONS IMPORTS TextFind = BEGIN Path: TYPE = TiogaNode.Path; Ref: TYPE = TiogaNode.Ref; RefTextNode: TYPE = TiogaNode.RefTextNode; Offset: TYPE = TiogaNode.Offset; ROPE: TYPE = Rope.ROPE; MaxLen: Offset = LAST[Offset]; Finder: TYPE = TextFind.Finder; Create: PROC [ pattern: RefTextNode, literal, word, ignoreLooks, ignoreCase, addBounds: BOOL _ FALSE, patternStart: Offset _ 0, patternLen: Offset _ MaxLen] RETURNS [Finder] = INLINE { RETURN [TextFind.Create[ pattern,literal,word,ignoreLooks,ignoreCase,addBounds,patternStart,patternLen]] }; CreateFromRope: PROC [pattern: ROPE, literal, word, ignoreCase, addBounds: BOOL _ FALSE, patternStart: Offset _ 0, patternLen: Offset _ MaxLen] RETURNS [Finder] = INLINE { RETURN [TextFind.CreateFromRope[ pattern,literal,word,ignoreCase,addBounds,patternStart,patternLen]] }; CommentControl: TYPE = { includeComments, excludeComments, commentsOnly }; Try: PROC [finder: Finder, first: Path, start: Offset _ 0, last: Path _ [NIL, NIL], lastLen: Offset _ MaxLen, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOLEAN _ FALSE, format: TiogaNode.Name _ TiogaNode.nullName, checkStyle: BOOLEAN _ FALSE, style: TiogaNode.Name _ TiogaNode.nullName, styleProc: PROC [Ref] RETURNS [TiogaNode.Name] _ NIL, interrupt: REF BOOL _ NIL] RETURNS [found: BOOLEAN, where: Path, at, atEnd, before, after: Offset]; TryBackwards: PROC [finder: Finder, first: Path, len: Offset _ MaxLen, last: Path _ [NIL, NIL], lastStart: Offset _ 0, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOLEAN _ FALSE, format: TiogaNode.Name _ TiogaNode.nullName, checkStyle: BOOLEAN _ FALSE, style: TiogaNode.Name _ TiogaNode.nullName, styleProc: PROC [Ref] RETURNS [TiogaNode.Name] _ NIL, interrupt: REF BOOL _ NIL] RETURNS [found: BOOLEAN, where: Path, at, atEnd, before, after: Offset]; Apply: PROC [finder: Finder, first: Path, proc: ApplyProc, start: Offset _ 0, last: Path _ [NIL, NIL], lastLen: Offset _ MaxLen, looksExact: BOOL _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOLEAN _ FALSE, format: TiogaNode.Name _ TiogaNode.nullName, checkStyle: BOOLEAN _ FALSE, style: TiogaNode.Name _ TiogaNode.nullName, styleProc: PROC [Ref] RETURNS [TiogaNode.Name] _ NIL] RETURNS [count: LONG INTEGER]; ApplyProc: TYPE = PROC [where: Path, at, atEnd, before, after: Offset] RETURNS [continue, bumpCount: BOOL, from, delta: Offset]; END. ÆTreeFind.mesa; written by Bill Paxton, June 1981 edited by McGregor, February 8, 1983 9:43 am edited by Bill Paxton, December 30, 1982 10:30 am This module provides a "Find" operation for text in trees The pattern matching is done by TextFind.Mesa This module simply walks the tree (forward or backwards) applying the text creates a record containing a "compiled" version of the pattern see TextFind.Mesa for more info about patterns if literal is true, each character in pattern is taken literally if word flag is true, pattern only matches if no adjacent letters or digits if ignoreLooks if true, then ignore the looks of the pattern characters if ignoreCase is false, then alpha chars in pattern must match case otherwise, they can match either upper or lower if addBounds is true, add |'s to both ends of pattern searches first node beginning at start continues until finds a match or reaches last node seaches lastLen chars in last node; seaches to end of other nodes if finds a match, returns with found = true, at = beginning of match or location corresponding to { in pattern atEnd = end of match or location corresponding to } in pattern after = end of entire match, which may be > atEnd if used } in pattern before = start of entire match, which may be < at if used { in pattern if looksExact is true, then match by equality, else by subset commentControl allows restriction of search to comments/noncomments if checkType is true, then only match in nodes with given type if checkStyle is true, then only match in nodes with given style styleProc is supplied so called can determine style for nodes if just interested in type/style, can pass finder=NIL if interrupt^ becomes true, will stop searching searches first node from start=0 to end=len continues back through tree until finds a match or reaches last node searches from lastStart in last node; searches from 0 in other nodes finds a span of text and calls proc arg's are results from Try if continue is true, Apply will Try again starting at "from" in "where" delta tells change in length caused by the action Apply does the following with delta IF where=last AND lastLen < MaxLen THEN lastLen _ lastLen+delta if bumpCount is true, Apply will increment its result counter ÊǘJšœ0™0Jšœ,™,Jšœ1™1J˜Jšœ9™9Jšœ-™-JšœJ™JJ˜JšÏk ˜ J˜ J˜ J˜J˜Jšœ œœ ˜.Jš˜J˜Jšœœ˜Jšœœ˜Jšœ œ˜*Jšœœ˜ Jšœœœ˜Jšœœ ˜Jšœœ˜J˜šÏnœœ˜JšœIœœ˜VJ˜6šœ œœ˜4J˜R—Jšœ?™?Jšœ.™.Jšœ@™@JšœK™KJšœG™GšœC™CJšœ/™/—Jšœ5™5J˜—š žœœ œ(œœ˜XJ˜6šœ œœ˜™>JšœF™FJšœF™FJšœ=™=JšœC™CJšœ>™>šœ@™@Jšœ=™=—Jšœ5™5Jšœ/™/J˜—šž œœ˜0Jšœ$œœ˜EJšœ œœ3˜NJšœ œœ.˜JJšœ œœ-˜HJšœ œœœ˜5Jšœ œœœ˜Jšœ œ1˜HJšœ+™+JšœD™DJšœD™DJ˜—šžœœB˜MJš œœœ)œœ˜LJ˜1Jšœ œœ.˜JJšœ œœ-˜HJšœ œœœ˜5Jšœ œœ˜Jšœ#™#J˜—šž œœœ0˜FJšœœ˜9Jšœ™JšœG™Gšœ1™1Jšœ#™#Jšœ?™?—Jšœ=™=J˜—Jšœ˜J˜—…— âo