Although the docs state that calling a token/rule/regex as <.foo>
instead of <foo>
makes them non-capturing, it seems there is a difference in scope, but I'm not sure if it's intended.
Here is a simplified test. In a module file:
unit module Foo;
my token y { y }
my token a is export { x <y> }
my token b is export { x <.y> }
Inside of another script file:
grammar A {
use Foo;
token TOP { <a> }
}
grammar B {
use Foo;
token TOP { <b> }
}
If we calling A.parse("xy")
everything runs as expected. However, calling B.parse("xy")
results in the error No such method 'y' for invocant of type 'B'
. Is this expected behavior or a potential bug?
The intention per S05
The intention according to the relevant speculation/design doc includes:
Examples of forms
<bar>
is as explained above. It preferentially resolves to an early bound lexical (my
/our
) routine/rule named&bar
. Otherwise it resolves to a late bound attempt to call a has (has
) method/rule namedbar
. If it succeeds it stores the match under a capture namedbar
.<.bar>
calls a has (has
) method/rule namedbar
if it finds one. It does not capture.<bar=.bar>
calls a has (has
) method/rule namedbar
if it finds one. If it succeeds it stores the match under a capture namedbar
. In other words, it's the same as<bar>
except it only attempts to call a has method named.bar
; it doesn't first attempt to resolve to a lexical&bar
.<&bar>
and<.&bar>
mean the same thing. They call a lexical routine named&bar
and do not capture. To do the same thing, but capture, use<bar=&bar>
or<bar=.&bar>
.(If you read the speculation/design doc linked above and try things, you'll find most of the design details that doc mentions have already been implemented in Rakudo even if they're not officially supported/roasted/documented.)
Scope examples
First the common case:
displays:
(The
has
declarators are optional and it's idiomatic to exclude them.)Now introducing a rule lexically scoped to the grammar block:
displays:
Even a lexical rule declared outside the grammar block has precedence over has rules:
displays: