Front page | perl.perl6.language |
Postings from May 2005
Re: C<::> in rules
From: Luke Palmer
May 13, 2005 08:04
Re: C<::> in rules
Message ID: firstname.lastname@example.org
On 5/12/05, Patrick R. Michaud <email@example.com> wrote:
> I have a couple of questions regarding C< :: > in perl 6 rules.
> First, a question of verification -- in
> $rule = rx :w / plane :: (\d+) | train :: (\w+) | auto :: (\S+) / ;
> "travel by plane jet train tgv today" ~~ $rule
> I think the match should fail outright, as opposed to matching "train tgv".
> 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+) ]/ ;
Those both do the same thing (which is the same as your example).
When you fail over the :: after plane, it skips out of the alternation
looking for something to backtrack before it. Since there is nothing,
the rule fails.
> Does this sound right?
> Next on my list, S05 says "It is illegal to use :: outside of
> an alternation", but A05 has
> /[:w::foo bar]/
> which leads me to believe that :: isn't illegal here even though there's
> no alternation. I'd like to strike that sentence from S05
Yeah, I think using :: to break out of the innermost bracketing group
is helpful even without an alternation present.
> Also, A05 proposes incorrect alternatives to the above
> /[:wfoo bar]/ # null pattern illegal, use <null>
> /[:w()foo bar]/ # null capture illegal, and probably undesirable
> /[:w\bfoo bar]/ # not exactly the same as above
> I'd like to remove those from A05, or at least put an "Update:"
> note there that doesn't lead people astray. One option not
> mentioned in A05 that we can add there is
> /[:w<?null>foo bar]/
> which is admittedly ugly.
> So, now then, on to the item that got me here in the first place.
> The upshot of all of the above is that
> rx :w /foo bar/
> is not equivalent to
> rx /:w::foo bar/
Yeah, but it is. So no problem. :-)
> which may surprise a few people. The :: at the beginning of
> the pattern effectively anchors the match to the beginning of
> the string or the current position -- i.e., it eliminates the
> implicit C< .*? > at the start of the match.
Ohhh, ohh. There isn't an implicit .*? at the beginning of the match.
It's more like there's an implicit .*? followed by a rule call to the
match. Think of it as that we're trying to match the pattern at any
position rather than there being an implicit .*?.