gpt4 book ai didi

grammar - 使用 $/与在语法操作中使用任何其他变量并不完全相同

转载 作者:行者123 更新时间:2023-12-02 12:04:03 27 4
gpt4 key购买 nike

理论上,并且according to the documentation ,您可以在语法操作中使用方法的任何参数。

grammar G {
token TOP { \w+ }
}

class Action-Arg {
method TOP ($match) { $match.make: ~$match }
}

class Action {
method TOP ($/) { make ~$/ }
}

class Action-Fails {
method TOP ($match) { make ~$match }
}

say G.parse( "zipi", actions => Action-Arg );
say G.parse( "zape", actions => Action );
say G.parse( "pantuflo", actions => Action-Fails );

但是,前两个版本可以按预期工作。但是第三个(这将是第二个的直接翻译)失败了

Cannot bind attributes in a Nil type object
in method TOP at match-and-match.p6 line 19
in regex TOP at match-and-match.p6 line 7
in block <unit> at match-and-match.p6 line 24

可能存在一些特殊的语法(从 make 的意义上来说,可能实际上是 $/.make),但我想澄清一下这是否符合规范或者是一个错误。

最佳答案

这是因为 make 子例程是 Rakudo 中罕见的情况之一,它实际上尝试从调用它的范围访问 $/ 变量。这也是它的记录方式:

The sub form operates on the current $/

(来自 the documentation )

关于grammar - 使用 $/与在语法操作中使用任何其他变量并不完全相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56833809/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com