TextFind.mesa
Copyright Ó 1985, 1986, 1991, 1992 by Xerox Corporation. All rights reserved.
Pattern syntax derived from EditorFind.mesa of Laurel 6
Old version of TextFind.mesa written by Bill Paxton, May 1981
Major redesign by Doug Wyatt, December 1991
Doug Wyatt, March 11, 1992 7:04 pm PST
DIRECTORY
Char USING [XCHAR],
Rope USING [ROPE];
TextFind: CEDAR DEFINITIONS ~ BEGIN
XCHAR: TYPE ~ Char.XCHAR;
ROPE: TYPE ~ Rope.ROPE;
Literal search
Direction: TYPE ~ {forward, backward};
LiteralSearch: PROC [direction: Direction,
targetHash: PROC [INT] RETURNS [BYTE], targetStart: INT, targetLen: INT,
objectHash: PROC [INT] RETURNS [BYTE], objectStart: INT, objectLen: INT,
match: PROC [objectStart, targetStart, len: INT] RETURNS [BOOL],
interrupt: REF BOOL ¬ NIL] RETURNS [found: BOOL ¬ FALSE,
matchStart, matchEnd: INT ¬ 0];
CharMap: TYPE ~ REF CharMapRep;
CharMapRep: TYPE ~ PACKED ARRAY CHAR OF CHAR;
CharMapFromCase: PROC [case: BOOL] RETURNS [CharMap];
case=TRUE means case is significant (same convention as the Rope interface)
Pattern search and replace
FetchProc: TYPE ~ PROC [index: INT] RETURNS [XCHAR];
return the character at the given index in the object text
SubstrProc: TYPE ~ PROC [start, len: INT] RETURNS [Text];
return an immutable representation of a substring of the object text
Text: TYPE ~ REF;
Either ROPE or a type private to Tioga.
Target: TYPE ~ REF TargetRep;
TargetRep: TYPE; -- see TextFindImpl
CreateTarget: PROC [size: INT, start: INT ¬ 0, len: INT ¬ INT.LAST,
fetch: FetchProc, substr: SubstrProc, pattern: BOOL ¬ FALSE]
RETURNS
[Target];
creates a search target from the specified text
pattern -> parse the text as a pattern description, else use it literally
addBounds -> ensure that the target has left and right boundary items
may raise Error if the pattern is malformed
Error: ERROR [index: INT, reason: ROPE];
WildType: TYPE ~ {any, alpha, nonalpha, blank, nonblank};
MatchTypeProc: TYPE ~ PROC [index: INT, type: WildType] RETURNS [BOOL];
test whether object[index] has the specified type
MatchStringProc: TYPE ~ PROC [index: INT, text: Text, start: INT, len: INT] RETURNS [BOOL];
test whether object[index..index+len) matches text[start..start+len)
Bound: TYPE ~ {start, end};
MatchBoundProc: TYPE ~ PROC [index: INT, bound: Bound] RETURNS [BOOL];
test whether index is an acceptable matchStart/matchEnd
Subs: TYPE ~ REF SubsRep;
SubsRep: TYPE; -- see TextFindImpl
Search: PROC [direction: Direction, target: Target,
size: INT, start: INT ¬ 0, len: INT ¬ INT.LAST, substr: SubstrProc,
matchType: MatchTypeProc, matchString: MatchStringProc,
matchProps: MatchStringProc ¬ NIL, matchBound: MatchBoundProc ¬ NIL,
interrupt: REF BOOL ¬ NIL] RETURNS [found: BOOL ¬ FALSE,
matchStart, matchEnd, selStart, selEnd: INT ¬ 0, subs: Subs ¬ NIL];
searches in direction for target in object[start..start+len)
if the target has named subpatterns, subs represents what they matched
abort the search if interrupt^ becomes true
ReplaceProc: TYPE ~ PROC [start, len: INT];
emit replacement[start..start+len)
SubstituteProc: TYPE ~ PROC [text: Text, start, len: INT, nameStart, nameLen: INT];
emit text[start..start+len), corresponding to replacement[nameStart..nameStart+nameLen)
Replace: PROC [replace: ReplaceProc, substitute: SubstituteProc,
size: INT, start: INT ¬ 0, len: INT ¬ INT.LAST, fetch: FetchProc,
pattern: BOOL ¬ FALSE, subs: Subs ¬ NIL];
calls replace and substitute to emit the result of a replacement
uses the specified text as the replacement source
if pattern, parses the text as a replacement pattern, substituting names from subs
Rope operations
RopeLiteralSearch: PROC [direction: Direction,
target: ROPE, targetStart: INT ¬ 0, targetLen: INT ¬ INT.LAST,
object: ROPE, objectStart: INT ¬ 0, objectLen: INT ¬ INT.LAST,
case: BOOL ¬ TRUE] RETURNS [found: BOOL, matchStart, matchEnd: INT ¬ 0];
TargetFromRope: PROC [rope: ROPE, start: INT ¬ 0, len: INT ¬ INT.LAST,
pattern: BOOL ¬ FALSE] RETURNS [Target];
RopeSearch: PROC [direction: Direction, target: Target,
rope: ROPE, start: INT ¬ 0, len: INT ¬ INT.LAST,
case: BOOL ¬ TRUE, word, def, all: BOOL ¬ FALSE,
interrupt: REF BOOL ¬ NIL] RETURNS [found: BOOL ¬ FALSE,
matchStart, matchEnd, selStart, selEnd: INT ¬ 0, subs: Subs ¬ NIL];
RopeReplace: PROC [rope: ROPE, start: INT ¬ 0, len: INT ¬ INT.LAST,
with: ROPE, pattern: BOOL ¬ FALSE, subs: Subs ¬ NIL] RETURNS [ROPE];
END.