in reply to Re^3: Perl6: Dynamic Grammars
in thread Perl6: Dynamic Grammars
my regex line { ^^ (\w+) :my $s; <?{ $s = %sigils{$0} }> \h+ $s $<foo>=\N* $s # Note the foo bit here ... $$ } is ('bang !one!' ~~ m/<line>/)<line><foo>, 'one', 'is bang!one'; # +... and here
Another tweak is to drop one level of hash keys by using a grammar (again, see the two lines with comments):
grammar g { regex TOP { # drop 'my'; name 'TOP' to simplify .parse call in `is +` test ^^ (\w+) :my $s; <?{ $s = %sigils{$0} }> \h+ $s $<foo>=\N* $s $$ } } is g.parse('bang !one!')<foo>, 'one', 'is bang!one'; # calling +.parse method on grammar defaults to starting with rule (regex) named + 'TOP'
|
|---|