相关疑难解决方法(0)

Perl 6 / Raku中捕获和不捕获正则表达式作用域的差异

尽管文档指出将令牌/规则/正则表达式作为<.foo>代替而不是<foo>使其不被捕获,但似乎范围有所不同,但我不确定是否打算这样做。

这是一个简化的测试。在模块文件中:

unit module Foo;
my token y           {     y  }
my token a is export { x  <y> }
my token b is export { x <.y> }
Run Code Online (Sandbox Code Playgroud)

在另一个脚本文件中:

grammar A {
  use Foo;
  token TOP { <a> }
}

grammar B {
  use Foo;
  token TOP { <b> }
}
Run Code Online (Sandbox Code Playgroud)

如果我们打电话,A.parse("xy")一切都会按预期运行。但是,调用会B.parse("xy")导致错误No such method 'y' for invocant of type 'B'。这是预期的行为还是潜在的错误?

regex grammar module perl6 raku

5
推荐指数
1
解决办法
96
查看次数

标签 统计

grammar ×1

module ×1

perl6 ×1

raku ×1

regex ×1