Parrot Perl6Grammar compiler and parsers #20

Subrule matches

regex TOP     { <integer> <addop> <integer> {*} }
regex integer { \d+ {*} }
regex addop   { [ '+' | '-' ] {*} }

method TOP($/)     {  say("found an expression ", $/); }

Within a regex, subrules are captured into named components of the match object

In the TOP method, the matched integers and addop are available as $/<integer> and $/<addop>

Perl 6 and NQP also allow $<integer> and $<addop> shorthands

Copyright © 2009
http://www.pmichaud.com/2009/pres/