【发布时间】:2020-07-13 11:08:04
【问题描述】:
我想在我的自定义俚语中重用 Perl6::Grammar 中的 token parameter 来添加“custom-param”参数无需货物培养。
我的意思:
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)
【问题讨论】:
-
也许更简单:我可以在
Match中转换NQPMatch对象吗?