How to pass params to token referenced by variable?

Either:

  • Use the solution in jnthn's answer to let Raku explicitly know you wish to use your $ sigil'd token variable as a Callable.

  • Declare the variable as explicitly being Callable in the first place and make the corresponding change in the call:

my &t = token ( $x ) { $x };

say 'axb' ~~ / 'a' <&t: 'x'> 'b' /;   # 「axb」
say 'axb' ~~ / 'a' <&t( 'x' )> 'b' /; # 「axb」

Place an & before the variable:

my $t = token ( $x ) { $x };
say 'axb' ~~ / 'a' <&$t: 'x'> 'b' /;
say 'axb' ~~ / 'a' <&$t( 'x' )> 'b' /;

The parser looks for the &, and then delegates to the Raku variable parse rule, which will happily parse a contextualizer like this.

Tags:

Raku