I want to reuse the token parameter
from Perl6::Grammar in my custom slang to add a "custom-param" parameter without cargo culting.
What I mean:
my $main-grammar = $*LANG.slang_grammar('MAIN');
my $main-actions = $*LANG.slang_actions('MAIN');
role Nogil::NogilGrammar {
token parameter { # the new one
"custom-param" || < here the token stolen from $main-grammar.^find_method('parameter'); >
}
my $grammar = $main-grammar.^mixin(Nogil::NogilGrammar);
my $actions = $main-actions.^mixin(Nogil::NogilActions);
$*LANG.define_slang('MAIN', $grammar, $actions);
Not sure it is clear: it is like calling the parent token in a token of a role. I know the role will overwrite it so I kept a backup of pristine object in $grammar
.
Already tested:
- Define it as a method returning the Match object of the parent but got the following error:
P6opaque: no such attribute '$!pos' on type NQPMatch in a Scalar when trying to get a value
- Return from a Regex code interpolation
Attempt to return outside of immediately-enclosing Routine (i.e. `return` execution is outside the dynamic scope of the Routine where `return` was used)
NQPMatch
object inMatch
? – Lawn