On Wed, Dec 08, 2004 at 08:19:17AM -0800, Larry Wall wrote:
> And people would have to get used to seeing ? as non-capturing assertions:
>     <?before ...>
>     <?after ...>
>     <?ws>
>     <?sp>
>     <?null>
> This has a rather Ruby-esque "I am a boolean" feeling to it.  I think
> I like it.  It's pretty easy to type, at least on my keyboard.

FWIW, for some reason in rule contexts I tend to conflate 
"I am a boolean" feelings with "zero-width assertion", so that each
of those look vaguely to me as though I'm testing a zero-width 
proposition and not consuming any text.  And I still tend to think of
'?' in it's "zero or one matches" or "minimal match" connotations.
Oh well, I suppose I could get used to that.

> Now suppose that we extend that "I am a boolean" feeling to
>     <?{ code }>
> which might take the place of the confusing <(...)>, and make consistent
> the notion that we always use {...} to invoke "real" code.

Hmm, this is nice, however.

> Another problem we've run into is naming if there are multiple assertions
> of the same name.  If the capture name is just the alpha part of the
> assertion, then we could allow an optional number, and still recognize
> it as a "ws":
>     <ws1> <ws2> <ws3>
> Except I can well imagine people wanting numbered rules.  Drat.  Could
> force people to say <ws_1> if they want that, I suppose.

I had been thinking that 

    /<ws> <foo> <ws> <bar>/

would simply cause $<ws> to be a list of captured elements, similar to 
what might happen for $1 in 

    / [ (.*?) , ]* /

If someone really needs the contents of the first and second <ws>, they
could do

   (<ws>) <foo> (<ws>)

and get them as $1 and $2.  But, seeing this tells me that perhaps
<(rule)> should be used for capturing rules, analogous to the
capturing parens, and leave <rule> to be the non-capturing version.
But maybe that's anti-Huffman overall.  Maybe the parens could also
help for disambiguating

   <(ws)> <foo> <(ws)>

so that we end up with $/<ws>[1], $/<ws>[2], etc.  But then we might
have to always subscript our named captures, which is icky, or maybe 
we'd only make $/<ws> act like list when there's more than one 
capturing <(ws)> in the rule.

I dunno.  I kinda like <(rule)> for capturing, but maybe it just
doesn't work.

Pm

Reply via email to