Grammars are classes and, as such, they should get to be subject to the same rules as other classes. However, there seems to be a problem with exporting regexes from a Grammar:
grammar Word {
token TOP { ^ <letters> $}
regex letters is export { <[\w] - [_]>+ };
sub exported () is export { return 'exported' };
}
import Word;
say exported;
say "what_ever" ~~ &letters;
import
effectively imports exported
and it does not complain about letters
. However, there's this error in the last line:
Type check failed in binding to parameter '<anon>'; expected Word but got Match (Match.new(orig => "what_ev...)
The same error happens if &letters
is changed to /<letters>/
, which is the other way to invoke regexes. The error seems to point out to letters
having some hidden argument when they are declared within a grammar, because this works:
module Regexes {
my regex letters is export { <[\w] - [_]>+ };
}
import Regexes;
say "what_ever" ~~ /<letters>/;
# Output:
# 「what」
# letters => 「what」
So what would effectively be that parameter? How could we effectively use exported regexes/tokens/rules from a Grammar