Jonathan Scott Duff wrote:

> > > rule val {
> > >     [   # quoted
> > >        $b := <['"]>
> > >        ( [ \\. | . ]*? )
> > >        $b
> > >     ] | # or not
> > >        (\H+)
> > > }
> >
> > Not quite. Assigning to $b is a capture.
> 
> I'm confused. The examples in A5 all show $var := (pattern). So are you
> saying that parens or no, binding with := affects a capture into
> $1,$2,etc.? Or that it affects a capture that alters the return value
> of the rule, just not $1,$2,etc.?

The latter.


> So ... should this work?
> 
>         rule quote      { <["']> }
>         rule quotedword { <quote> (<alpha>+) $quote }
>         $justtheword = /<quotedword>/;

My understanding is that it won't just return the word. If you invoke a named rule, 
its return value is captured in a hypothetical variable of the same name (but *not* 
into a numbered hypovar -- only parens do that). The named hypovar lives inside the 
object that is ultimately returned to the next level up.

So C<rule quote> returns (what appears to be) a simple string to C<rule quotedword>, 
but -- because of the captures it does -- C<rule quotedword> returns an object with 
embedded C<$quote> and C<$alpha> hypovars.


> And if the above works, why can't "$var:=atom" be a short hand for a
> lexical "rule var { atom }" that only applies for the current ... um ...
> rule/<insert more appropriate word>? And thus the capture would be out
> of band WRT $1, $2, etc. or the rule's return value.

As explained above, named captures *are* out-of-band wrt $1, $2, etc. 
Just not wrt to the return value.

As I mentioned in a previous post, the issue is how to control what a given
(sub-)rule returns (i.e. all its explicit and captures, or just a specific
result). I think the correct answer is to control that explicitly, via a 
<return...> assertion or a $RETURN:= capture.

Damian

Reply via email to