![]() |
Section 8.17.3.11:
|
![]() |
types SAME = REG_EXP ; REG_EXP = token
This class provides POSIX-style string pattern matching. It provides a matches operation to find out if a test string matches the extended regular expression.
An extended regular expression consists of one or more of the following kinds of components :-
NOTE | The syntax of extended regular expressions is defined in the POSIX standard ISO/IEC 9945-2:1995 to which reference should be made in understanding the regular expression mechanism. |
The following features are required to be implemented for this class in accordance with the specifications given in $BINARY :-
This creation routine checks that the argument is a valid extended regular expression and returns it if it is, otherwise the argument returned is an indicative error message.
create | ( |
inout | str : STR |
) : SAME |
This formal signature uses a tuple for the result, the implementation being required to set the string component of that as the inout argument.
create(arg : STR) res : [SAME] * STR
Since this is a creation routine, the pre-condition is vacuously true.
post let mk_(rexp,arg_out) = res in (rexp <> nil and arg_out = arg) or (res = nil and arg_out <> arg)
This routine creates a new regular expression pattern object unless an error has been detected, when void is returned and the string inout parameter is an error message indicating the problem.
This predicate returns true of the given string matches self. Note that if self and the string have different encodings then a match is identically false.
matches2(self : SAME, test_str : STR) res : BOOL
pre len test_str > 0
Since this routine is a predicate, the post-condition is vacuously true.
This predicate returns true if and only if the given string matches self.
This second variant of the matching predicate takes a string cursor, moving the cursor position to the end of the matched string if successful.
matches | ( |
test_cursor : STR_CURSOR | |
) : BOOL |
matches(self : SAME, test_cursor : STR_CURSOR) res : BOOL
pre not STR_CURSOR.is_done(test_cursor)
post (res and let head : seq of CHAR, match : seq of CHAR, tail : seq of CHAR be st head ^ matching ^ tail = test_cursor and len head = test_cursor(1, ..., STR_CURSOR.index(test_cursor~)) and len (head ^ matching) = test_cursor(1, ..., STR_CURSOR.index(test_cursor)) in match2(matching)) or (not res and STR_CURSOR.index(test_cursor~) = STR_CURSOR.index(test_cursor))
This predicate returns true if and only if self matches the test cursor, starting at the current buffer position. If a match is found, the cursor is positioned at the end of the longest matching string found.
![]() |
Language Index | ![]() |
Library Index | ![]() |
Text Index |
Comments
or enquiries should be made toKeith Hopper. Page last modified: Monday, 26 March 2001. |
![]() |