I am debugging a larger grammar, and was able to reduce the error to the following minimal example:
#! /usr/bin/env perl6
use v6;
my $str = q:to/END/;
bar baz, bak
END
class Actions {
method arg-separator ($match-data) {
my $match-str = $match-data.Str;
if $match-str ~~ /^ \s+ $/ {
make ", ";
}
else {
make $match-str;
}
}
}
grammar Simple-Grammar {
token TOP { ^ \s* [[<argument> <arg-separator>]* <argument>] \s* $ }
token argument {
[<!before <arg-separator>> . ]+
}
token arg-separator {
[<!before <eos>> \s+] || [\s* ',' [<!before <eos>> \s*]]
}
token eos { \s* $ }
}
Simple-Grammar.parse( $str, actions => Actions.new);
Output:
Cannot bind attributes in a Nil type object
in method arg-separator at ./p.p6 line 16
in regex arg-separator at ./p.p6 line 28
in regex argument at ./p.p6 line 24
in regex TOP at ./p.p6 line 22
in block <unit> at ./p.p6 line 35
Line 16 is here
make $match-str;
I do not understand why $match-str is here a Nil type object ? The strange thing is that if I replace $match-str in line 16 with any constant string, for example make "xxx"; I still get the same error..
makeoperates on$/by default, so I should use$match-data.make($match-str)instead when I don't use$/as an input argument. The reason I did not use$/from the beginning was that the regex match operator~~also uses$/, so there would be a conflict..