my $GLOBAL-BINARY = False;
grammar Foo {
regex TOP {
:my Bool $*BINARY;
<ab>+
{ $GLOBAL-BINARY = $*BINARY with $*BINARY }
}
token ab { <a>+ (<b>+)? }
token a { 'a' {$*BINARY = True} }
token b { 'b' {$*BINARY = False} }
}
my $f = Foo.parse('a');
say $GLOBAL-BINARY;
$f = Foo.parse('ab');
say $GLOBAL-BINARY;
$f = Foo.parse('aba');
say $GLOBAL-BINARY;
$f = Foo.parse('abac');
say $GLOBAL-BINARY;
$f = Foo.parse('abbbbbbb');
say $GLOBAL-BINARY;