Parrot/PGE, parsers Parsers, Perl 6 Rules, and the Parrot Grammar Engine #21

Example

The subrule performs whatever matching it wants to do, sets the final .to() position for the match, and returns it to the caller.

For example, here's a <null> subrule:

.sub "null"
    .param pmc mob         # incoming match state          
    .param pmc adverbs     :named :slurpy
    .local pmc match       # match object to return
    .local string target   # current match target
    .local int cpos        # current match position
    (match, cpos, target) = mob.'new'(adverbs :flat :named)

    ##   set end of match to current position and return it
    match.to(cpos)
    .return (match)
 .end
Copyright © 2006 Patrick Michaud