Briefly:你必须改变$!target
的字符串ParseShared
nqp 对象,这会在解析时更改代码。
Why:
The sigil
令牌不再是原型,而是已定义的rakudo/src/Perl6/Grammar.nqp https://github.com/rakudo/rakudo/blob/aa5154e02783c7e1a4c5f7a210f622d1908eef31/src/Perl6/Grammar.nqp#L1840作为交替。
所以作为一个最小的解决方案:token sigil { <[$@%&€]> }
但新的问题来了:返回值可以是€
并用于其他语法中。
Where:所以你必须改变$<sigil>.Str
定义于nqp/src/QRegex/Cursor.nqp https://github.com/Raku/nqp/blob/57a4d5eacbb7da72e68c08da99d6bfe86cab0506/src/QRegex/Cursor.nqp#L90 as:
method Str() {
$!pos >= $!from
?? nqp::substr(nqp::getattr_s($!shared, ParseShared, '$!target'),
$!from, nqp::sub_i(self.to, $!from))
!! '' }
The string in target between from and to if pos is not so low.
-> 所以我们必须改变$!target
之间$!from
and $!to
in a NQPMatch
.
Demo:以下是嵌入俚语语法的代码:
token sigil {
| <[$@%&]>
| <nogil> { say "Nogil returned: ", lk($/, 'nogil').Str; }
}
method nogil {
# The object to return
my $cursor := self.nogil-proxy;
# Get from cursor
my $shared := nqp::getattr($cursor, NQPMatch, '$!shared');
my $from = nqp::getattr_i($cursor, NQPMatch, '$!from');
my $target = $cursor.target;
# Replace in target current character (€) by $
$target.substr-rw($from, 1) = '$';
# Set in cursor
nqp::bindattr_s($shared, $shared.WHAT, '$!target', $target);
# Return the "created by proxy" and modified NQPMatch
return $cursor;
}
token nogil-proxy { '€' }
单独说:_它应该适合您的情况。在我的中,(没有印记)我仍然有问题,因为尺寸在$!target
修改搞乱了to
and from
其他光标。在这种情况下:
- I must 覆盖NQPMatch.Str函数 https://stackoverflow.com/posts/60982963(希望这是可能的)。
- 我必须列出光标(如果可能)并更改它们
$!from
and $!to
明智地归因以恢复银河系的和平或至少在客户端代码中恢复和平。