|
From: <per...@li...> - 2006-02-24 18:42:15
|
Update of /cvsroot/perl-flat/blokhead/lib/FLAT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27297/lib/FLAT Modified Files: Regex.pm Log Message: - updates to regex ops (especially handling extended [] characters) - added more regex tests - anchoring option to as_perl_regex - "contains" method for regexes (just pass off regex matching to perl ;)) Index: Regex.pm =================================================================== RCS file: /cvsroot/perl-flat/blokhead/lib/FLAT/Regex.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Regex.pm 24 Feb 2006 06:20:25 -0000 1.4 --- Regex.pm 24 Feb 2006 18:42:09 -0000 1.5 *************** *** 37,41 **** sub as_perl_regex { ! "(?:" . $_[0]->op->as_perl_regex(0) . ")"; } --- 37,49 ---- sub as_perl_regex { ! my ($self, %opts) = @_; ! ! my $fmt = $opts{anchored} ? '(?:\A%s\z)' : '(?:%s)'; ! return sprintf $fmt, $self->op->as_perl_regex(0); ! } ! ! sub contains { ! my ($self, $string) = @_; ! $string =~ $self->as_perl_regex(anchored => 1); } *************** *** 138,141 **** --- 146,152 ---- literal square bracket characters is currently not supported. + The expression "" (or any string containing only whitespace) is not a valid + FLAT regex expression. Either C<[]> or C<#> are probably what was intended. + =item $regex-E<gt>as_string *************** *** 145,167 **** FLAT::Regex->new($string)->as_string ! is the same as $string, especially if $string contains unneeded whitespace ! or redundant parentheses. =item $regex-E<gt>as_perl_regex ! Returns an equivalent Perl regular expression. The Perl regex will NOT be ! anchored to the beginning and end of the string. In particular this means ! that ! ! $string =~ $regex->as_perl_regex ! ! and ! ! $regex->contains($string) ! may not be equivalent. The Perl regex will not contain capturing parentheses. "Extended" characters ! that are written as "[stuff]" in FLAT regexes will be written without the square brackets in the corresponding Perl regex. So the following: --- 156,172 ---- FLAT::Regex->new($string)->as_string ! is identical to $string, especially if $string contains whitespace or ! redundant parentheses. =item $regex-E<gt>as_perl_regex ! =item $regex-E<gt>as_perl_regex(anchored => $bool); ! Returns an equivalent Perl regular expression. If the "anchored" option ! is set to a true value, the regular expression will be anchored with ! C<\A> and C<\z>. The default behavior is to omit the anchors. The Perl regex will not contain capturing parentheses. "Extended" characters ! that are written as "[char]" in FLAT regexes will be written without the square brackets in the corresponding Perl regex. So the following: *************** *** 169,171 **** --- 174,177 ---- will be equal to "(?:foo(?:bar)*)". + =back |