develooper Front page | perl.perl6.compiler | Postings from December 2004

Re: PGE tests wanted (was P6GE tests wanted)

Thread Previous | Thread Next
From:
hv
Date:
December 18, 2004 11:02
Subject:
Re: PGE tests wanted (was P6GE tests wanted)
Message ID:
200412181907.iBIJ7Ab21219@zen.crypt.org
Larry Wall <larry@wall.org> wrote:
:Henry Spencer's original regex routines simply disallowed expressions
:that might be infinite.  We tried relaxing that in Perl 5, and got
:it wrong more than one way.  I'm not actually sure what approach p5
:takes right now, if any.

We detect and warn of repeated empty expressions:
  zen% perl -wle 'print "ok" if "x" =~ /()*/'/'
  ()* matches null string many times in regex; marked by <-- HERE in m/()* <-- HERE / at -e line 1.
  ok
  zen% 

For optionally empty expressions, we don't allow them to match emptily
more than once:
  zen% perl -wle 'while ("baa" =~ /((b??)*a)/g) { print "<$1>" }'
  <ba>
  <a>
  zen% 

For optionally empty patterns, we don't allow them to match emptily at
the same location more than once:
  zen% perl -wle 'while ("a" =~ /(a??)/g) { print "<$1>" }'
  <>
  <a>
  <>
  zen% 

This last is achieved by magic on the string to which the pattern is
applied, which can lead to problematic interactions with other magic
(eg tainting) or restoration after local(). In principle it may also
be undesirable if you are parsing a string with a variety of //gc
patterns, and want to allow more than one of them to match an empty
string at the same location.

Hugo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About