TextFind.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
derived from EditorFind.Mesa of Laurel 6
written by Bill Paxton, May 1981
last edit by Paxton, December 30, 1982 10:33 am
Michael Plass, March 21, 1985 2:40:46 pm PST
Doug Wyatt, August 28, 1986 6:28:12 pm PDT
This module provides a "Find" operation for text nodes
The pattern is given as a substring of a text node
The text to be searched is also a substring of a text node
The search can be in either direction within the substring
If a match character in the pattern has looks,
the looks of the matching character(s) in the text will include those looks.
For example, if the pattern includes a * with looks x and y,
the characters matching the * will have looks x and y too.
The matching characters may have other looks too.
DIRECTORY
Rope USING [ROPE],
TextLooks USING [Looks],
TextNode USING [Node],
TextFindPrivate USING [FinderRecord];
TextFind: CEDAR DEFINITIONS
= BEGIN
Node: TYPE = TextNode.Node;
ROPE: TYPE = Rope.ROPE;
CR: CHAR = '\n;
MalformedPattern: ERROR [ec: PatternErrorCode];
PatternErrorCode: TYPE = {
toobig, -- pattern too long
endquote, -- pattern ends with '
endtilda, -- pattern ends with ~
boundary, -- pattern has | inside rather than at beginning or end
missingNameEnd, -- pattern has < without matching >
unmatchedNameEnd -- pattern has > without previous <
};
Finder: TYPE = REF FinderRec;
FinderRec: TYPE = TextFindPrivate.FinderRecord;
Create: PROC [pattern: Node,
literal, word, ignoreLooks, ignoreCase, addBounds: BOOLFALSE,
patternStart: INT ← 0, patternLen: INTLAST[INT]] RETURNS [finder: Finder];
creates a record containing a "compiled" version of the pattern
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 is 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
CreateFromRope: PROC [pattern: ROPE,
literal, word, ignoreCase, addBounds: BOOLFALSE,
patternStart: INT ← 0, patternLen: INTLAST[INT]] RETURNS [finder: Finder];
NameLoc: PROC [finder: Finder, name: ROPE] RETURNS [at, atEnd: INT];
name is the name of a subpattern
value is where that subpattern matched last time
NameLooks: PROC [finder: Finder, name: ROPE] RETURNS [looks: TextLooks.Looks];
name is the name of a subpattern
value are looks that name had in the pattern
Try: PROC [finder: Finder, text: Node,
start: INT ← 0, len: INTLAST[INT], looksExact: BOOLFALSE,
interrupt: REF BOOLNIL] RETURNS [found: BOOL, at, atEnd, before, after: INT];
searches text for first match in [start..start+len)
i.e., searches up from start until reaches start+len
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
if interrupt^ becomes true, will stop searching
TryBackwards: PROC [finder: Finder, text: Node,
start: INT ← 0, len: INTLAST[INT], looksExact: BOOLFALSE,
interrupt: REF BOOLNIL] RETURNS [found: BOOL, at, atEnd, before, after: INT];
searches text for last match in [start..start+len)
i.e., searches down from start+len until reaches start
SearchRope: PROC [finder: Finder, rope: ROPE, start: INT ← 0, len: INTLAST[INT],
interrupt: REF BOOLNIL] RETURNS [found: BOOL, at, atEnd, before, after: INT];
SearchRopeBackwards: PROC [finder: Finder, rope: ROPE, start: INT ← 0, len: INTLAST[INT],
interrupt: REF BOOLNIL] RETURNS [found: BOOL, at, atEnd, before, after: INT];
Find: PROC [pattern, text: Node,
literal, word, ignoreLooks, ignoreCase, looksExact, addBounds: BOOLFALSE,
patternStart: INT ← 0, patternLen: INTLAST[INT],
textStart: INT ← 0, textLen: INTLAST[INT],
interrupt: REF BOOLNIL] RETURNS [found: BOOL, at, atEnd, before, after: INT];
BackwardsFind: PROC [pattern, text: Node,
literal, word, ignoreLooks, ignoreCase, looksExact, addBounds: BOOLFALSE,
patternStart: INT ← 0, patternLen: INTLAST[INT],
textStart: INT ← 0, textLen: INTLAST[INT],
interrupt: REF BOOLNIL] RETURNS [found: BOOL, at, atEnd, before, after: INT];
END.