Perl 6 规则如何将参数传递给另一个规则?

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

中,我将参数作为潜入的一部分传递给规则。我想知道如何在语法中完全做到这一点。假设我有类似的东西:

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

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

如何将参数从 TOP 传递到 stuff?我没有找到任何例子,关于 parens near stuff 的各种猜测都没有用。

这些表格都有效:

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

不确定它们在用户文档中的什么位置,但是 S05:正则表达式和规则 设计文档 has a section on them.


请注意,在规则内,像 [=14=]$/ 这样的反向引用只能保证在序列点之后可用,例如块的左大括号。空块 {} 有效。

示例:

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

say TryIt.subparse: "3 ABCDEFG";

输出:

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