How can a Perl 6 rule pass arguments to another rule?

brian d foy

In How can I pass arguments to a Perl 6 grammar? I passed an argument to a rule as part of a submerse. I was wondering how I'd do that completely inside a grammar. Suppose I had something like:

grammar TryIt {
    rule TOP            { \d+ <stuff> }
    rule stuff ($count) { <[ \S A..Z ]>{$count} }
    }

my $match = TryIt.parse: "123 ABCD";
say $match;

How do I pass an argument from TOP to stuff? I didn't find any examples and various guesses about parens near stuff didn't work.

smls

These forms both work:

<stuff(...)>
<stuff: ...>

Not sure where they're listed in the user documentation, but the S05: Regexes and Rules design document has a section on them.


Note that inside a rule, backreferences like $0 and $/ are only guaranteed to be available after a sequence point, e.g the opening brace of a block. An empty block {} works.

Example:

grammar TryIt {
    token TOP            { (\d+) \s {} <stuff($0)> .* }
    token stuff ($count) { <[ A..Z ]> ** {$count} }
}

say TryIt.subparse: "3 ABCDEFG";

Output:

「3 ABCDEFG」
 0 => 「3」
 stuff => 「ABC」

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I pass arguments to a make rule?

How can I run a pattern rule within another rule in a makefile?

How can I pass arguments to a Perl 6 grammar?

Pass an attribute and it's value from another rule to a rule in a request

How to pass parameters in Laravel Rule?

How can I create a custom bazel build rule that uses the runfiles path of another rule?

How can I access the output of a bazel rule from another rule without using a relative path?

How to create a rule from within another rule in Bazel

Another rule as argument to a rule in prolog

htaccess rule conflict with another rule

Conditional execution of one rule or another depending on the arguments given to a snakemake pipeline

Does .parse anchor or :sigspace first in a Perl 6 rule?

how to pass a class method as argument to another method of the class in perl 6

How can I create a rule to move meeting requests to another calendar as they are received?

How can I set PHPMD rule properties?

How can I turn a bad rule good?

How can I change a Squid rule in Sonar?

How can I debug a udev rule?

How can I conform to a 4 nest rule?

How can I query the attribute of a rule in bazel?

How can I remove an iptables rule?

How can I DRY this css rule

Set variable in a rule and have it available in another rule

Building bazel rule that depends on another rule

How can I pass arguments from one tab to another?

ANTLR 4 can't parse one rule similar to another

How can I pass a sequence as a parameter in Perl 6?

How do I setup a folder with a different rule and another folder with a different rule

How to pass arguments to another .py