From S05:

If a subrule appears two (or more) times in any branch of a lexical
scope (i.e. twice within the same subpattern and alternation), or if the
subrule is quantified anywhere within a given scope, then its
corresponding hash entry is always assigned an array of
C<Match> objects rather than a single C<Match> object.

However, fglock and I both find the "quantified" clause very surprising.
Intuitively:

    /<foo>  bar bar <foo>/

should set $<foo> to an Array with two Match elements.  However:

  /<foo>+/

should set $<foo> to a single Match, with multiple positional Match elements, each
one representing one match in the quantified match.  Moreover:

   /<foo> bar bar <foo>+/

should set $<foo> to an Array with two Match elements, the first being a
simple match, and the second has multiple positional submatches.

The thinking behind the separate treatment is that in a contiguous quantified match, it does make sense to ask the .from and .to for the entire range, which is very hard to do if it's an Array (which can have 0 elements, rendering $<foo>[-1].to dangerous). Also stringification for $<foo> on a /<foo>+/ match should perhaps not be space-separated, i.e. it should follow Match semantics not Array semantics.

To recap: Is it possible to amend the quantified clause to have it produce Match
objects, and reserve Array only for noncontiguous same-named subrules?

Thanks,
Audrey

Reply via email to