...或者如何从匹配的文本$<sigil>.Str
中独立地更改值。是的,我在问如何欺骗上面的语法(即打电话给我)。token sigil { ... }
我正在尝试为没有 sigil 的 Raku 写一个俚语。
所以我想要nogil
令牌,匹配任何东西<?>
以返回字符串化的 NqpMatch:$<sigil>.Str
到'$'。
目前,我的令牌印记看起来像这样
token sigil {
| <[$@%&]>
| <nogil> { say "Nogil returned: ", lk($/, 'nogil').Str; # Here It should print "$"
}
}
token nogil-proxy {
| '€'
| <?>
{log "No sigil:", get-stack; }
}
并且该方法应该返回一个被覆盖的NQPMatch
方法Str
method nogil {
my $cursor := self.nogil-proxy;
# .. This si where Nqp expertise would be nice
say "string is:", $cursor.Str; # here also it should print "$"
return $cursor;
}
尝试失败:
$cursor.^cache_add('Str', sub { return '$'; } );
$cursor.^publish_method_cache;
for $cursor.^attributes { .name.say };
for $cursor.^methods { .name.say };
say $cursor.WHAT.Str;
nqp::setmethcacheauth($cursor, 0);
目前,我的大部分测试都有效,但我在没有我的 (with no strict
)的情况下在声明中遇到问题,my-var = 42;
因为它们被视为方法调用。
@Arne-Sommer 已经发表了一篇文章和一篇文章。这是密切相关的。但这个问题的目的是:
我们如何自定义编译时令牌的返回值,而不是如何声明它。