On Wed, 8 Dec 2004 08:19:17 -0800, Larry Wall <[EMAIL PROTECTED]> wrote:
>     / $<bar> := [ (<?ident>) = (\N+) ]* /

You know, to be honest I don't know that I want rules in one-liners to
capture by default. I certainly want them to capture in rules, though.

> 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.

I like it. It reads to me as "if before ...", "if null". Sounds good.

> I think I'm leaning toward the idea that anything in angles that
> begins alpha is a capture to just the alpha part, so the ? prefix is
> merely a no-op that happens to make the assertion not start with an
> alpha.  Interestingly, that gives these implicit bindings:
> 
>     <after ...>         $<after>        $`
>     <before ...>        $<before>       $'

Again, I don't see the utility of that in a one-liner. In a grammar,
you would create a real rule which would assert <after ...> and
capture the result in a reasonable name.

> Anyway, that's where I am this week/day/hour/minute/second.

I'm thinking capturing rules should be default in rules, where they're
downright useful. Your hour/minute/second comment brings up parsing
ISO time:

grammar ISO8601::DateTime {
    rule year { \d<4> }
    rule month { \d<2> }
    rule day { \d<2> }
    rule hour { \d<2> }
    rule minute { \d<2> }
    rule second { \d<2> }
    rule fraction { \d+ }

    rule date { <year> -? <month> -? <day> }
    rule time { <hour> \:? <minute> \:? <second> [\. <fraction>]? }
    rule datetime { <date> T <time> }
}

For a grammar, that works perfectly!

In a one-liner, I'd rather just use:

$datetime ~~ /$year := (\d+) -? $month := (\d+) -? ...../

and specify the vars I want to save directly in my own scope.

Ashley Winters

Reply via email to