develooper Front page | perl.perl6.language | Postings from May 2005

C<::> in rules

Thread Next
From:
Patrick R. Michaud
Date:
May 12, 2005 07:33
Subject:
C<::> in rules
Message ID:
20050512143337.GB18528@pmichaud.com
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+) ]/ ;

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.

Also, A05 proposes incorrect alternatives to the above 

    /[:w[]foo 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/

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.  To put the :w
inside the rule (e.g., in a variable or subrule), one would
have to write it as

    rx /[:w::foo bar]/
    rx /:w<null>foo bar/

Now then, I don't have a problem at all with this outcome -- 
but I wanted to let p6l verify my interpretation of things and
make sure it's okay for me to adjust S05/A05 accordingly.

Pm

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About