在语法动作代码中替换怪异的“ p6opaque”错误

发布于 2025-01-17 11:51:00 字数 588 浏览 4 评论 0原文

我有此操作,该操作覆盖了另一个动作类中的动作:

        method taskwiki-prefix($/ is copy) {
            my $prefix = $/.Str;
            $prefix ~~ s:g!'|'!!;
            make $prefix;
        }

替换会引发此错误:

,在列表中的类型匹配中没有此类属性'$!

p6opaque:在尝试绑定值时 评论替代,错误消失了。 dd $ prefix显示:

str $ prefix =“任务||”

所以它只是一个普通的字符串。

如果我删除:g副词,则不再错误,但是这样做会导致nil,并且在输出中没有任何内容显示$< task; task; taskwiki-前缀> .made

在我看来,如果我猜想,替代和动作中的比赛和动作的比赛发生了一些不良的互动。

有修复吗?

I have this action which overrides an action in another action class:

        method taskwiki-prefix($/ is copy) {
            my $prefix = $/.Str;
            $prefix ~~ s:g!'|'!!;
            make $prefix;
        }

The substitution throws this error:

P6opaque: no such attribute '$!made' on type Match in a List when trying to bind a value

If I comment out the substitution, the error goes away. dd $prefix shows:

Str $prefix = " Tasks ||"

So it's just a plain string.

If I remove the :g adverb, no more error, but doing that makes the made value Nil and nothing shows up in the output for $<taskwiki-prefix>.made.

Looks to me like there is some bad interaction going on with the matches in the substitution and the action, if I were to guess.

Any fix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天冷不及心凉 2025-01-24 11:51:00

This is another case of your previous question,

替换更新$/和:

  • 的情况下:g副词,list最终以$/和make会感到困惑。我提出了改进的错误
  • 对于NO :G,在$/中有一个Match>,它已连接到此 - 但是,它不再是<代码>匹配被传递到我建议的方法中的对象

  1. 始终具有您的操作方法的签名为($/),因此对的目标没有混淆制作
  2. 在可能的情况下,避免重新计算(这是您自己答案中提到的解决方案)。
  3. 如果您无法避免在操作方法中进行其他匹配或替换,请将它们放入sub或私有方法而不是将其放入。

This is another case of your previous question, Raku grammar action throwing "Cannot bind attributes in a Nil type object. Did you forget a '.new'?" error when using "make". As there, the make function wants to update the $/ currently in scope.

Substitutions update $/, and:

  • In the case of the :g adverb, a List ends up in $/, and make gets confused. I've proposed an improved error.
  • In the case of no :g, there is a Match in $/ and it is attached to that - however, it's no longer the Match object that was passed into the method

I recommend to:

  1. Always have the signature of your action methods be ($/), so there's no confusion about the target of make.
  2. When possible, avoid reparsing (which was the achieved solution mentioned in your own answer).
  3. If you can't avoid doing other matches or substitutions in your action method, put them in a sub or private method instead and then call it.
奢望 2025-01-24 11:51:00

通过更改语法以提供更清晰的输出来解决问题,这样我就不必操作 $/ 变量。

Problem was solved by changing the the grammar to give me a cleaner output so I did not have to manipulate the $/ variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文