Patrick R. Michaud wrote:
On Tue, Mar 01, 2005 at 09:32:28PM -0800, Larry Wall wrote:
On Tue, Mar 01, 2005 at 11:06:17PM -0600, Rod Adams wrote:
: Since the line between rules and subs is already blurring significantly, : I want to blur it a little more. I want to write rules which can take : parameters.
No problem. That's how the arguments to rules like <before foo> are
already passed. If I recall, we originally specified three basic forms:
<foo bar> # bar is pattern
<foo: bar> # bar is string
<foo(bar)> # bar is Perl expression
Yes, this is written in A05, although it's often hard to spot and easy to overlook. They're in the large table under "Metacharacter reform":
<name(expr)> # call rule, passing Perl args { .name(expr) } # same thing.
<$var(expr)> # call rule indirectly by name { .$var(expr) } # same thing.
<name pat> # call rule, passing regex arg { .name(/pat/) } # same thing.
# maybe... <name: text> # call rule, passing string { .name(q<text>) } # same thing.
The argument form of subrules is not currently mentioned in S05.
I've been designing and implementing PGE consistent with the
above syntaxes.
Thanks for pointing that out, Patrick. I'm impressed with how you've assimilated all the S's & A's. (And yes, I love that the guy in charge of implementing the language has that ability.)
And now some questions to hammer out some details on passing args to subrules:
What if you wish to pass two args, the first a string, the second a rule? Are you then forced to use <name(expr, expr)> syntax?
Does <name: text1 text2> get handled as <name(q<text1 text2>)> or as <name(q<text1>, q<text2>)>, in which case it's really qw//?
If I declare my rule as:
rule MyRule (Str $text) { ... }
Will the P6RE be smart enough to pass:
m:{<MyRule /thisdir/>}
As a string, not the rule that it looks like?
If I define a named rule, how do I get a reference to it from outside a rule?
A05 leads me to think that
my $rx := Rule.MyRule;
will work, assuming Rule is the default gramme. I would also suspect that one could reverse this.
my $rx = rule { ... }; Rule.MyRule := $rx;
Thus defining a new rule dynamically.
-- Rod Adams