According to the documentation, you can redefine the ws
token in a grammar, this token is called automatically in some cases, such as this:
grammar Numbers { rule TOP { \d \d } };
my $result = Numbers.parse("3 \n 3");
say $result.perl
# OUTPUT: «Match.new(pos => 5, made => Any, from => 0, hash => Map.new(()), orig => "3 \n 3", list => ())»
One of the advantages of redefining ws
might be that it will not be thrown away. OK, I'll buy that and use for ws
the exact same definition that is used internally:
grammar Numbers { rule TOP { \d \d }; regex ws { <!ww> \s* } };
my $result = Numbers.parse("3 \n 3");
say $result<ws> # OUTPUT: «Nil»
Matching works, but $result is still dropped (redefining this to another token that does not use the default ws will work). So is ws
dropped always?
Update This is probably related to this Rakudo bug