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 RepeatChar {
    token start($character) { $character+ }
}
 
say RepeatChar.subparse('bbbabb':rule('start'), :args(\('b')));
say RepeatChar.parse('bbbabb':rule('start'), :args(\('b')));
say RepeatChar.subparse('bbbabb':rule('start'), :args(\('a')));
say RepeatChar.subparse('bbbabb':rule('start'), :args(\('a')), :pos(3));
 
 
# OUTPUT: 
# 「bbb」 
# Nil 
# #<failed match> 
# 「a」