Documentation for method subparse

Documentation for method subparse, assembled from the following types:

class Grammar

From Grammar

(Grammar) method subparse

Defined as:

method subparse($target:$rule = 'TOP'Capture() :$args = \(),  Mu :$actions = Mu*%opt)

Does exactly the same as method parse, except that cursor doesn't have to reach the end of the string to succeed. (That is, it doesn't have to match the whole string).

Note that unlike method parse, subparse always returns a Match object, which will be a failed match (and thus falsy), if the grammar failed to match.

grammar A {
    token as { a+ };
my $match = A.subparse('aaab':rule<as>);
say ~$match;        # OUTPUT: «aaa␤» 
say $;      # OUTPUT: «3␤»