develooper Front page | perl.perl5.porters | Postings from May 2016

Re: [perl #128213] No deprecation warning on literal left curlybracket in /.{/ etc

Thread Previous | Thread Next
May 25, 2016 03:11
Re: [perl #128213] No deprecation warning on literal left curlybracket in /.{/ etc
Message ID:
On 25 May 2016 at 02:02, Zefram <> wrote:
> demerphq wrote:
>>I can understand forbidding quantifiers on an assertion, but not
>>allowing it if its wrapped.
> My point is that any forbidding of quantifiers on assertions should be a
> purely syntactic effect.  A quantifier is syntactically permitted on (?:),
> and must be allowed regardless of what is contained in the group.  If,
> instead, the forbidding of quantifiers were a semantic effect, we'd get
> into much woollier territory trying to define what semantically counts as
> an assertion.  (/^/ is, and you'd say that /(?:^)/ is; what about /^(?:)/
> or /^^/?)  It'd be much more difficult to define what's permitted in a way
> that's independent of the implementation (particularly of optimisation).
> Since quantifying an assertion is actually semantically meaningful,
> albeit a bit insipid, we'd also run into trouble with machine-generated
> or translated code.  Keeping the restriction purely syntactic avoids
> all of these problems.

My first reaction to this is "Ok, I get it, and oh BTW, bonus points
for using 'insipid' in a technical discussion".

My second reaction to this is that without a quantifier or alternation
(?:) is semantically invisible, and should that make a difference?


$ perl -Mre=debug -wle'qr/(?:a)bcd/'
Compiling REx "(?:a)bcd"
Final program:
   1: EXACT <abcd> (5)
   5: END (0)
anchored "abcd" at 0 (checking anchored isall) minlen 4
Freeing REx: "(?:a)bcd"

So I would expect /^*/ and /(?:^)*/ to produce the same compiled
optree, and the same errors.

But what you are saying is you would expect them to differ. Which I
guess is the difference between erroring at parse time, versus
optimization time.

But the difference makes me wonder a bit, because of things like this:

$ perl -Mre=debug -wle'qr/(?:a) */x'
Compiling REx "(?:a) *"
Final program:
   1: STAR (4)
   2:   EXACT <a> (0)
   4: END (0)
minlen 0
Freeing REx: "(?:a) *"

IOW, under /x we allow comments and whitespace to be inserted between
a construct and the quantifier. (I have argued in the past this is not
a good thing, but I lost the argument.).

So if we determine this at compile time I guess we have to do it
*after* we strip whitespace, but before we construct the optree.

Historically I have done everything I could to get us out of special
casing things based on the spelling of the pattern[1], and to instead
use the optree representation instead, so doing the opposite here
feels wrong. Although I am open minded about it.

[1] I hope this is the same as what you mean by "syntactically".

perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About