On Wed, Feb 15, 2006 at 10:09:05AM +0100, H. Stelling wrote:
> - Capture numbering:
> 
> /(a) [ (b) (c) (d) | (e) & (f) ] (g)/ capture.t suggests something like
>  $0    $1  $2  $3    $1    $2    $4,  but I'm only guessing about the
> "&" bit.

Yes.


> In the following,
> 
> / (a) [ (b) (c) | $5 := (d) $0 := (e) ] (f) /
> 
> does the first alias have any effect on where the f's will go
> (probably not)?

I'll defer to @Larry on this one, but my initial impression is
that the (f) capture would go into $6.

> - Which rules do apply to repeated captures with the same alias? For
> example,
> the second array aliasing example
> 
> m:w/ Mr?s? @<names> := <ident> W\. @<names> := <ident>
>    | Mr?s? @<names> := <ident>
>    /;
> 
> seems to suggests that by using $<names>, the lower branch would have
> resulted in a single Match object instead of an array (like the array we
> would have gotten if we hadn't used the aliases in the first place). Is
> this right? 

Yes, that's correct.

> And could the same effect have been achieved by something
> like
> 
> / $<names> := <indent>**{1} / ?

Yes, a quantified capturing subrule or subpattern results in an
array of Match objects (even if the quantification is "1").

> - More array aliasing:
> 
> is                          / mv  @<files> := [...]*  /
> just (slightly) shorter for / mv [$<files> := [...]]* / ?

I think so.

> Likewise, could        /   @<pairs> := ( (\w+) \:             (\N+) )+ /
> have also been written / [ $<pairs> :=   (\w+) \: $<pairs> := (\N+) ]+ / ?

Seems like it would work.

> - Array and hash aliasing of quantified subpatterns or subrules: what
> happens
> to the named captures?
> 
> / @<foo> := ( ... $bar := (...) ... )* /

Presuming you meant $<bar> there instead of $bar, I have no idea
what would happen.  (With $bar it's an external alias and would
capture an array of matches into the scope in which the rule was
declared.)

> And if the subpattern or subrule ends with an alternation, can the
> number of
> array elements to be appended (or hashed) vary depending on whitch
> branch is
> taken?

Again I have to refer this to @Larry, but my initial impression is
"yes, it would vary".

> - Which of the following constructs could possibly be ok (I hope, none)?
> 
> / $<foo> := ... & $<foo> := ... /

I think this one is okay.  $<foo> is an array of Match objects, and
each Match is likely repeated within the array.

> / $<foo> := ...   %<foo> := ... /

I hope this is not okay.  It's certainly not going to be okay anytime
soon in the PGE implementation of Perl 6 rules.  :-)

> / $<foo> := ... | %<foo> := ... /

Since the two aliases are in separate alternation branches, I think
this is okay.  The argument would be similar to

    / $<foo> := ... | @<foo> := .../

in which $<foo> is either a single Match object or an array of
Match objects depending on the branch matched.

> / $<foo> := $<foo> := ... /

While my instinctual reaction is to say that this ought to be okay,
upon thinking about it a bit more I think I'd prefer to say that
it's not.  At least initially, if nothing else.  In particular, I 
wonder about something like

    / @<foo> := $<bar> := [...]+ /

If we say that an alias always requires a subpattern or subrule
(and not another alias), then we avoid a lot of ambiguity, and the
above could be written as

    / @<foo> := [ $<bar> := [...]+ ] /
    / @<foo> := [ $<bar> := [...] ]+ /

depending on what is desired.

> - Do aliases bind right-to-left, as do assignments?
> / $2 := $5 := ... /   # next should be $3, not $6

Assuming we allow chained aliases such as this (see above note),
I'd still argue for $6 instead of $3.

> - Which kind of escape sequences are allowed (or required) in enumerated
> character classes?

AFAIK, this hasn't been completely decided or specified yet.  

Pm

Reply via email to