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

Re: comprehensive list of perl6 rule tokens

Thread Previous | Thread Next
From:
Patrick R. Michaud
Date:
June 1, 2005 22:51
Subject:
Re: comprehensive list of perl6 rule tokens
Message ID:
20050602055150.GA7874@pmichaud.com
On Thu, Jun 02, 2005 at 12:52:36AM -0400, Jeff 'japhy' Pinyan wrote:
> Further woes, arguments, questions:
> 
> In regards to <@array>, A5 says "A leading @ matches like a bare array..." 
> but this is an over-generalization.  A leading '@' merely indicates the 
> rule is found in an array.  <@array[3]> would be the same as 
> <$fourth_element_of_array>, assuming those two values are identical.

I'll leave this to the A05 authors to decide.  :-)  S05 doesn't
present any examples of subscripted rules or hashes, so perhaps
that particular syntax was reconsidered (i.e., I think one could
do <{ @array[3] }>).  

> Next, about <before RULE> and <after RULE>.  What is the justification for 
> that syntax?  There is no other example of a <-sequence with whitespace, 
> at least that I can see.  It would appear "RULE" is an argument of sorts 
> to the 'before' and 'after' rules, but how do they access that argument? 
> How do I write a rule that takes an argument?

According to A05, rules take arguments much the same way that
subs do.  (In fact, it's *very* useful to think of rules as subs or
methods.)  So, one can do:

   rule myrule ($x) { \w+ $x }

and $x is scoped something like a subroutine parameter would be.

A05 also mentions several mechanisms for passing parameters to
a rule:

   <myrule pattern>     # same as calling myrule(/pattern/)
   <myrule: text>       # same as calling myrule(q<text>)
   <myrule(expr)>       # same as calling myrule(expr)

Of course, there are other "implicit" parameters that are given
to a rule -- the target string to be matched and an initial
starting position.  But I think some of those details are still 
being worked out.  

Pm

Thread Previous | 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