Ashley Winters writes:
> 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!

Yep. 

> In a one-liner, I'd rather just use:
> 
> $datetime ~~ /$year := (\d+) -? $month := (\d+) -? ...../

Then go ahead and use that.  If you're going to use subrules, you can
either use the <?subrule> form or just the regular old <subrule> form
and ignore the result.  There's nothing forcing you to pay attention to
those.  The number variables only get incremented when you use
parentheses.  I'd suspect that the return value of a rule only accounts
for parenthecized captures as well.

Or are you asking something different than that?

Luke

Reply via email to