Front page | perl.perl6.language |
Postings from May 2005
Re: C<::> in rules
From: Patrick R. Michaud
May 12, 2005 10:44
Re: C<::> in rules
Message ID: 20050512174455.GB23748@pmichaud.com
On Thu, May 12, 2005 at 12:53:46PM -0400, Aaron Sherman wrote:
> My take, based on S05:
> > In other words, it acts as though one had written
> > $rule = rx :w / plane ::: (\d+) | train ::: (\w+) | auto ::: (\S+) / ;
> > and not
> > $rule = rx :w /[ plane :: (\d+) | train :: (\w+) | auto :: (\S+) ]/ ;
> Your two examples fail in the same way because of the fact that the
> group IS the whole rule.
False. In the first case the group is the whole rule. In the second
case the group would not include the (implied) '.*?' at the start of
the rule. Perhaps it helps to see the difference if I write it this way:
$rule = rx :w /<null>[ plane :: (\d+) | train :: (\w+) | auto :: (\S+) ]/;
Note that the rule is *unanchored*, thus it tries at the first character,
if it fails then it goes to the second character, if that fails it goes
to the third, etc. Thus, given:
$rule1 = rx :w / plane ::: (\d+) | train ::: (\w+) | auto ::: (\S+) / ;
$rule2 = rx :w /<null>[ plane :: (\d+) | train :: (\w+) | auto :: (\S+) ]/ ;
"travel by plane jet train tgv today" ~~ $rule1; # fails
"travel by plane jet train tgv today" ~~ $rule2; # matches "train tgv"
They're not equivalent.
> > Next on my list, S05 says "It is illegal to use :: outside of
> > an alternation", but A05 has
> > /[:w::foo bar]/
> I can't even figure out what that means. :w turns on word mode
> (lexically scoped per S05) and "::" is a group-level commit. What are we
> committing exactly? Looks like a noop to me, which actually might not be
> so bad.
Yes, the point is that it's a no-op, because
is something entirely different.
> > /[:w\bfoo bar]/ # not exactly the same as above
> No, I think that's exactly the same.
$foo = rx /[:w::foo bar]/
$baz = rx /[:w\bfoo bar]/
"myfoo bar" ~~ $foo # matches
"myfoo bar" ~~ $baz # fails, foo is not on a word boundary