我想在我的自定义俚语中重用token parameter
from Perl6::Grammar来添加“custom-param”参数而无需 cargo culting。
我的意思是说:
my $main-grammar = $*LANG.slang_grammar('MAIN');
my $main-actions = $*LANG.slang_actions('MAIN');
role Nogil::NogilGrammar {
token parameter { # the new one
"custom-param" || < here the token stolen from $main-grammar.^find_method('parameter'); >
}
my $grammar = $main-grammar.^mixin(Nogil::NogilGrammar);
my $actions = $main-actions.^mixin(Nogil::NogilActions);
$*LANG.define_slang('MAIN', $grammar, $actions);
不确定是否清楚:就像在角色的令牌中调用父令牌一样。我知道这个角色会覆盖它,所以我在$grammar
.
已经测试过:
- 将其定义为返回父匹配对象的方法,但出现以下错误:
P6opaque: no such attribute '$!pos' on type NQPMatch in a Scalar when trying to get a value
- 从正则表达式代码插值返回
Attempt to return outside of immediately-enclosing Routine (i.e. `return` execution is outside the dynamic scope of the Routine where `return` was used)