从理论上讲,根据文档,您可以在语法操作中为方法使用任何参数。
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 );
Run Code Online (Sandbox Code Playgroud)
但是,两个第一个版本按预期工作。但是第三个(将是第二个的直接翻译)以
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
Run Code Online (Sandbox Code Playgroud)
可能存在一些特殊的语法(make实际上$/.make可能是在某种意义上),但是我只是想澄清一下这是否符合规范或是一个错误。
| 归档时间: |
|
| 查看次数: |
93 次 |
| 最近记录: |