Compaq AA-PWCBD-TE Computer Accessories User Manual


 
DEC Text Processing Utility Data Types
3.7 Pattern Data Type
Given this definition, the following patterns match the same text but are not
equal:
pat1 := LINE_BEGIN + ANY ("abc");
pat2 := LINE_BEGIN + this_pat;
3.7.4 Compiling and Executing Patterns
When you execute a DECTPU statement that contains a pattern expression,
DECTPU builds an internal representation of the pattern. DECTPU uses the
current contents of any buffers or ranges used as arguments to pattern built-ins
in the pattern expression to build the internal representation. Later changes
to those buffers and ranges do not affect the internal representation for the
pattern. DECTPU also uses the current values of any variables used in the
pattern expression. Later changes to these variables do not affect the internal
representation of the pattern. For example, suppose you wrote the following code
fragment:
p1 := "abc";
p2 := "123";
pat := p1 & p2;
p1 := "xyz";
SEARCH (pat, FORWARD);
Given this code fragment, the search matches the string "abc123" because the
variable pat is evaluated as it is built from p1 and p2 during the assignment
statement.
3.7.5 Searching for a Pattern
The SEARCH and SEARCH_QUIETLY built-ins use the following algorithm to
find a match for a pattern:
1. Put the internal marker that marks the search position at the starting
position for the search. The starting position is determined as follows:
If you do not specify where to search, search the current buffer, starting
at the editing point.
If you specify a buffer or range where the search is to take place, start at
the beginning or end of the buffer or range, depending on the direction of
the search.
2. Check whether the pattern matches text, starting at the current search
position and extending toward the end of the searched buffer or range. If a
range is being searched, the matched text cannot extend beyond the end of
that range. If the pattern matches, return a range that contains the matching
text and stop searching.
3. If the previous step fails, move the search position one character forward or
backward, depending upon the direction of the search. If this is impossible
because the search position is at the end or beginning of the searched buffer
or range, stop searching. If this step succeeds, repeat the previous step.
Note
This algorithm changes if you specify a reverse search for a pattern
starting with SCAN, SPAN, SCANL, or SPANL. For more information, see
the descriptions of these built-in procedures in the DEC Text Processing
Utility Reference Manual.
3–16 DEC Text Processing Utility Data Types