With a regular expression, token, or rule, you can define such a variable;
token directive { :my $foo = "in command"; <command> <subject> <value>? }
The language documentation does not and very little in S05 - Regular rules and regulations to quote:
Any regular expression in a grammar is actually just a kind of method, and you can declare variables in such a routine using a colon followed by any sphere declarator parsed by Perl 6, including my, our, state, and a constant. (Since quasi-declarators, temp, and let are also recognized.) A single statement (up through the end semicolon or end end figure) is parsed like normal Perl 6 code:
token prove-nondeterministic-parsing { :my $threshold = rand; 'maybe' \s+ <it($threshold)> }
I get that regular expression in grammars is very similar to methods in classes; I get that you can run the block anywhere in the rule, and if the parsing successfully reaches this point, the block will be executed - but I donβt understand what this thing is for.
Can someone clearly define what their area of ββaction is; explain what it needs and give a typical use case?
source share