Patrick R. Michaud wrote:
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.
I think that sequences should behave exactly as single branch
alternations (only that there is no such thing, although we
can write "[foo|<fail>]"). So I would rather opt for $1.
- 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.
But wouldn't it be nice if the same rules applied to aliases and
subrule invocations, that is, recursion put aside, to think of
/ <foo> /
simply as a shorter way to say
/ $<foo> := ([definition of foo]:) /?
And I've got two more somewhat related questions:
The synopsis says:
* If a subrule appears two (or more) times in the same lexical scope
(i.e. twice within the same subpattern and alternation), or if the
subrule is quantified anywhere within the entire rule, then its
corresponding hash entry is always assigned a reference to an array
of Match objects, rather than a single Match object.
Maybe you're not the right person to ask, but is there a particular
reason for the "entire rule" bit?
/ (<foo>|None) <foo> (<foo>) /
Here we get three Matches $0<foo> (possibly undefined), $<foo>, and
$1<foo>. At least, I think so.
/ (<foo>?) <foo> (<foo>) /
Now, we suddenly get three more or less unrelated arrays with lengths
0..1, 1, and 1. Of course, I admit this example is a bit artificial.
Furthermore, I think "within the same subpattern and alternation" is
not quite correct, at least it wouldn't apply to somethink like
/ (<foo> [ <foo> | ... ]) /
unless we consider the (...) sequence as a kind of single branch
alternation. And why are alternation branches considered to be
lexical scopes, anyway? Just because of subpattern numbering?
My second question is why adding a "?" or "??" to an unquantified
subrule which would otherwise result in a single Match object should
result in an array, rather than a single (possibly undefined) Match.
That is, why doesn't "<foo>?" rather behave like "[<foo>|<null>]"?
This would save us the trouble to create all these tiny arrays, or
having to write "[...|<null>]" all the time. Or maybe one could
define one's own quantifiers?