Gordon Henriksen wrote:
> 
> Benjamin Goldberg wrote:
> 
> > Gordon Henriksen wrote:
[snip]
> > > [3] Unshift hack #1: Where commit appears in the above, exit the
> > > grammar, trim the beginning of the string, and re-enter. (But that
> > > forces the grammar author to discard the regex state, whereas commit
> > > would offer no such restriction.) Unshift hack #2: Tell =~ that
> > > <commit> can trim the beginning of the string. (DWIM departs;
> > > /cgxism returns.)
> >
> > Trimming off the beginning of the string is the job of the <cut>
> > operator, not the <commit> operator.
> 
> Indeed, my bad--been a while since I read the apocalypse.
> 
> > Hmm... I wonder how <cut> would be done with an iterator.  Bleh.
> 
> Equivalent to <commit>, I say....

Not necessarily.  I mean, consider if someone does:

   my @ary := unpack "U*", $string;

Then, doing:

   @ary =~ /regex/

And:

   $string =~ /regex/

*Should* be equivilant, ne?

And a <cut> on the string should trim the front of the string, and a
<cut> on the array should splice of the front of the array.

Maybe we should provide some vtable entries for altering a pmc through
an iterator, so that that <cut> could say:

   VTABLE_trim_front_keyed(INTERP, pmc, key);

> Then your grammar rule can work on an
> iterator, or on a string that's being used as a buffer.
> 
> Here's a question: How does $iter =~ /a+b/ work on an iterator which
> returns "aaaaaaack!"? Requires a putback op.

Have you read how perl6's regex engine works?

> I'm not sure about <cut> vs. <commit>. They seem so orthogonal, and they
> pervasively tie a grammar to an implementation choice. It seems more
> like an m:option.

They are orthogonal:  A <commit> says, throw away the backtracking stack
before this point, because if we *try* to backtrack before here, then
the entire match fails.  A <cut> says, throw away the backtracking
stack, *AND* throw away the front of the string/aggregate we're matching
against.

However, I'm not so sure that they tie a grammar to a choice: if we
provide an interface to trim off the "front" of an aggregate using an
iterator, (and we can already trim off the front of a string, using
string_replace), then we have both <commit> and <cut> with both.

Of course, it's quite possible that some pmc classes won't *provide* a
method for trimming itself, in which case <cut> will throw an exception.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "[EMAIL PROTECTED]
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}

Reply via email to